mirror of
https://github.com/nginx/nginx.git
synced 2024-11-29 01:09:53 +08:00
nginx-0.0.2-2004-02-26-20:10:01 import
This commit is contained in:
parent
f2334416e7
commit
898446c8ba
@ -77,10 +77,8 @@ void ngx_time_update(time_t s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if (NGX_THREADS)
|
#if (NGX_THREADS)
|
||||||
if (ngx_time_mutex) {
|
if (ngx_mutex_trylock(ngx_time_mutex) != NGX_OK) {
|
||||||
if (ngx_mutex_trylock(ngx_time_mutex) != NGX_OK) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -119,9 +117,7 @@ void ngx_time_update(time_t s)
|
|||||||
tm.ngx_tm_sec);
|
tm.ngx_tm_sec);
|
||||||
|
|
||||||
#if (NGX_THREADS)
|
#if (NGX_THREADS)
|
||||||
if (ngx_time_mutex) {
|
ngx_mutex_unlock(ngx_time_mutex);
|
||||||
ngx_mutex_unlock(ngx_time_mutex);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -413,6 +413,12 @@ static ngx_int_t ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (NGX_THREADS0)
|
||||||
|
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < events; i++) {
|
for (i = 0; i < events; i++) {
|
||||||
|
|
||||||
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0,
|
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0,
|
||||||
@ -468,41 +474,109 @@ static ngx_int_t ngx_kqueue_process_events(ngx_log_t *log)
|
|||||||
|
|
||||||
ev->ready = 1;
|
ev->ready = 1;
|
||||||
|
|
||||||
ev->event_handler(ev);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVFILT_VNODE:
|
case EVFILT_VNODE:
|
||||||
ev->kq_vnode = 1;
|
ev->kq_vnode = 1;
|
||||||
|
|
||||||
ev->event_handler(ev);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVFILT_AIO:
|
case EVFILT_AIO:
|
||||||
ev->complete = 1;
|
ev->complete = 1;
|
||||||
ev->ready = 1;
|
ev->ready = 1;
|
||||||
|
|
||||||
ev->event_handler(ev);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
ngx_log_error(NGX_LOG_ALERT, log, 0,
|
||||||
"unexpected kevent() filter %d",
|
"unexpected kevent() filter %d",
|
||||||
event_list[i].filter);
|
event_list[i].filter);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (NGX_THREADS0)
|
||||||
|
|
||||||
|
if (ngx_threaded) {
|
||||||
|
|
||||||
|
if (ev->light) {
|
||||||
|
|
||||||
|
/* the accept event */
|
||||||
|
|
||||||
|
ngx_mutex_unlock(ngx_posted_events_mutex);
|
||||||
|
|
||||||
|
ev->event_handler(ev);
|
||||||
|
|
||||||
|
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ev->next = ngx_posted_events;
|
||||||
|
ngx_posted_events = ev;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ev->event_handler(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (NGX_THREADS0)
|
||||||
|
ngx_mutex_unlock(ngx_posted_events_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (timer && delta) {
|
if (timer && delta) {
|
||||||
ngx_event_expire_timers((ngx_msec_t) delta);
|
ngx_event_expire_timers((ngx_msec_t) delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (NGX_THREADS0)
|
||||||
|
if (!ngx_threaded) {
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* TODO: non-thread mode only */
|
||||||
|
|
||||||
|
ev = ngx_posted_events;
|
||||||
|
ngx_posted_events = NULL;
|
||||||
|
|
||||||
|
while (ev) {
|
||||||
|
ev->event_handler(ev);
|
||||||
|
ev = ev->next;
|
||||||
|
}
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if (NGX_THREADS)
|
||||||
|
|
||||||
|
static void ngx_kqueue_thread_handler(ngx_event_t *ev)
|
||||||
|
{
|
||||||
|
ngx_int_t instance;
|
||||||
|
|
||||||
|
instance = (uintptr_t) ev & 1;
|
||||||
|
ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1);
|
||||||
|
|
||||||
|
if (ev->active == 0 || ev->instance != instance) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the stale event from a file descriptor
|
||||||
|
* that was just closed in this iteration
|
||||||
|
*/
|
||||||
|
|
||||||
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
||||||
|
"kevent: stale event " PTR_FMT, ev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev->event_handler(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle)
|
static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
ngx_kqueue_conf_t *kcf;
|
ngx_kqueue_conf_t *kcf;
|
||||||
|
@ -45,6 +45,7 @@ ngx_event_actions_t ngx_event_actions;
|
|||||||
|
|
||||||
static int ngx_event_max_module;
|
static int ngx_event_max_module;
|
||||||
|
|
||||||
|
ngx_event_t *ngx_posted_events;
|
||||||
|
|
||||||
|
|
||||||
static ngx_str_t events_name = ngx_string("events");
|
static ngx_str_t events_name = ngx_string("events");
|
||||||
|
@ -27,8 +27,7 @@ struct ngx_event_s {
|
|||||||
|
|
||||||
u_int index;
|
u_int index;
|
||||||
|
|
||||||
/* queue in mutex(), aio_read(), aio_write() */
|
/* the link of the posted queue or the event mutecies queues */
|
||||||
ngx_event_t *prev;
|
|
||||||
ngx_event_t *next;
|
ngx_event_t *next;
|
||||||
|
|
||||||
ngx_log_t *log;
|
ngx_log_t *log;
|
||||||
@ -374,6 +373,8 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern ngx_event_t *ngx_posted_events;
|
||||||
|
|
||||||
extern int ngx_event_flags;
|
extern int ngx_event_flags;
|
||||||
extern ngx_module_t ngx_events_module;
|
extern ngx_module_t ngx_events_module;
|
||||||
extern ngx_module_t ngx_event_core_module;
|
extern ngx_module_t ngx_event_core_module;
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ngx_int_t ngx_threaded;
|
||||||
|
|
||||||
static inline int ngx_gettid();
|
static inline int ngx_gettid();
|
||||||
|
|
||||||
|
|
||||||
@ -204,6 +206,8 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
|
|||||||
/* allow the spinlock in libc malloc() */
|
/* allow the spinlock in libc malloc() */
|
||||||
__isthreaded = 1;
|
__isthreaded = 1;
|
||||||
|
|
||||||
|
ngx_threaded = 1;
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,6 +319,10 @@ ngx_int_t ngx_mutex_do_lock(ngx_mutex_t *m, ngx_int_t try)
|
|||||||
ngx_uint_t tries;
|
ngx_uint_t tries;
|
||||||
struct sembuf op;
|
struct sembuf op;
|
||||||
|
|
||||||
|
if (!ngx_threaded) {
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#if (NGX_DEBUG)
|
#if (NGX_DEBUG)
|
||||||
if (try) {
|
if (try) {
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
|
ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
|
||||||
@ -438,6 +446,10 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
|
|||||||
uint32_t lock, new, old;
|
uint32_t lock, new, old;
|
||||||
struct sembuf op;
|
struct sembuf op;
|
||||||
|
|
||||||
|
if (!ngx_threaded) {
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
old = m->lock;
|
old = m->lock;
|
||||||
|
|
||||||
if (!(old & NGX_MUTEX_LOCK_BUSY)) {
|
if (!(old & NGX_MUTEX_LOCK_BUSY)) {
|
||||||
|
@ -60,6 +60,9 @@ ngx_int_t ngx_mutex_do_lock(ngx_mutex_t *m, ngx_int_t try);
|
|||||||
ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m);
|
ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m);
|
||||||
|
|
||||||
|
|
||||||
|
extern ngx_int_t ngx_threaded;
|
||||||
|
|
||||||
|
|
||||||
#else /* !NGX_THREADS */
|
#else /* !NGX_THREADS */
|
||||||
|
|
||||||
#define ngx_log_tid 0
|
#define ngx_log_tid 0
|
||||||
|
Loading…
Reference in New Issue
Block a user