Igor Sysoev | 0c331d9 | 2002-08-15 17:20:26 +0000 | [diff] [blame] | 1 | |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 7 | #include <ngx_config.h> |
| 8 | #include <ngx_core.h> |
| 9 | #include <ngx_event.h> |
Igor Sysoev | 0c331d9 | 2002-08-15 17:20:26 +0000 | [diff] [blame] | 10 | |
| 11 | |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 12 | ngx_int_t ngx_event_mutex_timedlock(ngx_event_mutex_t *m, ngx_msec_t timer, |
| 13 | ngx_event_t *ev) |
Igor Sysoev | 0c331d9 | 2002-08-15 17:20:26 +0000 | [diff] [blame] | 14 | { |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 15 | ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 16 | "lock event mutex %p lock:%XD", m, m->lock); |
Igor Sysoev | 0c331d9 | 2002-08-15 17:20:26 +0000 | [diff] [blame] | 17 | |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 18 | 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 Sysoev | 83a7a2e | 2004-03-01 16:45:48 +0000 | [diff] [blame] | 30 | #if (NGX_THREADS0) |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 31 | 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 | |
| 45 | ngx_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 Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 51 | "tring to unlock the free event mutex %p", m); |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 52 | return NGX_ERROR; |
| 53 | } |
| 54 | |
| 55 | ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, |
Igor Sysoev | 1b73583 | 2004-11-11 14:07:14 +0000 | [diff] [blame] | 56 | "unlock event mutex %p, next event: %p", m, m->events); |
Igor Sysoev | d94049b | 2004-02-29 21:03:02 +0000 | [diff] [blame] | 57 | |
| 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 Sysoev | 0c331d9 | 2002-08-15 17:20:26 +0000 | [diff] [blame] | 69 | } |