Author: mturk Date: Thu Oct 23 23:42:01 2008 New Revision: 707561 URL: http://svn.apache.org/viewvc?rev=707561&view=rev Log: Ensure that maintain cannot be executed by multiple threads if maintain takes longer then maintain_time
Modified: tomcat/connectors/trunk/jk/native/common/jk_worker.c Modified: tomcat/connectors/trunk/jk/native/common/jk_worker.c URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_worker.c?rev=707561&r1=707560&r2=707561&view=diff ============================================================================== --- tomcat/connectors/trunk/jk/native/common/jk_worker.c (original) +++ tomcat/connectors/trunk/jk/native/common/jk_worker.c Thu Oct 23 23:42:01 2008 @@ -305,18 +305,28 @@ void wc_maintain(jk_logger_t *l) { static time_t last_maintain = 0; + static int running_maintain = 0; int sz = jk_map_size(worker_map); JK_TRACE_ENTER(l); if (sz > 0 && worker_maintain_time > 0) { int i; - time_t now; + JK_ENTER_CS(&worker_lock, i); - now = time(NULL); - if (difftime(now, last_maintain) >= worker_maintain_time) { - last_maintain = now; + if (running_maintain) { + /* Already in maintain */ + JK_LEAVE_CS(&worker_lock, i); + JK_TRACE_EXIT(l); + return; + } + if (difftime(time(NULL), last_maintain) >= worker_maintain_time) { + /* Set the maintain run flag so other threads skip + * the maintain until we are finished. + */ + running_maintain = 1; JK_LEAVE_CS(&worker_lock, i); + for (i = 0; i < sz; i++) { jk_worker_t *w = jk_map_value_at(worker_map, i); if (w && w->maintain) { @@ -324,9 +334,13 @@ jk_log(l, JK_LOG_DEBUG, "Maintaining worker %s", jk_map_name_at(worker_map, i)); - w->maintain(w, now, l); + w->maintain(w, time(NULL), l); } } + JK_ENTER_CS(&worker_lock, i); + last_maintain = time(NULL); + running_maintain = 0; + JK_LEAVE_CS(&worker_lock, i); } else { JK_LEAVE_CS(&worker_lock, i); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]