nginx-quic/src/event/ngx_event_posted.c

133 lines
3.1 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;
}
ngx_posted_events = ev->next;
2004-04-13 11:08:48 -04:00
if (ev->accept) {
continue;
}
2004-04-04 16:32:09 -04:00
if ((!ev->posted && !ev->active)
|| (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;
}
if (ev->posted) {
ev->posted = 0;
}
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-06-27 14:01:57 -04:00
ngx_event_t *ev, **ep;
2004-04-04 16:32:09 -04:00
2004-06-27 14:01:57 -04:00
for ( ;; ) {
ev = (ngx_event_t *) ngx_posted_events;
ep = (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);
ep = &ev->next;
ev = ev->next;
continue;
}
2004-04-04 16:32:09 -04:00
2004-06-27 14:01:57 -04:00
*ep = ev->next;
if ((!ev->posted && !ev->active)
|| (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-06-27 14:01:57 -04:00
"kevent: stale event " PTR_FMT, ev);
2004-06-28 17:03:14 -04:00
ngx_unlock(ev->lock);
2004-06-27 14:01:57 -04:00
ev = ev->next;
continue;
}
ngx_mutex_unlock(ngx_posted_events_mutex);
if (ev->posted) {
ev->posted = 0;
2004-06-30 11:30:41 -04:00
if (!ev->timedout) {
ev->ready = 1;
}
2004-06-27 14:01:57 -04:00
}
ev->event_handler(ev);
2004-06-28 12:05:02 -04:00
ngx_unlock(ev->lock);
2004-06-27 14:01:57 -04:00
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return NGX_ERROR;
}
break;
}
}
2004-04-04 16:32:09 -04:00
}
#endif