isc_result_t dns_fwdtable_create(isc_mem_t *mctx, dns_fwdtable_t **fwdtablep) { dns_fwdtable_t *fwdtable; isc_result_t result; REQUIRE(fwdtablep != NULL && *fwdtablep == NULL); fwdtable = isc_mem_get(mctx, sizeof(dns_fwdtable_t)); if (fwdtable == NULL) return (ISC_R_NOMEMORY); fwdtable->table = NULL; result = dns_rbt_create(mctx, auto_detach, fwdtable, &fwdtable->table); if (result != ISC_R_SUCCESS) goto cleanup_fwdtable; result = isc_rwlock_init(&fwdtable->rwlock, 0, 0); if (result != ISC_R_SUCCESS) goto cleanup_rbt; fwdtable->mctx = NULL; isc_mem_attach(mctx, &fwdtable->mctx); fwdtable->magic = FWDTABLEMAGIC; *fwdtablep = fwdtable; return (ISC_R_SUCCESS); cleanup_rbt: dns_rbt_destroy(&fwdtable->table); cleanup_fwdtable: isc_mem_put(mctx, fwdtable, sizeof(dns_fwdtable_t)); return (result); }
isc_result_t dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ringp) { isc_result_t result; dns_tsig_keyring_t *ring; REQUIRE(mctx != NULL); REQUIRE(ringp != NULL); REQUIRE(*ringp == NULL); ring = isc_mem_get(mctx, sizeof(dns_tsig_keyring_t)); if (ring == NULL) return (ISC_R_NOMEMORY); result = isc_rwlock_init(&ring->lock, 0, 0); if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_rwlock_init() failed: %s", isc_result_totext(result)); return (ISC_R_UNEXPECTED); } ring->keys = NULL; result = dns_rbt_create(mctx, free_tsignode, NULL, &ring->keys); if (result != ISC_R_SUCCESS) { isc_rwlock_destroy(&ring->lock); isc_mem_put(mctx, ring, sizeof(dns_tsig_keyring_t)); return (result); } ring->mctx = mctx; *ringp = ring; return (ISC_R_SUCCESS); }
isc_result_t dns_dbtable_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_dbtable_t **dbtablep) { dns_dbtable_t *dbtable; isc_result_t result; REQUIRE(mctx != NULL); REQUIRE(dbtablep != NULL && *dbtablep == NULL); dbtable = (dns_dbtable_t *)isc_mem_get(mctx, sizeof(*dbtable)); if (dbtable == NULL) return (ISC_R_NOMEMORY); dbtable->rbt = NULL; result = dns_rbt_create(mctx, dbdetach, NULL, &dbtable->rbt); if (result != ISC_R_SUCCESS) goto clean1; result = isc_mutex_init(&dbtable->lock); if (result != ISC_R_SUCCESS) goto clean2; result = isc_rwlock_init(&dbtable->tree_lock, 0, 0); if (result != ISC_R_SUCCESS) goto clean3; dbtable->default_db = NULL; dbtable->mctx = NULL; isc_mem_attach(mctx, &dbtable->mctx); dbtable->rdclass = rdclass; dbtable->magic = DBTABLE_MAGIC; dbtable->references = 1; *dbtablep = dbtable; return (ISC_R_SUCCESS); clean3: DESTROYLOCK(&dbtable->lock); clean2: dns_rbt_destroy(&dbtable->rbt); clean1: isc_mem_putanddetach(&mctx, dbtable, sizeof(*dbtable)); return (result); }
isc_result_t dns_keytable_create(isc_mem_t *mctx, dns_keytable_t **keytablep) { dns_keytable_t *keytable; isc_result_t result; /* * Create a keytable. */ REQUIRE(keytablep != NULL && *keytablep == NULL); keytable = isc_mem_get(mctx, sizeof(*keytable)); if (keytable == NULL) return (ISC_R_NOMEMORY); keytable->table = NULL; result = dns_rbt_create(mctx, free_keynode, mctx, &keytable->table); if (result != ISC_R_SUCCESS) goto cleanup_keytable; result = isc_mutex_init(&keytable->lock); if (result != ISC_R_SUCCESS) goto cleanup_rbt; result = isc_rwlock_init(&keytable->rwlock, 0, 0); if (result != ISC_R_SUCCESS) goto cleanup_lock; keytable->mctx = NULL; isc_mem_attach(mctx, &keytable->mctx); keytable->active_nodes = 0; keytable->references = 1; keytable->magic = KEYTABLE_MAGIC; *keytablep = keytable; return (ISC_R_SUCCESS); cleanup_lock: DESTROYLOCK(&keytable->lock); cleanup_rbt: dns_rbt_destroy(&keytable->table); cleanup_keytable: isc_mem_putanddetach(&mctx, keytable, sizeof(*keytable)); return (result); }
static void initialize(void) { RUNTIME_CHECK(isc_rwlock_init(&implock, 0, 0) == ISC_R_SUCCESS); rbtimp.name = "rbt"; rbtimp.create = dns_rbtdb_create; rbtimp.mctx = NULL; rbtimp.driverarg = NULL; ISC_LINK_INIT(&rbtimp, link); rbt64imp.name = "rbt64"; rbt64imp.create = dns_rbtdb64_create; rbt64imp.mctx = NULL; rbt64imp.driverarg = NULL; ISC_LINK_INIT(&rbt64imp, link); ISC_LIST_INIT(implementations); ISC_LIST_APPEND(implementations, &rbtimp, link); ISC_LIST_APPEND(implementations, &rbt64imp, link); }
isc_result_t dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) { dns_zt_t *zt; isc_result_t result; REQUIRE(ztp != NULL && *ztp == NULL); zt = isc_mem_get(mctx, sizeof(*zt)); if (zt == NULL) return (ISC_R_NOMEMORY); zt->table = NULL; result = dns_rbt_create(mctx, auto_detach, zt, &zt->table); if (result != ISC_R_SUCCESS) goto cleanup_zt; result = isc_rwlock_init(&zt->rwlock, 0, 0); if (result != ISC_R_SUCCESS) goto cleanup_rbt; zt->mctx = NULL; isc_mem_attach(mctx, &zt->mctx); zt->references = 1; zt->flush = ISC_FALSE; zt->rdclass = rdclass; zt->magic = ZTMAGIC; zt->loaddone = NULL; zt->loaddone_arg = NULL; zt->loads_pending = 0; *ztp = zt; return (ISC_R_SUCCESS); cleanup_rbt: dns_rbt_destroy(&zt->table); cleanup_zt: isc_mem_put(mctx, zt, sizeof(*zt)); return (result); }
isc_result_t dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) { dns_zt_t *zt; isc_result_t result; REQUIRE(ztp != NULL && *ztp == NULL); zt = isc_mem_get(mctx, sizeof(*zt)); if (zt == NULL) return (ISC_R_NOMEMORY); zt->table = NULL; result = dns_rbt_create(mctx, auto_detach, zt, &zt->table); if (result != ISC_R_SUCCESS) goto cleanup_zt; result = isc_rwlock_init(&zt->rwlock, 0, 0); if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_rwlock_init() failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; goto cleanup_rbt; } zt->mctx = mctx; zt->references = 1; zt->rdclass = rdclass; zt->magic = ZTMAGIC; *ztp = zt; return (ISC_R_SUCCESS); cleanup_rbt: dns_rbt_destroy(&zt->table); cleanup_zt: isc_mem_put(mctx, zt, sizeof(*zt)); return (result); }
int main(int argc, char *argv[]) { unsigned int nworkers; unsigned int i; isc_thread_t workers[100]; char name[100]; void *dupname; if (argc > 1) nworkers = atoi(argv[1]); else nworkers = 2; if (nworkers > 100) nworkers = 100; printf("%d workers\n", nworkers); RUNTIME_CHECK(isc_rwlock_init(&lock, 5, 10) == ISC_R_SUCCESS); for (i = 0; i < nworkers; i++) { sprintf(name, "%02u", i); dupname = strdup(name); RUNTIME_CHECK(dupname != NULL); if (i != 0 && i % 3 == 0) RUNTIME_CHECK(isc_thread_create(run1, dupname, &workers[i]) == ISC_R_SUCCESS); else RUNTIME_CHECK(isc_thread_create(run2, dupname, &workers[i]) == ISC_R_SUCCESS); } for (i = 0; i < nworkers; i++) (void)isc_thread_join(workers[i], NULL); isc_rwlock_destroy(&lock); return (0); }
isc_result_t dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ringp) { isc_result_t result; dns_tsig_keyring_t *ring; REQUIRE(mctx != NULL); REQUIRE(ringp != NULL); REQUIRE(*ringp == NULL); ring = isc_mem_get(mctx, sizeof(dns_tsig_keyring_t)); if (ring == NULL) return (ISC_R_NOMEMORY); result = isc_rwlock_init(&ring->lock, 0, 0); if (result != ISC_R_SUCCESS) { isc_mem_put(mctx, ring, sizeof(dns_tsig_keyring_t)); return (result); } ring->keys = NULL; result = dns_rbt_create(mctx, free_tsignode, NULL, &ring->keys); if (result != ISC_R_SUCCESS) { isc_rwlock_destroy(&ring->lock); isc_mem_put(mctx, ring, sizeof(dns_tsig_keyring_t)); return (result); } ring->writecount = 0; ring->mctx = NULL; ring->generated = 0; ring->maxgenerated = DNS_TSIG_MAXGENERATEDKEYS; ISC_LIST_INIT(ring->lru); isc_mem_attach(mctx, &ring->mctx); ring->references = 1; *ringp = ring; return (ISC_R_SUCCESS); }
static isc_result_t create_stats(isc_mem_t *mctx, int ncounters, isc_stats_t **statsp) { isc_stats_t *stats; isc_result_t result = ISC_R_SUCCESS; REQUIRE(statsp != NULL && *statsp == NULL); stats = isc_mem_get(mctx, sizeof(*stats)); if (stats == NULL) return (ISC_R_NOMEMORY); result = isc_mutex_init(&stats->lock); if (result != ISC_R_SUCCESS) goto clean_stats; stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters); if (stats->counters == NULL) { result = ISC_R_NOMEMORY; goto clean_mutex; } stats->copiedcounters = isc_mem_get(mctx, sizeof(isc_uint64_t) * ncounters); if (stats->copiedcounters == NULL) { result = ISC_R_NOMEMORY; goto clean_counters; } #ifdef ISC_RWLOCK_USEATOMIC result = isc_rwlock_init(&stats->counterlock, 0, 0); if (result != ISC_R_SUCCESS) goto clean_copiedcounters; #endif stats->references = 1; memset(stats->counters, 0, sizeof(isc_stat_t) * ncounters); stats->mctx = NULL; isc_mem_attach(mctx, &stats->mctx); stats->ncounters = ncounters; stats->magic = ISC_STATS_MAGIC; *statsp = stats; return (result); clean_counters: isc_mem_put(mctx, stats->counters, sizeof(isc_stat_t) * ncounters); #ifdef ISC_RWLOCK_USEATOMIC clean_copiedcounters: isc_mem_put(mctx, stats->copiedcounters, sizeof(isc_stat_t) * ncounters); #endif clean_mutex: DESTROYLOCK(&stats->lock); clean_stats: isc_mem_put(mctx, stats, sizeof(*stats)); return (result); }
static void dlz_initialize(void) { RUNTIME_CHECK(isc_rwlock_init(&dlz_implock, 0, 0) == ISC_R_SUCCESS); ISC_LIST_INIT(dlz_implementations); }