* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: sdb.c,v 1.31 2001/05/02 19:25:19 bwelling Exp $ */
+/* $Id: sdb.c,v 1.32 2001/05/29 18:34:24 bwelling Exp $ */
#include <config.h>
void *driverdata;
unsigned int flags;
isc_mem_t *mctx;
+ isc_mutex_t driverlock;
dns_dbimplementation_t *dbimp;
};
dns_sdbimplementation_t *implementation;
void *dbdata;
isc_mutex_t lock;
- isc_mutex_t driverlock;
/* Locked */
unsigned int references;
do { \
unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
- LOCK(&sdb->driverlock); \
+ LOCK(&sdb->implementation->driverlock); \
} while (0)
#define MAYBE_UNLOCK(sdb) \
do { \
unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
- UNLOCK(&sdb->driverlock); \
+ UNLOCK(&sdb->implementation->driverlock); \
} while (0)
static int dummy;
imp->flags = flags;
imp->mctx = NULL;
isc_mem_attach(mctx, &imp->mctx);
+ result = isc_mutex_init(&imp->driverlock);
+ if (result != ISC_R_SUCCESS) {
+ UNEXPECTED_ERROR(__FILE__, __LINE__,
+ "isc_mutex_init() failed: %s",
+ isc_result_totext(result));
+ goto cleanup_mctx;
+ }
+
imp->dbimp = NULL;
result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
&imp->dbimp);
- if (result != ISC_R_SUCCESS) {
- dns_sdb_unregister(&imp);
- return (result);
- }
+ if (result != ISC_R_SUCCESS)
+ goto cleanup_mutex;
*sdbimp = imp;
return (ISC_R_SUCCESS);
+
+ cleanup_mutex:
+ DESTROYLOCK(&imp->driverlock);
+ cleanup_mctx:
+ isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
+ return (result);
}
void
imp = *sdbimp;
dns_db_unregister(&imp->dbimp);
+ DESTROYLOCK(&imp->driverlock);
mctx = imp->mctx;
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
mctx = sdb->common.mctx;
- if (imp->methods->destroy != NULL)
+ if (imp->methods->destroy != NULL) {
+ MAYBE_LOCK(sdb);
imp->methods->destroy(sdb->zone, imp->driverdata,
&sdb->dbdata);
+ MAYBE_UNLOCK(sdb);
+ }
isc_mem_free(mctx, sdb->zone);
DESTROYLOCK(&sdb->lock);
- DESTROYLOCK(&sdb->driverlock);
sdb->common.magic = 0;
sdb->common.impmagic = 0;
goto cleanup_mctx;
}
- result = isc_mutex_init(&sdb->driverlock);
- if (result != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_mutex_init() failed: %s",
- isc_result_totext(result));
- result = ISC_R_UNEXPECTED;
- goto cleanup_lock;
- }
-
result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
if (result != ISC_R_SUCCESS)
- goto cleanup_driverlock;
+ goto cleanup_lock;
isc_buffer_init(&b, zonestr, sizeof(zonestr));
result = dns_name_totext(origin, ISC_TRUE, &b);
sdb->dbdata = NULL;
if (imp->methods->create != NULL) {
+ MAYBE_LOCK(sdb);
result = imp->methods->create(sdb->zone, argc, argv,
imp->driverdata, &sdb->dbdata);
+ MAYBE_UNLOCK(sdb);
if (result != ISC_R_SUCCESS)
goto cleanup_zonestr;
}
isc_mem_free(mctx, sdb->zone);
cleanup_origin:
dns_name_free(&sdb->common.origin, mctx);
- cleanup_driverlock:
- isc_mutex_destroy(&sdb->driverlock);
cleanup_lock:
isc_mutex_destroy(&sdb->lock);
cleanup_mctx: