Skip to content

Commit

Permalink
* prof_file.c: Don't double lock the mutex (causes hang). Also, only …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
lxs committed Jun 4, 2002
1 parent c84ae72 commit a55d6dc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 35 deletions.
8 changes: 8 additions & 0 deletions src/util/profile/ChangeLog
@@ -1,3 +1,11 @@
2002-06-04 Alexandra Ellwood <lxs@mit.edu>
* 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 <lxs@mit.edu>
* 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
Expand Down
68 changes: 41 additions & 27 deletions src/util/profile/prof_file.c
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -475,7 +490,6 @@ void profile_free_file_data(data)
next = next -> next;
}
}
prof_mutex_unlock (&g_shared_trees_mutex);
}
#endif /* SHARE_TREE_DATA */

Expand Down
14 changes: 7 additions & 7 deletions src/util/profile/prof_set.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/util/profile/prof_threads.h
Expand Up @@ -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) \
Expand Down

0 comments on commit a55d6dc

Please sign in to comment.