diff options
author | Ken Raeburn <raeburn@mit.edu> | 2002-12-21 04:28:06 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2002-12-21 04:28:06 +0000 |
commit | bc38f344018bfa66182dd58401c4ed83a4fbd6e6 (patch) | |
tree | 885154a33be98eb20778c64ba8a421917dec7182 /src | |
parent | 7c28091d5daeb6431e6e76aeeca9ba1d33665d66 (diff) | |
download | krb5-bc38f344018bfa66182dd58401c4ed83a4fbd6e6.tar.gz krb5-bc38f344018bfa66182dd58401c4ed83a4fbd6e6.tar.xz krb5-bc38f344018bfa66182dd58401c4ed83a4fbd6e6.zip |
* prof_int.h: Define USE_PTHREADS and include pthread.h if on MacOS X.
(struct global_shared_profile_data) [USE_PTHREADS]: Add a mutex.
(g_shared_trees_mutex) [USE_PTHREADS]: New macro, references the global mutex.
(prof_mutex_lock, prof_mutex_unlock) [SHARE_TREE_DATA]: Define to use pthread
functions or do nothing.
(profile_free_file_data): Delete declaration.
(profile_dereference_data): Declare.
* prof_file.c (profile_free_file_data): Now static.
(profile_open_file, profile_dereference_data) [SHARE_TREE_DATA]: Grab lock
while manipulating global data list or its contents.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15061 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r-- | src/util/profile/ChangeLog | 13 | ||||
-rw-r--r-- | src/util/profile/prof_file.c | 14 | ||||
-rw-r--r-- | src/util/profile/prof_int.h | 19 |
3 files changed, 43 insertions, 3 deletions
diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index bcf9c2f106..38c67105a5 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,5 +1,18 @@ 2002-12-20 Ken Raeburn <raeburn@mit.edu> + * prof_int.h: Define USE_PTHREADS and include pthread.h if on + MacOS X. + (struct global_shared_profile_data) [USE_PTHREADS]: Add a mutex. + (g_shared_trees_mutex) [USE_PTHREADS]: New macro, references the + global mutex. + (prof_mutex_lock, prof_mutex_unlock) [SHARE_TREE_DATA]: Define to + use pthread functions or do nothing. + (profile_free_file_data): Delete declaration. + (profile_dereference_data): Declare. + * prof_file.c (profile_free_file_data): Now static. + (profile_open_file, profile_dereference_data) [SHARE_TREE_DATA]: + Grab lock while manipulating global data list or its contents. + * prof_int.h (SHARE_TREE_DATA): Define. (struct _prf_file_t) [SHARE_TREE_DATA]: Make data field a pointer rather than an array. diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index e9da626e3d..b3cee881c6 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -42,6 +42,8 @@ static OSErr GetMacOSTempFilespec ( FSSpec* outFilespec); #endif +static void profile_free_file_data(prf_data_t); + static int rw_access(filespec) profile_filespec_t filespec; { @@ -88,6 +90,7 @@ errcode_t profile_open_file(filespec, ret_prof) prf->magic = PROF_MAGIC_FILE; #ifdef SHARE_TREE_DATA + prof_mutex_lock(&g_shared_trees_mutex); for (data = g_shared_trees; data; data = data->next) { if (!strcmp(data->filespec, filespec) /* Check that current uid has read access. */ @@ -97,10 +100,12 @@ errcode_t profile_open_file(filespec, ret_prof) if (data) { retval = profile_update_file_data(data); data->refcount++; + prof_mutex_unlock(&g_shared_trees_mutex); prf->data = data; *ret_prof = prf; return retval; } + prof_mutex_unlock(&g_shared_trees_mutex); data = malloc(sizeof(struct _prf_data_t)); if (data == NULL) { free(prf); @@ -140,9 +145,11 @@ errcode_t profile_open_file(filespec, ret_prof) } #ifdef SHARE_TREE_DATA - data->next = g_shared_trees; data->flags |= PROFILE_FILE_SHARED; + prof_mutex_lock(&g_shared_trees_mutex); + data->next = g_shared_trees; g_shared_trees = data; + prof_mutex_unlock(&g_shared_trees_mutex); #endif *ret_prof = prf; @@ -316,9 +323,11 @@ errout: void profile_dereference_data(prf_data_t data) { #ifdef SHARE_TREE_DATA + prof_mutex_lock(&g_shared_trees_mutex); data->refcount--; if (data->refcount == 0) profile_free_file_data(data); + prof_mutex_unlock(&g_shared_trees_mutex); #else profile_free_file_data(data); #endif @@ -331,7 +340,8 @@ void profile_free_file(prf) free(prf); } -void profile_free_file_data(data) +/* Call with mutex locked! */ +static void profile_free_file_data(data) prf_data_t data; { #ifdef SHARE_TREE_DATA diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h index ead23dc3a2..690a0aae04 100644 --- a/src/util/profile/prof_int.h +++ b/src/util/profile/prof_int.h @@ -8,6 +8,7 @@ #include <Kerberos/com_err.h> #include <Kerberos/FullPOSIXPath.h> #include <CoreServices/CoreServices.h> +#define USE_PTHREADS #else #include "com_err.h" #endif @@ -66,9 +67,24 @@ typedef struct _prf_file_t *prf_file_t; struct global_shared_profile_data { /* This is the head of the global list of shared trees */ prf_data_t trees; +#ifdef USE_PTHREADS + /* Lock for above list. */ + pthread_mutex_t mutex; +#endif }; extern struct global_shared_profile_data krb5int_profile_shared_data; #define g_shared_trees (krb5int_profile_shared_data.trees) + +#ifdef USE_PTHREADS +#include <pthread.h> +#define g_shared_trees_mutex (krb5int_profile_shared_data.mutex) +#define prof_mutex_lock(L) (pthread_mutex_lock(L)) +#define prof_mutex_unlock(L) (pthread_mutex_unlock(L)) +#else +#define prof_mutex_lock(L) (0) +#define prof_mutex_unlock(L) (0) +#endif + #endif /* SHARE_TREE_DATA */ /* @@ -207,11 +223,12 @@ errcode_t profile_flush_file_data void profile_free_file (prf_file_t profile); -void profile_free_file_data (prf_data_t data); errcode_t profile_close_file (prf_file_t profile); +void profile_dereference_data (prf_data_t); + /* prof_init.c -- included from profile.h */ errcode_t profile_ser_size (const char *, profile_t, size_t *); |