/* This function is a prefetch call generated by the compiler that
* populates the shared primary prefetch queue*/
void prefetch(int ntuples, unsigned int *oids, unsigned short *endoffsets, short *arrayfields) {
- int qnodesize;
- int len = 0;
- int i, rc;
-
- /* Allocate for the queue node*/
- char *node;
- if(ntuples > 0) {
- qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short);
- if((node = calloc(1, qnodesize)) == NULL) {
- printf("Calloc Error %s, %d\n", __FILE__, __LINE__);
- return;
- }
- /* Set queue node values */
- len = sizeof(prefetchqelem_t);
- memcpy(node + len, &ntuples, sizeof(int));
- len += sizeof(int);
- memcpy(node + len, oids, ntuples*sizeof(unsigned int));
- len += ntuples * sizeof(unsigned int);
- memcpy(node + len, endoffsets, ntuples*sizeof(unsigned short));
- len += ntuples * sizeof(unsigned short);
- memcpy(node + len, arrayfields, endoffsets[ntuples-1]*sizeof(short));
- /* Lock and insert into primary prefetch queue */
- pthread_mutex_lock(&pqueue.qlock);
- pre_enqueue((prefetchqelem_t *)node);
- pthread_cond_signal(&pqueue.qcond);
- pthread_mutex_unlock(&pqueue.qlock);
- }
+ /* Allocate for the queue node*/
+ if(ntuples > 0) {
+ int qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short);
+ char * node;
+
+ if((node = calloc(1, qnodesize)) == NULL) {
+ printf("Calloc Error %s, %d\n", __FILE__, __LINE__);
+ return;
+ } else {
+ /* Set queue node values */
+ int len = sizeof(prefetchqelem_t);
+ int i;
+ unsigned int *narray;
+ unsigned short *narray2;
+ short * narray3;
+ int top=endoffsets[ntuples-1];
+ *((int *)(node+len))=ntuples;
+ len += sizeof(int);
+ narray=(unsigned int *)(node+len);
+ narray2=(unsigned short *)(narray+ntuples);
+ narray3=(short *)(narray2+ntuples);
+
+ for(i=0;i<ntuples;i++) {
+ narray[i]=oids[i];
+ narray2[i]=endoffsets[i];
+ }
+ for(i=0;i<top;i++) {
+ narray3[i]=arrayfields[i];
+ }
+ /* Lock and insert into primary prefetch queue */
+ pthread_mutex_lock(&pqueue.qlock);
+ pre_enqueue((prefetchqelem_t *)node);
+ pthread_cond_signal(&pqueue.qcond);
+ pthread_mutex_unlock(&pqueue.qlock);
+ }
+ }
}
/* This function starts up the transaction runtime. */