int asyncMakeHandle ( AsyncHandle *handle, Element *(*newElement) (const void *parameters), const void *parameters ) { if (handle) { if (!(*handle = malloc(sizeof(**handle)))) { logMallocError(); return 0; } } { Element *element = newElement(parameters); if (element) { if (handle) { memset(*handle, 0, sizeof(**handle)); (*handle)->element = element; (*handle)->identifier = getElementIdentifier(element); (*handle)->tsd = asyncGetThreadSpecificData(); } return 1; } } if (handle) free(*handle); return 0; }
int asyncTestHandle (AsyncHandle handle) { AsyncThreadSpecificData *tsd = asyncGetThreadSpecificData(); if (handle->tsd == tsd) return 1; logMessage(LOG_WARNING, "invalid async handle"); return 0; }
static AsyncAlarmData * getAlarmData (void) { AsyncThreadSpecificData *tsd = asyncGetThreadSpecificData(); if (!tsd) return NULL; if (!tsd->alarmData) { AsyncAlarmData *ad; if (!(ad = malloc(sizeof(*ad)))) { logMallocError(); return NULL; } memset(ad, 0, sizeof(*ad)); ad->alarmQueue = NULL; tsd->alarmData = ad; } return tsd->alarmData; }
static AsyncIoData * getIoData (void) { AsyncThreadSpecificData *tsd = asyncGetThreadSpecificData(); if (!tsd) return NULL; if (!tsd->ioData) { AsyncIoData *iod; if (!(iod = malloc(sizeof(*iod)))) { logMallocError(); return NULL; } memset(iod, 0, sizeof(*iod)); iod->functionQueue = NULL; tsd->ioData = iod; } return tsd->ioData; }
static AsyncWaitData * getWaitData (void) { AsyncThreadSpecificData *tsd = asyncGetThreadSpecificData(); if (!tsd) return NULL; if (!tsd->waitData) { AsyncWaitData *wd; if (!(wd = malloc(sizeof(*wd)))) { logMallocError(); return NULL; } memset(wd, 0, sizeof(*wd)); wd->tsd = tsd; wd->waitDepth = 0; tsd->waitData = wd; } return tsd->waitData; }