nginx-quic/src/event/ngx_event_posted.c

148 lines
3.5 KiB
C
Raw Normal View History

2004-04-04 16:32:09 -04:00
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
ngx_thread_volatile ngx_event_t *ngx_posted_events;
2004-06-27 14:01:57 -04:00
2004-04-04 16:32:09 -04:00
#if (NGX_THREADS)
ngx_mutex_t *ngx_posted_events_mutex;
2004-06-28 12:05:02 -04:00
ngx_cond_t *ngx_posted_events_cv;
2004-04-04 16:32:09 -04:00
#endif
void ngx_event_process_posted(ngx_cycle_t *cycle)
{
ngx_event_t *ev;
for ( ;; ) {
ev = (ngx_event_t *) ngx_posted_events;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT, ev);
if (ev == NULL) {
return;
}
2004-07-02 11:54:34 -04:00
ngx_delete_posted_event(ev);
#if 0
/* do not check instance ??? */
2004-04-04 16:32:09 -04:00
2004-04-13 11:08:48 -04:00
if (ev->accept) {
continue;
}
2004-07-02 11:54:34 -04:00
#endif
2004-04-13 11:08:48 -04:00
2004-07-02 11:54:34 -04:00
if (ev->closed
2004-04-04 16:32:09 -04:00
|| (ev->use_instance && ev->instance != ev->returned_instance))
{
/*
* the stale event from a file descriptor
* that was just closed in this iteration
*/
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
2004-06-09 16:03:54 -04:00
"stale posted event " PTR_FMT, ev);
2004-04-04 16:32:09 -04:00
continue;
}
ev->event_handler(ev);
}
}
#if (NGX_THREADS)
2004-06-27 14:01:57 -04:00
ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle)
2004-04-04 16:32:09 -04:00
{
2004-07-02 11:54:34 -04:00
ngx_event_t *ev;
2004-04-04 16:32:09 -04:00
2004-06-27 14:01:57 -04:00
for ( ;; ) {
ev = (ngx_event_t *) ngx_posted_events;
for ( ;; ) {
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT, ev);
if (ev == NULL) {
ngx_mutex_unlock(ngx_posted_events_mutex);
return NGX_OK;
}
2004-06-28 12:05:02 -04:00
if (ngx_trylock(ev->lock) == 0) {
2004-06-27 14:01:57 -04:00
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"posted event " PTR_FMT " is busy", ev);
ev = ev->next;
continue;
}
2004-04-04 16:32:09 -04:00
2004-07-02 11:54:34 -04:00
ngx_delete_posted_event(ev);
2004-06-27 14:01:57 -04:00
2004-07-02 11:54:34 -04:00
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"event instance: c:%d i:%d r:%d",
ev->closed, ev->instance, ev->returned_instance);
if (ev->closed
2004-06-27 14:01:57 -04:00
|| (ev->use_instance && ev->instance != ev->returned_instance))
{
/*
2004-06-28 17:03:14 -04:00
* The stale event from a file descriptor that was just
* closed in this iteration. We use ngx_cycle->log
* because ev->log may be already destoyed.
2004-06-27 14:01:57 -04:00
*/
2004-06-28 17:03:14 -04:00
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
2004-07-02 11:54:34 -04:00
"stale posted event " PTR_FMT, ev);
2004-06-27 14:01:57 -04:00
2004-06-28 17:03:14 -04:00
ngx_unlock(ev->lock);
2004-06-27 14:01:57 -04:00
ev = ev->next;
continue;
}
2004-07-02 01:47:00 -04:00
ev->locked = 1;
2004-06-27 14:01:57 -04:00
2004-07-02 11:54:34 -04:00
ev->ready |= ev->posted_ready;
ev->timedout |= ev->posted_timedout;
ev->available |= ev->posted_available;
ev->pending_eof |= ev->posted_eof;
2004-07-02 01:47:00 -04:00
#if (HAVE_KQUEUE)
2004-07-02 11:54:34 -04:00
ev->kq_errno |= ev->posted_errno;
#endif
ev->posted_ready = 0;
ev->posted_timedout = 0;
ev->posted_available = 0;
ev->posted_eof = 0;
#if (HAVE_KQUEUE)
ev->posted_errno = 0;
2004-07-02 01:47:00 -04:00
#endif
2004-06-27 14:01:57 -04:00
2004-07-02 01:47:00 -04:00
ngx_mutex_unlock(ngx_posted_events_mutex);
2004-06-27 14:01:57 -04:00
2004-07-02 01:47:00 -04:00
ev->event_handler(ev);
2004-06-27 14:01:57 -04:00
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return NGX_ERROR;
}
2004-07-02 01:47:00 -04:00
if (ev->locked) {
ngx_unlock(ev->lock);
}
2004-06-27 14:01:57 -04:00
break;
}
}
2004-04-04 16:32:09 -04:00
}
#endif