src/os/unix/ngx_freebsd_rfork_thread.h - nginx-1.7.10

Data types defined

Functions defined

Macros defined

Source code


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


  5. #ifndef _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_
  6. #define _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_


  7. #include <sys/ipc.h>
  8. #include <sys/sem.h>
  9. #include <sched.h>

  10. typedef pid_t  ngx_tid_t;

  11. #define ngx_log_pid    ngx_thread_self()
  12. #define ngx_log_tid    0

  13. #define NGX_TID_T_FMT  "%P"


  14. #define NGX_MUTEX_LIGHT      1

  15. #define NGX_MUTEX_LOCK_BUSY  0x80000000

  16. typedef volatile struct {
  17.     ngx_atomic_t  lock;
  18.     ngx_log_t    *log;
  19.     int           semid;
  20. } ngx_mutex_t;


  21. #define NGX_CV_SIGNAL        64

  22. typedef struct {
  23.     int           signo;
  24.     int           kq;
  25.     ngx_tid_t     tid;
  26.     ngx_log_t    *log;
  27. } ngx_cond_t;


  28. #define ngx_thread_sigmask(how, set, oset)                         \
  29.             (sigprocmask(how, set, oset) == -1) ? ngx_errno : 0

  30. #define ngx_thread_sigmask_n   "sigprocmask()"

  31. #define ngx_thread_join(t, p)

  32. #define ngx_setthrtitle(n)     setproctitle(n)


  33. extern char    *ngx_freebsd_kern_usrstack;
  34. extern size_t   ngx_thread_stack_size;


  35. static ngx_inline ngx_int_t
  36. ngx_gettid(void)
  37. {
  38.     char  *sp;

  39.     if (ngx_thread_stack_size == 0) {
  40.         return 0;
  41.     }

  42. #if ( __i386__ )

  43.     __asm__ volatile ("mov %%esp, %0" : "=q" (sp));

  44. #elif ( __amd64__ )

  45.     __asm__ volatile ("mov %%rsp, %0" : "=q" (sp));

  46. #else

  47. #error "rfork()ed threads are not supported on this platform"

  48. #endif

  49.     return (ngx_freebsd_kern_usrstack - sp) / ngx_thread_stack_size;
  50. }


  51. ngx_tid_t ngx_thread_self(void);


  52. typedef ngx_uint_t               ngx_tls_key_t;

  53. #define NGX_THREAD_KEYS_MAX      16

  54. extern void    **ngx_tls;

  55. ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key);
  56. #define ngx_thread_key_create_n  "the tls key creation"

  57. ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value);
  58. #define ngx_thread_set_tls_n     "the tls key setting"


  59. static void *
  60. ngx_thread_get_tls(ngx_tls_key_t key)
  61. {
  62.     if (key >= NGX_THREAD_KEYS_MAX) {
  63.         return NULL;
  64.     }

  65.     return ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()];
  66. }


  67. #define ngx_mutex_trylock(m)  ngx_mutex_dolock(m, 1)
  68. #define ngx_mutex_lock(m)     (void) ngx_mutex_dolock(m, 0)
  69. ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try);
  70. void ngx_mutex_unlock(ngx_mutex_t *m);


  71. typedef int (*ngx_rfork_thread_func_pt)(void *arg);


  72. #endif /* _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_ */