Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ngx_freebsd_rfork_thread.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) Nginx, Inc.
5  */
6 
7 
8 #ifndef _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_
9 #define _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_
10 
11 
12 #include <sys/ipc.h>
13 #include <sys/sem.h>
14 #include <sched.h>
15 
16 typedef pid_t ngx_tid_t;
17 
18 #define ngx_log_pid ngx_thread_self()
19 #define ngx_log_tid 0
20 
21 #define NGX_TID_T_FMT "%P"
22 
23 
24 #define NGX_MUTEX_LIGHT 1
25 
26 #define NGX_MUTEX_LOCK_BUSY 0x80000000
27 
28 typedef volatile struct {
31  int semid;
32 } ngx_mutex_t;
33 
34 
35 #define NGX_CV_SIGNAL 64
36 
37 typedef struct {
38  int signo;
39  int kq;
42 } ngx_cond_t;
43 
44 
45 #define ngx_thread_sigmask(how, set, oset) \
46  (sigprocmask(how, set, oset) == -1) ? ngx_errno : 0
47 
48 #define ngx_thread_sigmask_n "sigprocmask()"
49 
50 #define ngx_thread_join(t, p)
51 
52 #define ngx_setthrtitle(n) setproctitle(n)
53 
54 
55 extern char *ngx_freebsd_kern_usrstack;
56 extern size_t ngx_thread_stack_size;
57 
58 
59 static ngx_inline ngx_int_t
60 ngx_gettid()
61 {
62  char *sp;
63 
64  if (ngx_thread_stack_size == 0) {
65  return 0;
66  }
67 
68 #if ( __i386__ )
69 
70  __asm__ volatile ("mov %%esp, %0" : "=q" (sp));
71 
72 #elif ( __amd64__ )
73 
74  __asm__ volatile ("mov %%rsp, %0" : "=q" (sp));
75 
76 #else
77 
78 #error "rfork()ed threads are not supported on this platform"
79 
80 #endif
81 
83 }
84 
85 
87 
88 
90 
91 #define NGX_THREAD_KEYS_MAX 16
92 
93 extern void **ngx_tls;
94 
96 #define ngx_thread_key_create_n "the tls key creation"
97 
99 #define ngx_thread_set_tls_n "the tls key setting"
100 
101 
102 static void *
103 ngx_thread_get_tls(ngx_tls_key_t key)
104 {
105  if (key >= NGX_THREAD_KEYS_MAX) {
106  return NULL;
107  }
108 
109  return ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()];
110 }
111 
112 
113 #define ngx_mutex_trylock(m) ngx_mutex_dolock(m, 1)
114 #define ngx_mutex_lock(m) (void) ngx_mutex_dolock(m, 0)
117 
118 
119 typedef int (*ngx_rfork_thread_func_pt)(void *arg);
120 
121 
122 #endif /* _NGX_FREEBSD_RFORK_THREAD_H_INCLUDED_ */