CDList* CD_CloneList (CDList* self) { CDList* cloned = CD_CreateList(); assert(self); CD_LIST_FOREACH(self, it) { CD_ListPush(cloned, CD_ListIteratorValue(it)); }
void CD_EventRegisterWithPriority (CDServer* self, const char* eventName, int priority, CDEventCallbackFunction callback) { assert(self); CDList* callbacks = (CDList*) CD_HashGet(self->event.callbacks, eventName); if (!callbacks) { callbacks = CD_CreateList(); CD_HashPut(self->event.callbacks, eventName, (CDPointer) callbacks); } CD_ListSortedPush(callbacks, (CDPointer) CD_CreateEventCallback(callback, priority), (CDListCompareCallback) cd_EventCompare); }
CDList* CD_CreateEventParameters (const char* first, ...) { va_list ap; CDList* self = CD_CreateList(); char* current = NULL; if (first) { va_start(ap, first); CD_ListPush(self, (CDPointer) strdup(first)); while ((current = va_arg(ap, char*))) { CD_ListPush(self, (CDPointer) strdup(current)); } va_end(ap); } return self; }
CDWorkers* CD_CreateWorkers (CDServer* server) { CDWorkers* self = CD_malloc(sizeof(CDWorkers)); assert(self); self->server = server; self->last = 0; self->length = 0; self->item = NULL; self->jobs = CD_CreateList(); if (pthread_attr_init(&self->attributes) != 0) { CD_abort("pthread attribute failed to initialize"); } if (pthread_attr_setdetachstate(&self->attributes, PTHREAD_CREATE_DETACHED) != 0) { CD_abort("pthread attribute failed to set in detach state"); } if (pthread_attr_setstacksize(&self->attributes, CD_THREAD_STACK) != 0) { CD_abort("pthread attribute failed to set stack size"); } if (pthread_mutex_init(&self->lock.mutex, NULL) != 0) { CD_abort("pthread mutex failed to initialize"); } if (pthread_cond_init(&self->lock.condition, NULL) != 0) { CD_abort("pthread cond failed to initialize"); } return self; }