diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-28 20:05:02 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-28 20:05:02 +0400 |
commit | b14b91020284baf090b40bdb6ba87b99751f27fb (patch) | |
tree | 5c0a3b3cd099910a1d9698b6972db858839b3067 /src/event | |
parent | c02473048cee372cb8644e1f2d566431781074d2 (diff) |
nginx-0.0.7-2004-06-28-20:05:02 import
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 26 | ||||
-rw-r--r-- | src/event/ngx_event_posted.c | 6 | ||||
-rw-r--r-- | src/event/ngx_event_posted.h | 2 | ||||
-rw-r--r-- | src/event/ngx_event_timer.c | 29 | ||||
-rw-r--r-- | src/event/ngx_event_timer.h | 8 |
5 files changed, 43 insertions, 28 deletions
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 001d6a85e..99370ac42 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -361,11 +361,10 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) return NGX_ERROR; } - /* - * TODO: if timer is NGX_TIMER_INFINITE and any worker thread - * is still busy then set the configurable 500ms timeout - * to wake up another worker thread - */ + if (timer == NGX_TIMER_INFINITE || timer > 500) { + timer = 500; + break; + } #endif @@ -461,12 +460,17 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) } } - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - ngx_accept_mutex_unlock(); - return NGX_ERROR; - } + if (events > 0) { + if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { + ngx_accept_mutex_unlock(); + return NGX_ERROR; + } - lock = 1; + lock = 1; + + } else { + lock =0; + } for (i = 0; i < events; i++) { @@ -588,7 +592,7 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) if (ngx_posted_events) { if (ngx_threaded) { - ngx_cv_signal(ngx_posted_events_cv); + ngx_cond_signal(ngx_posted_events_cv); } else { ngx_event_process_posted(cycle); diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c index 478744341..b103159b0 100644 --- a/src/event/ngx_event_posted.c +++ b/src/event/ngx_event_posted.c @@ -8,7 +8,7 @@ ngx_thread_volatile ngx_event_t *ngx_posted_events; #if (NGX_THREADS) ngx_mutex_t *ngx_posted_events_mutex; -ngx_cv_t *ngx_posted_events_cv; +ngx_cond_t *ngx_posted_events_cv; #endif @@ -76,7 +76,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) return NGX_OK; } - if (ngx_trylock(ev->lock) == NGX_BUSY) { + if (ngx_trylock(ev->lock) == 0) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "posted event " PTR_FMT " is busy", ev); @@ -112,7 +112,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) ev->event_handler(ev); - *(ev->lock) = 0; + ngx_unlock(ev->lock); if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { return NGX_ERROR; diff --git a/src/event/ngx_event_posted.h b/src/event/ngx_event_posted.h index b060cc6d9..ba484fac0 100644 --- a/src/event/ngx_event_posted.h +++ b/src/event/ngx_event_posted.h @@ -22,7 +22,7 @@ extern ngx_thread_volatile ngx_event_t *ngx_posted_events; ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle); extern ngx_mutex_t *ngx_posted_events_mutex; -extern ngx_cv_t *ngx_posted_events_cv; +extern ngx_cond_t *ngx_posted_events_cv; #endif diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index fb401cf84..0f6de6793 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -71,7 +71,7 @@ void ngx_event_expire_timers(ngx_msec_t timer) for ( ;; ) { if (ngx_event_timer_rbtree == &ngx_event_timer_sentinel) { - break; + return; } if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { @@ -81,17 +81,35 @@ void ngx_event_expire_timers(ngx_msec_t timer) node = ngx_rbtree_min((ngx_rbtree_t *) ngx_event_timer_rbtree, &ngx_event_timer_sentinel); - ngx_mutex_unlock(ngx_event_timer_mutex); - if (node->key <= (ngx_msec_t) (ngx_old_elapsed_msec + timer) / NGX_TIMER_RESOLUTION) { ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, rbtree_key)); - ngx_del_timer(ev); + if (ngx_trylock(ev->lock) == 0) { + break; + } + + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "event timer del: %d: %d", + ngx_event_ident(ev->data), ev->rbtree_key); + + ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree, + &ngx_event_timer_sentinel, + (ngx_rbtree_t *) &ev->rbtree_key); + + ngx_mutex_unlock(ngx_event_timer_mutex); +#if (NGX_DEBUG) + ev->rbtree_left = NULL; + ev->rbtree_right = NULL; + ev->rbtree_parent = NULL; +#endif + + ev->timer_set = 0; ev->timedout = 1; + ngx_unlock(ev->lock); if (ngx_threaded) { if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { @@ -107,7 +125,8 @@ void ngx_event_expire_timers(ngx_msec_t timer) ev->event_handler(ev); continue; } - break; } + + ngx_mutex_unlock(ngx_event_timer_mutex); } diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h index e7e49d28d..0ff640539 100644 --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -42,19 +42,15 @@ ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) "event timer del: %d: %d", ngx_event_ident(ev->data), ev->rbtree_key); -#if (NGX_THREADS) if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { return; } -#endif ngx_rbtree_delete((ngx_rbtree_t **) &ngx_event_timer_rbtree, &ngx_event_timer_sentinel, (ngx_rbtree_t *) &ev->rbtree_key); -#if (NGX_THREADS) ngx_mutex_unlock(ngx_event_timer_mutex); -#endif #if (NGX_DEBUG) ev->rbtree_left = NULL; @@ -101,19 +97,15 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) "event timer add: %d: %d", ngx_event_ident(ev->data), ev->rbtree_key); -#if (NGX_THREADS) if (ngx_mutex_lock(ngx_event_timer_mutex) == NGX_ERROR) { return; } -#endif ngx_rbtree_insert((ngx_rbtree_t **) &ngx_event_timer_rbtree, &ngx_event_timer_sentinel, (ngx_rbtree_t *) &ev->rbtree_key); -#if (NGX_THREADS) ngx_mutex_unlock(ngx_event_timer_mutex); -#endif ev->timer_set = 1; } |