rwlock_t* rwlock_New(void) { rwlock_t* rwlock = (rwlock_t*)malloc(sizeof(rwlock_t)); rwlock->readers = 0; MUTEX_NEW(rwlock->lock); MUTEX_INIT(rwlock->lock); COND_NEW(rwlock->reader_cond); COND_INIT(rwlock->reader_cond); COND_NEW(rwlock->writer_cond); COND_INIT(rwlock->writer_cond); return rwlock; }
listtable* listTable(int options) { listtable* tbl = (listtable*) calloc(1, sizeof(listtable)); if (tbl == NULL) { errno = ENOMEM; return NULL; } // assign member methods. tbl->put = listablePut; tbl->putstr = listablePutAsString; tbl->putstrf = listablePutAsStringf; tbl->putint = listablePutAsInt; tbl->get = listableGet; tbl->getstr = listableGetAsString; tbl->getint = listableGetAsInt; tbl->getmulti = listableGetMulti; tbl->freemulti = listableFreeMulti; tbl->remove = listableRemove; tbl->removeobj = listableRemoveObj; tbl->getnext = listableGetNext; tbl->size = listableSize; tbl->sort = listableSort; tbl->clear = listableClear; tbl->save = listableSave; tbl->load = listableLoad; tbl->debug = listableDebug; tbl->lock = listableLock; tbl->unlock = listableUnlock; tbl->free = listableFree; // assign private methods. tbl->namematch = nameMatch; tbl->namecmp = strcmp; // handle options. if (options & LISTTABLE_THREADSAFE) { MUTEX_NEW(tbl->qmutex, true); if (tbl->qmutex == NULL) { errno = ENOMEM; free(tbl); return NULL; } } if (options & LISTTABLE_UNIQUE) { tbl->unique = true; } if (options & LISTTABLE_CASEINSENSITIVE) { tbl->namematch = nameCaseMatch; tbl->namecmp = strcasecmp; } if (options & LISTTABLE_INSERTTOP) { tbl->inserttop = true; } if (options & LISTTABLE_LOOKUPFORWARD) { tbl->lookupforward = true; } return tbl; }