blob: 2335e5bafd0f8f6134bc17234f10d5b01b0ceb53 [file] [log] [blame]
Igor Sysoev0c331d92002-08-15 17:20:26 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoevd94049b2004-02-29 21:03:02 +00007#include <ngx_config.h>
8#include <ngx_core.h>
9#include <ngx_event.h>
Igor Sysoev0c331d92002-08-15 17:20:26 +000010
11
Igor Sysoevd94049b2004-02-29 21:03:02 +000012ngx_int_t ngx_event_mutex_timedlock(ngx_event_mutex_t *m, ngx_msec_t timer,
13 ngx_event_t *ev)
Igor Sysoev0c331d92002-08-15 17:20:26 +000014{
Igor Sysoevd94049b2004-02-29 21:03:02 +000015 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +000016 "lock event mutex %p lock:%XD", m, m->lock);
Igor Sysoev0c331d92002-08-15 17:20:26 +000017
Igor Sysoevd94049b2004-02-29 21:03:02 +000018 if (m->lock) {
19
20 if (m->events == NULL) {
21 m->events = ev;
22
23 } else {
24 m->last->next = ev;
25 }
26
27 m->last = ev;
28 ev->next = NULL;
29
Igor Sysoev83a7a2e2004-03-01 16:45:48 +000030#if (NGX_THREADS0)
Igor Sysoevd94049b2004-02-29 21:03:02 +000031 ev->light = 1;
32#endif
33
34 ngx_add_timer(ev, timer);
35
36 return NGX_AGAIN;
37 }
38
39 m->lock = 1;
40
41 return NGX_OK;
42}
43
44
45ngx_int_t ngx_event_mutex_unlock(ngx_event_mutex_t *m, ngx_log_t *log)
46{
47 ngx_event_t *ev;
48
49 if (m->lock == 0) {
50 ngx_log_error(NGX_LOG_ALERT, log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +000051 "tring to unlock the free event mutex %p", m);
Igor Sysoevd94049b2004-02-29 21:03:02 +000052 return NGX_ERROR;
53 }
54
55 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
Igor Sysoev1b735832004-11-11 14:07:14 +000056 "unlock event mutex %p, next event: %p", m, m->events);
Igor Sysoevd94049b2004-02-29 21:03:02 +000057
58 m->lock = 0;
59
60 if (m->events) {
61 ev = m->events;
62 m->events = ev->next;
63
64 ev->next = (ngx_event_t *) ngx_posted_events;
65 ngx_posted_events = ev;
66 }
67
68 return NGX_OK;
Igor Sysoev0c331d92002-08-15 17:20:26 +000069}