* prof_int.h: Define USE_PTHREADS and include pthread.h if on MacOS X.
authorKen Raeburn <raeburn@mit.edu>
Sat, 21 Dec 2002 04:28:06 +0000 (04:28 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 21 Dec 2002 04:28:06 +0000 (04:28 +0000)
(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

src/util/profile/ChangeLog
src/util/profile/prof_file.c
src/util/profile/prof_int.h

index bcf9c2f106f80c8393fd83d1f5dd52e2c4e5be9c..38c67105a57e33c5591e81067ad1ffde0bfb6678 100644 (file)
@@ -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.
index e9da626e3d13855fa2db5e1a1840c05ce85201c4..b3cee881c61e9e0f99b2aadefec158aa8e33e235 100644 (file)
@@ -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
index ead23dc3a26da83bae10d2132aa848d516987afc..690a0aae043355a07a55f925a9247e9d9588ebe7 100644 (file)
@@ -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 *);