src/os/unix/ngx_thread_cond.c - nginx source code

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. ngx_int_t
  8. ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log)
  9. {
  10.     ngx_err_t  err;

  11.     err = pthread_cond_init(cond, NULL);
  12.     if (err == 0) {
  13.         return NGX_OK;
  14.     }

  15.     ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_init() failed");
  16.     return NGX_ERROR;
  17. }


  18. ngx_int_t
  19. ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log)
  20. {
  21.     ngx_err_t  err;

  22.     err = pthread_cond_destroy(cond);
  23.     if (err == 0) {
  24.         return NGX_OK;
  25.     }

  26.     ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_destroy() failed");
  27.     return NGX_ERROR;
  28. }


  29. ngx_int_t
  30. ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log)
  31. {
  32.     ngx_err_t  err;

  33.     err = pthread_cond_signal(cond);
  34.     if (err == 0) {
  35.         return NGX_OK;
  36.     }

  37.     ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_signal() failed");
  38.     return NGX_ERROR;
  39. }


  40. ngx_int_t
  41. ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx,
  42.     ngx_log_t *log)
  43. {
  44.     ngx_err_t  err;

  45.     err = pthread_cond_wait(cond, mtx);

  46. #if 0
  47.     ngx_time_update();
  48. #endif

  49.     if (err == 0) {
  50.         return NGX_OK;
  51.     }

  52.     ngx_log_error(NGX_LOG_ALERT, log, err, "pthread_cond_wait() failed");

  53.     return NGX_ERROR;
  54. }