diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2008-09-04 18:43:14 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2008-09-04 18:43:14 +0000 |
commit | e472b5dd07e78f0180f4fbf5f22fc2fff2ab2548 (patch) | |
tree | d8e92c566046b39c8fa8de207ee77d52b79261b4 /src/ccapi | |
parent | de5ddef09b291bd0c6e933a65fcdaf63aee2f7df (diff) | |
download | krb5-e472b5dd07e78f0180f4fbf5f22fc2fff2ab2548.tar.gz krb5-e472b5dd07e78f0180f4fbf5f22fc2fff2ab2548.tar.xz krb5-e472b5dd07e78f0180f4fbf5f22fc2fff2ab2548.zip |
CCAPI should only use one pthread key
Use k5 thread functions. Also add destructors so if we ever have a way
to detect application exit that the pthread key is destroyed.
ticket: new
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20705 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/ccapi')
-rw-r--r-- | src/ccapi/lib/ccapi_context.c | 14 | ||||
-rw-r--r-- | src/ccapi/lib/ccapi_context_change_time.c | 7 | ||||
-rw-r--r-- | src/ccapi/lib/ccapi_context_change_time.h | 1 | ||||
-rw-r--r-- | src/ccapi/lib/ccapi_ipc.c | 7 | ||||
-rw-r--r-- | src/ccapi/lib/ccapi_ipc.h | 1 | ||||
-rw-r--r-- | src/ccapi/lib/ccapi_os_ipc.h | 1 | ||||
-rw-r--r-- | src/ccapi/lib/mac/ccapi_os_ipc.c | 35 | ||||
-rw-r--r-- | src/ccapi/lib/win/ccapi_os_ipc.cxx | 7 |
8 files changed, 58 insertions, 15 deletions
diff --git a/src/ccapi/lib/ccapi_context.c b/src/ccapi/lib/ccapi_context.c index 3b8d60e3eb..640e153e8c 100644 --- a/src/ccapi/lib/ccapi_context.c +++ b/src/ccapi/lib/ccapi_context.c @@ -80,6 +80,7 @@ static cc_int32 cci_context_sync (cci_context_t in_context, #endif MAKE_INIT_FUNCTION(cci_thread_init); +MAKE_FINI_FUNCTION(cci_thread_fini); /* ------------------------------------------------------------------------ */ @@ -98,6 +99,19 @@ static int cci_thread_init (void) return err; } +/* ------------------------------------------------------------------------ */ + +static void cci_thread_fini (void) +{ + if (!INITIALIZER_RAN (cci_thread_init) || PROGRAM_EXITING ()) { + return; + } + + cci_context_change_time_thread_fini (); + cci_ipc_thread_fini (); +} + + #ifdef TARGET_OS_MAC #pragma mark - #endif diff --git a/src/ccapi/lib/ccapi_context_change_time.c b/src/ccapi/lib/ccapi_context_change_time.c index f701c22fef..4efc7db603 100644 --- a/src/ccapi/lib/ccapi_context_change_time.c +++ b/src/ccapi/lib/ccapi_context_change_time.c @@ -42,6 +42,13 @@ cc_int32 cci_context_change_time_thread_init (void) } /* ------------------------------------------------------------------------ */ + +void cci_context_change_time_thread_fini (void) +{ + k5_mutex_destroy(&g_change_time_mutex); +} + +/* ------------------------------------------------------------------------ */ /* WARNING! Mutex must be locked when calling this! */ static cc_int32 cci_context_change_time_update_identifier (cci_identifier_t in_new_identifier, diff --git a/src/ccapi/lib/ccapi_context_change_time.h b/src/ccapi/lib/ccapi_context_change_time.h index 536c492d88..ecf3583a94 100644 --- a/src/ccapi/lib/ccapi_context_change_time.h +++ b/src/ccapi/lib/ccapi_context_change_time.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_context_change_time_thread_init (void); +void cci_context_change_time_thread_fini (void); cc_int32 cci_context_change_time_get (cc_time_t *out_change_time); diff --git a/src/ccapi/lib/ccapi_ipc.c b/src/ccapi/lib/ccapi_ipc.c index 4d2e4314d5..fe541db4eb 100644 --- a/src/ccapi/lib/ccapi_ipc.c +++ b/src/ccapi/lib/ccapi_ipc.c @@ -36,6 +36,13 @@ cc_int32 cci_ipc_thread_init (void) /* ------------------------------------------------------------------------ */ +void cci_ipc_thread_fini (void) +{ + cci_os_ipc_thread_fini (); +} + +/* ------------------------------------------------------------------------ */ + static cc_int32 _cci_ipc_send (enum cci_msg_id_t in_request_name, cc_int32 in_launch_server, cci_identifier_t in_identifier, diff --git a/src/ccapi/lib/ccapi_ipc.h b/src/ccapi/lib/ccapi_ipc.h index 73c5b24972..2ba7637ac6 100644 --- a/src/ccapi/lib/ccapi_ipc.h +++ b/src/ccapi/lib/ccapi_ipc.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_ipc_thread_init (void); +void cci_ipc_thread_fini (void); cc_int32 cci_ipc_send (enum cci_msg_id_t in_request_name, cci_identifier_t in_identifier, diff --git a/src/ccapi/lib/ccapi_os_ipc.h b/src/ccapi/lib/ccapi_os_ipc.h index d9eb79f1c3..0121adadb7 100644 --- a/src/ccapi/lib/ccapi_os_ipc.h +++ b/src/ccapi/lib/ccapi_os_ipc.h @@ -30,6 +30,7 @@ #include "cci_common.h" cc_int32 cci_os_ipc_thread_init (void); +void cci_os_ipc_thread_fini (void); cc_int32 cci_os_ipc (cc_int32 in_launch_server, cci_stream_t in_request_stream, diff --git a/src/ccapi/lib/mac/ccapi_os_ipc.c b/src/ccapi/lib/mac/ccapi_os_ipc.c index 2fabb19220..d51e4c321a 100644 --- a/src/ccapi/lib/mac/ccapi_os_ipc.c +++ b/src/ccapi/lib/mac/ccapi_os_ipc.c @@ -34,29 +34,34 @@ #define cci_server_bundle_id "edu.mit.Kerberos.CCacheServer" #define cci_server_path "/System/Library/CoreServices/CCacheServer.app/Contents/MacOS/CCacheServer" -static pthread_key_t g_request_port_key = 0; -static pthread_key_t g_reply_stream_key = 0; -static pthread_key_t g_server_died_key = 0; - /* ------------------------------------------------------------------------ */ cc_int32 cci_os_ipc_thread_init (void) { cc_int32 err = ccNoError; - err = pthread_key_create (&g_request_port_key, free); + err = k5_key_register (K5_KEY_CCAPI_REQUEST_PORT, free); if (!err) { - err = pthread_key_create (&g_reply_stream_key, NULL); + err = k5_key_register (K5_KEY_CCAPI_REPLY_STREAM, NULL); } if (!err) { - err = pthread_key_create (&g_server_died_key, NULL); + err = k5_key_register (K5_KEY_CCAPI_SERVER_DIED, NULL); } return err; } +/* ------------------------------------------------------------------------ */ + +void cci_os_ipc_thread_fini (void) +{ + k5_key_delete (K5_KEY_CCAPI_REQUEST_PORT); + k5_key_delete (K5_KEY_CCAPI_REPLY_STREAM); + k5_key_delete (K5_KEY_CCAPI_SERVER_DIED); +} + #pragma mark - /* ------------------------------------------------------------------------ */ @@ -67,7 +72,7 @@ static boolean_t cci_server_demux (mach_msg_header_t *request, boolean_t handled = false; if (!handled && request->msgh_id == MACH_NOTIFY_NO_SENDERS) { - cc_int32 *server_died = pthread_getspecific (g_server_died_key); + cc_int32 *server_died = k5_getspecific (K5_KEY_CCAPI_SERVER_DIED); if (!server_died) { *server_died = 1; } @@ -94,7 +99,7 @@ kern_return_t cci_mipc_reply (mach_port_t in_reply_port, cci_stream_t reply_stream = NULL; if (!err) { - reply_stream = pthread_getspecific (g_reply_stream_key); + reply_stream = k5_getspecific (K5_KEY_CCAPI_REPLY_STREAM); if (!reply_stream) { err = cci_check_error (ccErrBadInternalMessage); } } @@ -161,7 +166,7 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, } if (!err) { - request_port = pthread_getspecific (g_request_port_key); + request_port = k5_getspecific (K5_KEY_CCAPI_REQUEST_PORT); if (!request_port) { request_port = malloc (sizeof (mach_port_t)); @@ -169,7 +174,7 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, if (!err) { *request_port = MACH_PORT_NULL; - err = pthread_setspecific (g_request_port_key, request_port); + err = k5_setspecific (K5_KEY_CCAPI_REQUEST_PORT, request_port); } } } @@ -226,11 +231,11 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, } if (!err) { - err = pthread_setspecific (g_reply_stream_key, reply_stream); + err = k5_setspecific (K5_KEY_CCAPI_REPLY_STREAM, reply_stream); } if (!err) { - err = pthread_setspecific (g_server_died_key, &server_died); + err = k5_setspecific (K5_KEY_CCAPI_SERVER_DIED, &server_died); } if (!err) { @@ -265,8 +270,8 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server, reply_stream = NULL; } - pthread_setspecific (g_reply_stream_key, NULL); - pthread_setspecific (g_server_died_key, NULL); + k5_setspecific (K5_KEY_CCAPI_REPLY_STREAM, NULL); + k5_setspecific (K5_KEY_CCAPI_SERVER_DIED, NULL); if (reply_port != MACH_PORT_NULL) { mach_port_destroy (mach_task_self (), reply_port); } if (ool_request_length ) { vm_deallocate (mach_task_self (), (vm_address_t) ool_request, ool_request_length); } if (reply_stream ) { cci_stream_release (reply_stream); } diff --git a/src/ccapi/lib/win/ccapi_os_ipc.cxx b/src/ccapi/lib/win/ccapi_os_ipc.cxx index 617598b77b..4b00e2de38 100644 --- a/src/ccapi/lib/win/ccapi_os_ipc.cxx +++ b/src/ccapi/lib/win/ccapi_os_ipc.cxx @@ -120,6 +120,13 @@ extern "C" cc_int32 cci_os_ipc_thread_init (void) { /* ------------------------------------------------------------------------ */ +void cci_os_ipc_thread_fini (void) +{ +} + + +/* ------------------------------------------------------------------------ */ + cc_int32 cci_os_ipc (cc_int32 in_launch_server, cci_stream_t in_request_stream, cci_stream_t* out_reply_stream) { |