aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/freebsd/ngx_rfork_thread.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2002-08-20 14:48:28 +0000
committerIgor Sysoev <igor@sysoev.ru>2002-08-20 14:48:28 +0000
commit2b54238a5f2edcca568c0676a779ef79ba152c91 (patch)
tree2cb7eb660e691eaab2c4f031adf881b7c88bffc9 /src/os/unix/freebsd/ngx_rfork_thread.c
parente0af1b89dcd100462a3195534b2f78a838ca85b5 (diff)
downloadnginx-2b54238a5f2edcca568c0676a779ef79ba152c91.tar.gz
nginx-2b54238a5f2edcca568c0676a779ef79ba152c91.zip
nginx-0.0.1-2002-08-20-18:48:28 import
Diffstat (limited to 'src/os/unix/freebsd/ngx_rfork_thread.c')
-rw-r--r--src/os/unix/freebsd/ngx_rfork_thread.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/os/unix/freebsd/ngx_rfork_thread.c b/src/os/unix/freebsd/ngx_rfork_thread.c
new file mode 100644
index 000000000..acd5ec6e2
--- /dev/null
+++ b/src/os/unix/freebsd/ngx_rfork_thread.c
@@ -0,0 +1,64 @@
+
+#include <ngx_os_thread.h>
+
+char *ngx_stacks_start;
+char *ngx_stacks_end;
+size_t ngx_stack_size;
+
+
+/* handle thread-safe errno */
+static int errno0; /* errno for main thread */
+static int *errnos;
+
+int *__error()
+{
+ ngx_tid_t tid = ngx_gettid();
+ return tid ? &(errnos[ngx_gettid()]) : &errno0;
+}
+
+
+int ngx_create_thread(ngx_os_tid_t *tid, void *stack,
+ int (*func)(void *arg), void *arg, ngx_log_t log)
+{
+ int id, err;
+
+ id = rfork_thread(RFPROC|RFMEM, stack, func, arg);
+ err = ngx_errno;
+
+ if (id == -1)
+ ngx_log_error(NGX_LOG_ERR, log, err,
+ "ngx_create_os_thread: rfork failed");
+ else
+ *tid = id;
+
+ return err;
+}
+
+
+int ngx_create_thread_env(int n, size_t size, ngx_log_t log)
+{
+ char *addr;
+
+ /* create thread stacks */
+ addr = mmap(NULL, n * size, PROT_READ|PROT_WRITE, MAP_ANON, -1, NULL);
+ if (addr == MAP_FAILED) {
+ ngx_log_error(NGX_LOG_ERR, log, ngx_errno,
+ "ngx_create_os_thread_stacks: mmap failed");
+ return -1;
+ }
+
+ nxg_stacks_start = addr;
+ nxg_stacks_end = addr + n * size;
+ nxg_stack_size = size;
+
+ /* create thread errno array */
+ ngx_test_null(errnos, ngx_calloc(n * sizeof(int)), -1);
+
+ /* create thread tid array */
+ ngx_test_null(ngx_os_tids, ngx_calloc(n * sizeof(ngx_os_tid_t)), -1);
+
+ /* allow spinlock in malloc() */
+ __isthreaded = 1;
+
+ return 0;
+}