PsmAddress Sm_list_create(const char *fileName, int lineNbr, PsmPartition partition) { sm_SemId lock; PsmAddress list; SmList *listBuffer; lock = sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO); if (lock < 0) { putErrmsg("Can't create semaphore for list.", NULL); return 0; } list = Psm_zalloc(fileName, lineNbr, partition, sizeof(SmList)); if (list == 0) { sm_SemDelete(lock); putErrmsg("Can't allocate space for list header.", NULL); return 0; } listBuffer = (SmList *) psp(partition, list); eraseList(listBuffer); listBuffer->lock = lock; return list; }
void MainWindow::test(QAction *action){ if(action) if(action->data().isNull()) eraseList(); else qDebug() << action->data(); }
int main(int argc, char *argv[]){ temperature_List = makeLL(); int i,a; sensor_struct *data; //to run --> ./nameofMain #sensors #cycles if(argc != 3){ puts("ERROR! Format should be: ./sensor #ofSensors #ofCycles\n"); exit(0); } numSensors = atoi(argv[1]); numCycles = atoi(argv[2]); printf("Running %d cycle(s) on %d sensor(s)\n\n", numCycles,numSensors); pthread_t sensors[numSensors]; pthread_mutex_init(&locker, NULL); //fills, prints, and gets average of LL a user specified number of times for(a=1; a<=numCycles; a++){ printf("CYCLE %d:\n", a); for(i=1; i<=numSensors; i++){ data = (sensor_struct*)malloc(sizeof(sensor_struct)); data->id = i; lTime = time(NULL); sTime = (unsigned) lTime/2; data->seed = sTime; //creates new sensor thread in array --> inserts newly generated temperature if(pthread_create(&(sensors[i]), NULL, (void *)sensor, data) != 0){ perror("pthread_create"); exit(1); } } sleep(1); traverse(temperature_List); average(temperature_List); eraseList(temperature_List); } //waiting for all sensor threads to terminate for(i=1; i<=numSensors; i++){ pthread_join(sensors[i], NULL); } printf("All done. Goodbye\n"); return 0; }
void eraseList(list *l, node *n) { if(l->head == NULL) { free(l); return; } if(n->next != NULL) eraseList(l, n->next); free(n->next); if(n == l->head) { free(n); free(l); } }
static int wipeList(const char *fileName, int lineNbr, PsmPartition partition, PsmAddress list, SmListDeleteFn deleteFn, void *arg, int destroy) { SmList *listBuffer; PsmAddress elt; PsmAddress next; SmListElt *eltBuffer; listBuffer = (SmList *) psp(partition, list); if (lockSmlist(listBuffer) < 0) { putErrmsg(_cannotLockMsg(), NULL); return -1; } for (elt = listBuffer->first; elt != 0; elt = next) { eltBuffer = (SmListElt *) psp(partition, elt); CHKERR(eltBuffer); next = eltBuffer->next; if (deleteFn) { deleteFn(partition, elt, arg); } /* clear in case user mistakenly accesses later... */ eraseListElt(eltBuffer); Psm_free(fileName, lineNbr, partition, elt); } eraseList(listBuffer); if (destroy) { sm_SemDelete(listBuffer->lock); listBuffer->lock = SM_SEM_NONE; Psm_free(fileName, lineNbr, partition, list); } else { unlockSmlist(listBuffer); } return 0; }
/************************************************************************************************ terminateLeave() Description: Function that is used to erase the list and close the socket opened in join. *************************************************************************************************/ void terminateLeave(){ eraseList(); close(saSocket); saSocket = -42; return; }
void releaseList(consPo l) { eraseList(O_OBJECT(l)); }