From: <ca...@us...> - 2008-03-28 04:34:43
|
Revision: 1142 http://ganglia.svn.sourceforge.net/ganglia/?rev=1142&view=rev Author: carenas Date: 2008-03-27 21:34:46 -0700 (Thu, 27 Mar 2008) Log Message: ----------- gmetad: simplify use of sum_finished mutex Modified Paths: -------------- trunk/monitor-core/gmetad/gmetad.c trunk/monitor-core/gmetad/gmetad.h trunk/monitor-core/gmetad/process_xml.c trunk/monitor-core/gmetad/server.c Modified: trunk/monitor-core/gmetad/gmetad.c =================================================================== --- trunk/monitor-core/gmetad/gmetad.c 2008-03-28 04:30:37 UTC (rev 1141) +++ trunk/monitor-core/gmetad/gmetad.c 2008-03-28 04:34:46 UTC (rev 1142) @@ -187,7 +187,7 @@ return 0; /* Need to be sure the source has a complete sum for its metrics. */ - pthread_mutex_lock(source->sum_finished); + pthread_mutex_lock(&source->sum_finished); /* err_msg("Doing root summary for source %s", source->ds->name); */ @@ -198,7 +198,7 @@ root.hosts_up += source->hosts_up; root.hosts_down += source->hosts_down; - pthread_mutex_unlock(source->sum_finished); + pthread_mutex_unlock(&source->sum_finished); return rc; } @@ -381,6 +381,9 @@ } debug_msg("interactive xml listening on port %d", c->interactive_port); + /* initialize summary mutex */ + pthread_mutex_init(&root.sum_finished, NULL); + pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); Modified: trunk/monitor-core/gmetad/gmetad.h =================================================================== --- trunk/monitor-core/gmetad/gmetad.h 2008-03-28 04:30:37 UTC (rev 1141) +++ trunk/monitor-core/gmetad/gmetad.h 2008-03-28 04:34:46 UTC (rev 1142) @@ -166,7 +166,7 @@ hash_t *authority; /* Null for a grid. */ short int authority_ptr; /* An authority URL. */ hash_t *metric_summary; - pthread_mutex_t *sum_finished; /* A lock held during summarization. */ + pthread_mutex_t sum_finished; /* A lock held during summarization. */ data_source_list_t *ds; uint32_t hosts_up; uint32_t hosts_down; Modified: trunk/monitor-core/gmetad/process_xml.c =================================================================== --- trunk/monitor-core/gmetad/process_xml.c 2008-03-28 04:30:37 UTC (rev 1141) +++ trunk/monitor-core/gmetad/process_xml.c 2008-03-28 04:34:46 UTC (rev 1142) @@ -207,13 +207,11 @@ source->ds = xmldata->ds; /* Initialize the partial sum lock */ - source->sum_finished = (pthread_mutex_t*) - malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(source->sum_finished, NULL); + pthread_mutex_init(&source->sum_finished, NULL); /* Grab the "partial sum" mutex until we are finished * summarizing. */ - pthread_mutex_lock(source->sum_finished); + pthread_mutex_lock(&source->sum_finished); } else { /* Found Cluster. Put into our Source buffer in xmldata. */ @@ -224,7 +222,7 @@ /* Grab the "partial sum" mutex until we are finished * summarizing. Needs to be done asap.*/ - pthread_mutex_lock(source->sum_finished); + pthread_mutex_lock(&source->sum_finished); hash_foreach(source->metric_summary, zero_out_summary, NULL); } @@ -323,12 +321,10 @@ source->ds = xmldata->ds; /* Initialize the partial sum lock */ - source->sum_finished = (pthread_mutex_t*) - malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(source->sum_finished, NULL); + pthread_mutex_init(&source->sum_finished, NULL); /* Grab the "partial sum" mutex until we are finished summarizing. */ - pthread_mutex_lock(source->sum_finished); + pthread_mutex_lock(&source->sum_finished); } else { @@ -339,7 +335,7 @@ source->hosts_down = 0; /* We need this lock before zeroing metric sums. */ - pthread_mutex_lock(source->sum_finished); + pthread_mutex_lock(&source->sum_finished); hash_foreach(source->metric_summary, zero_out_summary, NULL); } @@ -1057,7 +1053,7 @@ summary = xmldata->source.metric_summary; /* Release the partial sum mutex */ - pthread_mutex_unlock(source->sum_finished); + pthread_mutex_unlock(&source->sum_finished); /*err_msg("%s releasing lock", xmldata->sourcename);*/ hashkey.data = (void*) xmldata->sourcename; @@ -1069,7 +1065,6 @@ /* We insert here to get an accurate hosts up/down value. */ rdatum = hash_insert( &hashkey, &hashval, xmldata->root); - source->sum_finished = NULL; /* remember that we released the lock */ if (!rdatum) { err_msg("Could not insert source %s", xmldata->sourcename); return 1; @@ -1145,14 +1140,6 @@ xmldata.rval = 1; } - /* Release lock again for good measure (required under certain errors). */ - if (xmldata.source.sum_finished) - { - rval = pthread_mutex_unlock(xmldata.source.sum_finished); - if (rval!=0) - err_msg("Could not release summary lock for %s", d->name); - } - /* Free memory that might have been allocated in xmldata */ if (xmldata.sourcename) free(xmldata.sourcename); Modified: trunk/monitor-core/gmetad/server.c =================================================================== --- trunk/monitor-core/gmetad/server.c 2008-03-28 04:30:37 UTC (rev 1141) +++ trunk/monitor-core/gmetad/server.c 2008-03-28 04:34:46 UTC (rev 1142) @@ -107,7 +107,11 @@ source->hosts_up, source->hosts_down); if (rc) return 1; - return hash_foreach(source->metric_summary, metric_summary, (void*) client); + pthread_mutex_lock(&source->sum_finished); + rc = hash_foreach(source->metric_summary, metric_summary, (void*) client); + pthread_mutex_unlock(&source->sum_finished); + + return rc; } @@ -267,7 +271,6 @@ return 0; } - int applyfilter(client_t *client, Generic_t *node) { @@ -286,16 +289,8 @@ return 0; case SUMMARY: + return source_summary((Source_t*) node, client); -/* use the mutex to avoid reporting incomplete sums -twitham (bug#76) */ - pthread_mutex_lock(((Source_t*)node)->sum_finished); - - int i = source_summary((Source_t*) node, client); - - pthread_mutex_unlock(((Source_t*)node)->sum_finished); - - return i; - default: break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |