diff options
| -rw-r--r-- | src/lib/kdb/ChangeLog | 12 | ||||
| -rw-r--r-- | src/lib/kdb/Makefile.in | 2 | ||||
| -rw-r--r-- | src/lib/kdb/kdb5.c | 103 | ||||
| -rw-r--r-- | src/lib/kdb/kdb5.h | 5 |
4 files changed, 28 insertions, 94 deletions
diff --git a/src/lib/kdb/ChangeLog b/src/lib/kdb/ChangeLog index b6677ffee..b1099aa24 100644 --- a/src/lib/kdb/ChangeLog +++ b/src/lib/kdb/ChangeLog @@ -1,11 +1,15 @@ 2006-01-25 Ken Raeburn <raeburn@mit.edu> - * kdb5.h (struct _db_library): Delete unlocked and lock_holder - fields. + * kdb5.h (struct _db_library): Delete all lock-related fields. (struct _kdb_vftabl): Delete is_thread_safe field. * kdb5.c (kdb_init_lib_lock, kdb_destroy_lib_lock, - kdb_lock_lib_lock, kdb_unlock_lib_lock): Delete references. - Assume the plugin is always thread-safe. + kdb_lock_lib_lock, kdb_unlock_lib_lock): Make no-ops always. + + * kdb5.c (db_lock, kdb_lock_list, kdb_unlock_list): Use the + k5_mutex interfaces. + (kdb_init_lock_list, kdb_fini_lock_list): New functions; + initialize and destroy the mutex. Mark as init/fini functions. + * Makefile.in (LIBINITFUNC, LIBFINIFUNC): New variables. 2005-12-02 Ken Raeburn <raeburn@mit.edu> diff --git a/src/lib/kdb/Makefile.in b/src/lib/kdb/Makefile.in index e33a2d445..d8a03f3ad 100644 --- a/src/lib/kdb/Makefile.in +++ b/src/lib/kdb/Makefile.in @@ -12,6 +12,8 @@ LOCALINCLUDES= -I. LIBBASE=kdb5 LIBMAJOR=4 LIBMINOR=0 +LIBINITFUNC=kdb_init_lock_list +LIBFINIFUNC=kdb_fini_lock_list RELDIR=kdb # Depends on libk5crypto and libkrb5 diff --git a/src/lib/kdb/kdb5.c b/src/lib/kdb/kdb5.c index 156ebb65a..342bdc1bf 100644 --- a/src/lib/kdb/kdb5.c +++ b/src/lib/kdb/kdb5.c @@ -27,12 +27,7 @@ * internal static variable */ -#if defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) -/* static pthread_once_t db_inited = PTHREAD_ONCE_INIT; */ -static pthread_mutex_t db_lock = PTHREAD_MUTEX_INITIALIZER; -#else -/* static int db_inited = 0; */ -#endif +static k5_mutex_t db_lock = K5_MUTEX_PARTIAL_INITIALIZER; #ifdef _KDB5_STATIC_LINK #undef _KDB5_DYNAMIC_LINK @@ -47,106 +42,44 @@ static db_library lib_list; /* * Helper Functions */ -#if defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) - -/* - * KNOWN ISSUES with locking: This code does not handle a scenario - * where a library is thread-safe for different DB contexts, but not - * with the same context. It locks the complete DB library. If this is - * not the scenario, then lock has to be moved from db_library to - * kdb5_dal_handle. For now doing a pessimistic locking. - * - * If any thread does a DB lock, all the other threads are barred from - * accessing DB using this context (infact library because of the - * previous defect). This is with the assumption that, DB's lock code - * will take care of excluding other processes/machines from using the - * DB. But there could be a scenario where access by some other thread - * using the same context might corrupt the database. - */ - -static int -kdb_lock_list() -{ - return pthread_mutex_lock(&db_lock); -} -static int -kdb_unlock_list() -{ - return pthread_mutex_unlock(&db_lock); -} +MAKE_INIT_FUNCTION(kdb_init_lock_list); +MAKE_FINI_FUNCTION(kdb_fini_lock_list); -static int -kdb_init_lib_lock(db_library lib) +int +kdb_init_lock_list(void) { - krb5_error_code retval; - if ((retval = pthread_mutex_init(&lib->lib_lock, NULL))) { - return retval; - } - - lib->excl = 0; - lib->recursive_cnt = 0; - - return 0; + return k5_mutex_finish_init(&db_lock); } static int -kdb_destroy_lib_lock(db_library lib) +kdb_lock_list() { - krb5_error_code retval; - if ((retval = pthread_mutex_destroy(&lib->lib_lock))) { - return retval; - } - - return 0; + int err; + err = CALL_INIT_FUNCTION (kdb_init_lock_list); + if (err) + return err; + return k5_mutex_lock(&db_lock); } -static int -kdb_lock_lib_lock(db_library lib, krb5_boolean exclusive) +void +kdb_fini_lock_list(void) { - /* Since, handle locked by one thread should not allow another - thread to continue. */ - krb5_error_code retval = 0; - - if ((retval = pthread_mutex_lock(&lib->lib_lock))) - return retval; - - /* exclusive lock and recursive_cnt allow a thread to lock even it - already holds a lock */ - if (exclusive) - lib->excl++; - - lib->recursive_cnt++; - - return pthread_mutex_unlock(&lib->lib_lock); + if (INITIALIZER_RAN(kdb_init_lock_list)) + k5_mutex_destroy(&db_lock); } static int -kdb_unlock_lib_lock(db_library lib, krb5_boolean exclusive) +kdb_unlock_list() { - krb5_error_code retval = 0; - - if ((retval = pthread_mutex_lock(&lib->lib_lock))) - return retval; - - lib->recursive_cnt--; - if (exclusive) - lib->excl--; - - return pthread_mutex_unlock(&lib->lib_lock); + return k5_mutex_unlock(&db_lock); } -#else /* no PTHREAD */ - -/* program is not using pthread. So, threads wont be there. No need to lock */ -#define kdb_lock_list() 0 -#define kdb_unlock_list() 0 #define kdb_init_lib_lock(a) 0 #define kdb_destroy_lib_lock(a) 0 #define kdb_lock_lib_lock(a, b) 0 #define kdb_unlock_lib_lock(a, b) 0 -#endif /* end of HAVE_PTHREAD_H */ static char * kdb_get_conf_section(krb5_context kcontext) diff --git a/src/lib/kdb/kdb5.h b/src/lib/kdb/kdb5.h index 4027849e0..0df35dbee 100644 --- a/src/lib/kdb/kdb5.h +++ b/src/lib/kdb/kdb5.h @@ -196,11 +196,6 @@ typedef struct _kdb_vftabl{ typedef struct _db_library { char name[KDB_MAX_DB_NAME]; int reference_cnt; -#ifdef HAVE_PTHREAD_H - pthread_mutex_t lib_lock; - int recursive_cnt; /* this is used as lock to help recursive locking */ - int excl; -#endif void *dl_handle; kdb_vftabl vftabl; struct _db_library *next, *prev; |
