src/event/ngx_event_mutex.c - nginx-1.7.10

Functions defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #include <ngx_config.h>
  6. #include <ngx_core.h>
  7. #include <ngx_event.h>


  8. ngx_int_t ngx_event_mutex_timedlock(ngx_event_mutex_t *m, ngx_msec_t timer,
  9.                                     ngx_event_t *ev)
  10. {
  11.     ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
  12.                    "lock event mutex %p lock:%XD", m, m->lock);

  13.     if (m->lock) {

  14.         if (m->events == NULL) {
  15.             m->events = ev;

  16.         } else {
  17.             m->last->next = ev;
  18.         }

  19.         m->last = ev;
  20.         ev->next = NULL;

  21. #if (NGX_THREADS0)
  22.         ev->light = 1;
  23. #endif

  24.         ngx_add_timer(ev, timer);

  25.         return NGX_AGAIN;
  26.     }

  27.     m->lock = 1;

  28.     return NGX_OK;
  29. }


  30. ngx_int_t ngx_event_mutex_unlock(ngx_event_mutex_t *m, ngx_log_t *log)
  31. {
  32.     ngx_event_t  *ev;

  33.     if (m->lock == 0) {
  34.         ngx_log_error(NGX_LOG_ALERT, log, 0,
  35.                       "tring to unlock the free event mutex %p", m);
  36.         return NGX_ERROR;
  37.     }

  38.     ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
  39.                    "unlock event mutex %p, next event: %p", m, m->events);

  40.     m->lock = 0;

  41.     if (m->events) {
  42.         ev = m->events;
  43.         m->events = ev->next;

  44.         ev->next = ngx_posted_events;
  45.         ngx_posted_events = ev;
  46.     }

  47.     return NGX_OK;
  48. }