Mercurial > hg > nginx
view src/event/ngx_event_thread.c @ 227:2ba3477070ac
nginx-0.0.1-2004-01-14-21:19:42 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 Jan 2004 18:19:42 +0000 |
parents | 0b67be7d4489 |
children |
line wrap: on
line source
volitile int ngx_last_posted_event; typedef struct { ngx_tid_t tid; ngx_cv_t cv; } ngx_thread_data_t; static ngx_thread_data_t *threead_data; { err = ngx_thread_cond_wait(ngx_thread_data_cv, ngx_thread_data_mutex); tid = ngx_thread_self(); for (i = 0; i < thread_data_n; i++) { if (thread_data[i].tid == tid) { cv = thread_data[i].cv; break; } } if (i == thread_data_n) { error return } for ( ;; ) { err = ngx_thread_cond_wait(cv, ngx_posted_events_mutex); if (err) { ngx_log_error(NGX_ALERT, log, err, ngx_thread_cond_wait_n " failed, thread is exiting"); return; } for ( ;; ) { ev = NULL; for (i = ngx_last_posted_event; i > 0; i--) { ev = ngx_posted_events[i]; if (ev == NULL) { continue; } err = ngx_thread_mutex_trylock(ev->mutex); if (err == 0) { ngx_posted_events[i] = NULL; while (ngx_posted_events[ngx_last_posted_event] == NULL) { ngx_last_posted_event--; } break; } if (err == NGX_EBUSY) { ev = NULL; continue; } ngx_log_error(NGX_ALERT, log, err, ngx_thread_mutex_unlock_n " failed, thread is exiting"); ngx_worker_thread_error(); return; } err = ngx_thread_mutex_unlock(ngx_posted_events_mutex); if (err) { ngx_log_error(NGX_ALERT, log, err, ngx_thread_mutex_unlock_n " failed, thread exiting"); return; } if (ev == NULL) { break; } ngx_event_handle_event(ev); err = ngx_thread_mutex_unlock(ev->mutex); if (err) { ngx_log_error(NGX_ALERT, log, err, ngx_thread_mutex_unlock_n " failed, thread exiting"); ngx_worker_thread_error(); return; } err = ngx_thread_mutex_lock(ngx_posted_events_mutex); if (err) { ngx_log_error(NGX_ALERT, log, err, ngx_thread_mutex_lock_n " failed, thread exiting"); return; } } if (restart) { ngx_log_error(NGX_INFO, log, 0, "thread is exiting"); return; } } } ngx_worker_thread_error() { ngx_err_t err; err = ngx_thread_mutex_unlock(ngx_posted_events_mutex); if (err) { ngx_log_error(NGX_ALERT, log, err, ngx_thread_mutex_unlock_n " failed, thread exiting"); } }