Mercurial > hg > nginx-quic
comparison src/os/freebsd/ngx_os_thread.c @ 1:d220029ac7f3
nginx-0.0.1-2002-08-15-21:20:26 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 15 Aug 2002 17:20:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4eff17414a43 | 1:d220029ac7f3 |
---|---|
1 | |
2 #include <ngx_os_thread.h> | |
3 | |
4 char *ngx_stacks_start; | |
5 char *ngx_stacks_end; | |
6 size_t ngx_stack_size; | |
7 | |
8 | |
9 /* handle thread-safe errno */ | |
10 static int errno0; /* errno for main thread */ | |
11 static int *errnos; | |
12 | |
13 int *__error() | |
14 { | |
15 ngx_tid_t tid = ngx_gettid(); | |
16 return tid ? &(errnos[ngx_gettid()]) : &errno0; | |
17 } | |
18 | |
19 | |
20 int ngx_create_os_thread(ngx_os_tid_t *tid, void *stack, | |
21 int (*func)(void *arg), void *arg, ngx_log_t log) | |
22 { | |
23 int id, err; | |
24 | |
25 id = rfork_thread(RFPROC|RFMEM, stack, func, arg); | |
26 err = ngx_errno; | |
27 | |
28 if (id == -1) | |
29 ngx_log_error(NGX_LOG_ERR, log, err, | |
30 "ngx_create_os_thread: rfork failed"); | |
31 else | |
32 *tid = id; | |
33 | |
34 return err; | |
35 } | |
36 | |
37 | |
38 int ngx_create_os_thread_env(int n, size_t size, ngx_log_t log) | |
39 { | |
40 char *addr; | |
41 | |
42 /* create thread stacks */ | |
43 addr = mmap(NULL, n * size, PROT_READ|PROT_WRITE, MAP_ANON, -1, NULL); | |
44 if (addr == MAP_FAILED) { | |
45 ngx_log_error(NGX_LOG_ERR, log, ngx_errno, | |
46 "ngx_create_os_thread_stacks: mmap failed"); | |
47 return -1; | |
48 } | |
49 | |
50 nxg_stacks_start = addr; | |
51 nxg_stacks_end = addr + n * size; | |
52 nxg_stack_size = size; | |
53 | |
54 /* create thread errno array */ | |
55 ngx_test_null(errnos, ngx_calloc(n * sizeof(int)), -1); | |
56 | |
57 /* create thread tid array */ | |
58 ngx_test_null(ngx_os_tids, ngx_calloc(n * sizeof(ngx_os_tid_t)), -1); | |
59 | |
60 /* allow spinlock in malloc() */ | |
61 __isthreaded = 1; | |
62 | |
63 return 0; | |
64 } |