diff src/event/ngx_event_timer.c @ 375:744ccb59062d

nginx-0.0.7-2004-07-02-19:54:34 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 02 Jul 2004 15:54:34 +0000
parents 213f17e9f776
children 73688d5d7fc3
line wrap: on
line diff
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -88,7 +88,17 @@ void ngx_event_expire_timers(ngx_msec_t 
                            ((char *) node - offsetof(ngx_event_t, rbtree_key));
 
 #if (NGX_THREADS)
-            if (ngx_trylock(ev->lock) == 0) {
+
+            if (ngx_threaded && ngx_trylock(ev->lock) == 0) {
+
+                /*
+                 * We can not change the timer of the event that is been
+                 * handling by another thread.  And we can not easy walk
+                 * the rbtree to find a next expired timer so we exit the loop.
+                 * However it should be rare case when the event that is
+                 * been handling has expired timer.
+                 */
+
                 break;
             }
 #endif
@@ -111,17 +121,23 @@ void ngx_event_expire_timers(ngx_msec_t 
 
             ev->timer_set = 0;
 
+#if (NGX_THREADS)
             if (ngx_threaded) {
                 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
                     return;
                 }
 
                 ev->posted_timedout = 1;
+                ev->returned_instance = ev->instance;
                 ngx_post_event(ev);
 
                 ngx_mutex_unlock(ngx_posted_events_mutex);
+
+                ngx_unlock(ev->lock);
+
                 continue;
             }
+#endif
 
             ev->timedout = 1;