diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-30 19:30:41 +0400 |
commit | 078d1b2c2263690f2f6b7217b567eeeb525910d0 (patch) | |
tree | dfb82cccd10c3dee8a500506f7692b0445200e5c /src/event | |
parent | 0a94cfd2ae9ca87b4d988b5066f739a3034f3bff (diff) |
nginx-0.0.7-2004-06-30-19:30:41 import
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 3 | ||||
-rw-r--r-- | src/event/ngx_event_accept.c | 21 | ||||
-rw-r--r-- | src/event/ngx_event_posted.c | 3 | ||||
-rw-r--r-- | src/event/ngx_event_posted.h | 34 | ||||
-rw-r--r-- | src/event/ngx_event_spinlock.c | 26 |
5 files changed, 60 insertions, 27 deletions
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index cc84d2eaa..379e5304d 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -506,7 +506,6 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) instance = (uintptr_t) ev & 1; ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1); - ev->returned_instance = instance; if (!ev->active || ev->instance != instance) { @@ -520,6 +519,8 @@ static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle) continue; } + ev->returned_instance = instance; + if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { ngx_kqueue_dump_event(ev->log, &event_list[i]); } diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index 984570f80..18f8586cd 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -210,10 +210,31 @@ void ngx_event_accept(ngx_event_t *ev) rinstance = rev->returned_instance; winstance = wev->returned_instance; +#if (NGX_THREADS) + + /* + * We has to acquire the lock to avoid the race condition when + * the connection was just closed by another thread but its lock + * is not unlocked at this point and we got the same descriptor. + * + * The condition should be too rare. + */ + + if (ngx_trylock(&c->lock) == 0) { + + /* TODO: ngx_cycle->stat.accept.spinlock++; */ + + ngx_spinlock(&c->lock, 1000); + } + +#endif + ngx_memzero(rev, sizeof(ngx_event_t)); ngx_memzero(wev, sizeof(ngx_event_t)); ngx_memzero(c, sizeof(ngx_connection_t)); + /* ngx_memzero(c) does ngx_unlock(&c->lock); */ + c->pool = pool; c->listening = ls->listening; diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c index 795aa6171..0c91f4ea5 100644 --- a/src/event/ngx_event_posted.c +++ b/src/event/ngx_event_posted.c @@ -111,6 +111,9 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) if (ev->posted) { ev->posted = 0; + if (!ev->timedout) { + ev->ready = 1; + } } ev->event_handler(ev); diff --git a/src/event/ngx_event_posted.h b/src/event/ngx_event_posted.h index c2945c4ff..5059fa9ad 100644 --- a/src/event/ngx_event_posted.h +++ b/src/event/ngx_event_posted.h @@ -7,6 +7,19 @@ #include <ngx_event.h> +typedef struct ngx_posted_events_s ngx_posted_event_t; + +struct ngx_posted_events_s { + ngx_event_t *event; + ngx_posted_event_t *next; + + unsigned instance:1; + unsigned ready:1; + unsigned timedout:1; + unsigned complete:1; +}; + + #define ngx_post_event(ev) \ if (!ev->posted) { \ ev->next = (ngx_event_t *) ngx_posted_events; \ @@ -14,6 +27,27 @@ ev->posted = 1; \ } +/* +\ + ngx_log_debug3(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, \ + "POST: %08X %08X %08X", ngx_posted_events, \ + (ngx_posted_events ? ngx_posted_events->next: 0), \ + ((ngx_posted_events && ngx_posted_events->next) ? \ + ngx_posted_events->next->next: 0)); \ +\ +*/ + +/* +\ +{ int i; ngx_event_t *e;\ + e = (ngx_event_t *) ngx_posted_events; \ +for (i = 0; e && i < 10; e = e->next, i++) { \ + ngx_log_debug2(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, \ + "POST: %d %08X", i, e);\ +}} \ +\ +*/ + void ngx_event_process_posted(ngx_cycle_t *cycle); diff --git a/src/event/ngx_event_spinlock.c b/src/event/ngx_event_spinlock.c deleted file mode 100644 index 58edb2af5..000000000 --- a/src/event/ngx_event_spinlock.c +++ /dev/null @@ -1,26 +0,0 @@ - - -void _spinlock(ngx_atomic_t *lock) -{ - ngx_int_t tries; - - tries = 0; - - for ( ;; ) { - - if (*lock) { - if (ngx_ncpu > 1 && tries++ < 1000) { - continue; - } - - sched_yield(); - tries = 0; - - } else { - if (ngx_atomic_cmp_set(lock, 0, 1)) { - return; - } - } - } -} - |