From a55d6dceca4ae0edf9b374314047fe818caa51ae Mon Sep 17 00:00:00 2001 From: lxs Date: Tue, 4 Jun 2002 15:44:06 +0000 Subject: [PATCH] * prof_file.c: Don't double lock the mutex (causes hang). Also, only check timestamp if the file is already in the shared tree data. Otherwise just read it. * prof_set.c: Check to see whether the file is read only or has already been written to *before* mangling the shared tree data. * prof_threads.h: Use default pthread attributes when initializing mutex. git-svn-id: svn://anonsvn.mit.edu/krb5/branches/meeroh-profile-sharing-optimization@14468 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/profile/ChangeLog | 8 ++++ src/util/profile/prof_file.c | 68 ++++++++++++++++++++------------- src/util/profile/prof_set.c | 14 +++---- src/util/profile/prof_threads.h | 2 +- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 82707f5552..6121ad6869 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,11 @@ +2002-06-04 Alexandra Ellwood + * prof_file.c: Don't double lock the mutex (causes hang). Also, only + check timestamp if the file is already in the shared tree data. Otherwise + just read it. + * prof_set.c: Check to see whether the file is read only or has already + been written to *before* mangling the shared tree data. + * prof_threads.h: Use default pthread attributes when initializing mutex. + 2002-05-16 Alexandra Ellwood * prof_file.c, prof_init.c, prof_int.h, prof_set.c, profile.hin: Removed use of FSSpecs by the profile library other than FSSpec diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 99dcc4ed78..a1c34b4997 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -173,8 +173,9 @@ errcode_t profile_open_file(filespec, ret_prof) data -> refcount++; prf -> data = data; *ret_prof = prf; - retval = profile_update_file_data (data); /* make sure the saved file hasn't changed */ prof_mutex_unlock (&g_shared_trees_mutex); + /* make sure the saved file hasn't changed -- mutex must be unlocked */ + retval = profile_update_file_data (data); goto end; } /* We unlock the mutex here to avoid holding the mutex while we are reading in @@ -258,35 +259,36 @@ errcode_t profile_update_file_data(data) } #endif /* SHARE_TREE_DATA */ -#ifdef HAVE_STAT - if (stat(data->filespec, &st)) { - retval = errno; - goto end; - } - if (st.st_mtime == data->timestamp) { - retval = 0; - goto end; - } +#ifdef HAVE_STAT + /* Get the mod date of the file and verify it exists + * Don't worry about the cached data... profile_open_file + * won't let callers see it if they don't have access() + */ + if (stat(data->filespec, &st)) { + retval = errno; + goto end; + } +#endif + if (data->root) { - profile_free_node(data->root); - data->root = 0; - } - if (data->comment) { - free(data->comment); - data->comment = 0; - } + /* If the profile structure is already filled in, + * check to make sure we need to read it + */ +#ifdef HAVE_STAT + if (st.st_mtime == data->timestamp) { + retval = 0; + goto end; + } #else - /* - * If we don't have the stat() call, assume that our in-core - * memory image is correct. That is, we won't reread the - * profile file if it changes. - */ - if (data->root) { + /* If we don't have the stat() call, assume that our in-core + * memory image is correct. That is, we won't reread the + * profile file if it changes. + */ retval = 0; goto end; - } - #endif + } + errno = 0; f = fopen(data->filespec, "r"); if (f == NULL) { @@ -299,6 +301,19 @@ errcode_t profile_update_file_data(data) data->flags = 0; if (read_write_access(data->filespec)) data->flags |= PROFILE_FILE_RW; + + if (data->root) { + /* Free the old copy before profile_parse_file + * overwrites the pointer */ + profile_free_node(data->root); + data->root = 0; + } + if (data->comment) { + /* Free the old copy */ + free(data->comment); + data->comment = 0; + } + retval = profile_parse_file(f, &data->root); fclose(f); if (retval) { @@ -457,8 +472,8 @@ void profile_free_file_data(data) { #ifdef SHARE_TREE_DATA if ((data -> flags & PROFILE_FILE_SHARED) != 0) { + /* caller (profile_free_file) locked us */ /* Remove from the global list first */ - prof_mutex_lock (&g_shared_trees_mutex); if (g_shared_trees == data) { g_shared_trees = data -> next; } else { @@ -475,7 +490,6 @@ void profile_free_file_data(data) next = next -> next; } } - prof_mutex_unlock (&g_shared_trees_mutex); } #endif /* SHARE_TREE_DATA */ diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c index 7e3cc82eee..f229a8cbd2 100644 --- a/src/util/profile/prof_set.c +++ b/src/util/profile/prof_set.c @@ -34,6 +34,13 @@ static errcode_t rw_setup(profile) file = profile->first_file; + if (!(file->data->flags & PROFILE_FILE_RW)) + return PROF_READ_ONLY; + + /* Don't update the file if we've already made modifications */ + if (file->data->flags & PROFILE_FILE_DIRTY) + return 0; + #ifdef SHARE_TREE_DATA prof_mutex_lock (&g_shared_trees_mutex); /* If the file is shared and we want to write to it, get a lock */ @@ -71,13 +78,6 @@ static errcode_t rw_setup(profile) } #endif /* SHARE_TREE_DATA */ - if (!(file->data->flags & PROFILE_FILE_RW)) - return PROF_READ_ONLY; - - /* Don't update the file if we've already made modifications */ - if (file->data->flags & PROFILE_FILE_DIRTY) - return 0; - retval = profile_update_file_data(file->data); return retval; diff --git a/src/util/profile/prof_threads.h b/src/util/profile/prof_threads.h index 9b8d331691..8bc5d6d992 100644 --- a/src/util/profile/prof_threads.h +++ b/src/util/profile/prof_threads.h @@ -14,7 +14,7 @@ typedef pthread_mutex_t prof_mutex; #define prof_mutex_init(mutex) \ - pthread_mutex_init (mutex, PTHREAD_PROCESS_PRIVATE) + pthread_mutex_init (mutex, /* default attributes */ NULL) #define prof_mutex_lock(mutex) \ pthread_mutex_lock (mutex) #define prof_mutex_unlock(mutex) \