(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
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.
FSSpec* outFilespec);
#endif
+static void profile_free_file_data(prf_data_t);
+
static int rw_access(filespec)
profile_filespec_t filespec;
{
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. */
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);
}
#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;
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
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
#include <Kerberos/com_err.h>
#include <Kerberos/FullPOSIXPath.h>
#include <CoreServices/CoreServices.h>
+#define USE_PTHREADS
#else
#include "com_err.h"
#endif
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 */
/*
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 *);