[nginx] Removed old FreeBSD rfork() thread implementation.
Ruslan Ermilov
ru at nginx.com
Fri Mar 20 03:46:26 UTC 2015
details: http://hg.nginx.org/nginx/rev/fa77496b1df2
branches:
changeset: 6028:fa77496b1df2
user: Ruslan Ermilov <ru at nginx.com>
date: Fri Mar 20 06:43:19 2015 +0300
description:
Removed old FreeBSD rfork() thread implementation.
diffstat:
auto/sources | 3 -
src/os/unix/ngx_freebsd_config.h | 6 -
src/os/unix/ngx_freebsd_rfork_thread.c | 756 ---------------------------------
src/os/unix/ngx_freebsd_rfork_thread.h | 122 -----
src/os/unix/ngx_thread.h | 8 -
src/os/unix/rfork_thread.S | 73 ---
6 files changed, 0 insertions(+), 968 deletions(-)
diffs (truncated from 1017 to 300 lines):
diff -r 67717d4e4f47 -r fa77496b1df2 auto/sources
--- a/auto/sources Thu Mar 19 23:20:18 2015 +0300
+++ b/auto/sources Fri Mar 20 06:43:19 2015 +0300
@@ -203,9 +203,6 @@ THREAD_POOL_SRCS="src/core/ngx_thread_po
FREEBSD_DEPS="src/os/unix/ngx_freebsd_config.h src/os/unix/ngx_freebsd.h"
FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c
FREEBSD_SENDFILE_SRCS=src/os/unix/ngx_freebsd_sendfile_chain.c
-FREEBSD_RFORK_DEPS="src/os/unix/ngx_freebsd_rfork_thread.h"
-FREEBSD_RFORK_SRCS="src/os/unix/ngx_freebsd_rfork_thread.c"
-FREEBSD_RFORK_THREAD_SRCS="src/os/unix/rfork_thread.S"
PTHREAD_SRCS="src/os/unix/ngx_pthread_thread.c"
diff -r 67717d4e4f47 -r fa77496b1df2 src/os/unix/ngx_freebsd_config.h
--- a/src/os/unix/ngx_freebsd_config.h Thu Mar 19 23:20:18 2015 +0300
+++ b/src/os/unix/ngx_freebsd_config.h Fri Mar 20 06:43:19 2015 +0300
@@ -100,12 +100,6 @@ typedef struct aiocb ngx_aiocb_t;
#endif
-#if (__FreeBSD_version < 430000 || __FreeBSD_version < 500012)
-
-pid_t rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg);
-
-#endif
-
#ifndef IOV_MAX
#define IOV_MAX 1024
#endif
diff -r 67717d4e4f47 -r fa77496b1df2 src/os/unix/ngx_freebsd_rfork_thread.c
--- a/src/os/unix/ngx_freebsd_rfork_thread.c Thu Mar 19 23:20:18 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,756 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-
-/*
- * The threads implementation uses the rfork(RFPROC|RFTHREAD|RFMEM) syscall
- * to create threads. All threads use the stacks of the same size mmap()ed
- * below the main stack. Thus the current thread id is determined via
- * the stack pointer value.
- *
- * The mutex implementation uses the ngx_atomic_cmp_set() operation
- * to acquire a mutex and the SysV semaphore to wait on a mutex and to wake up
- * the waiting threads. The light mutex does not use semaphore, so after
- * spinning in the lock the thread calls sched_yield(). However the light
- * mutexes are intended to be used with the "trylock" operation only.
- * The SysV semop() is a cheap syscall, particularly if it has little sembuf's
- * and does not use SEM_UNDO.
- *
- * The condition variable implementation uses the signal #64.
- * The signal handler is SIG_IGN so the kill() is a cheap syscall.
- * The thread waits a signal in kevent(). The use of the EVFILT_SIGNAL
- * is safe since FreeBSD 4.10-STABLE.
- *
- * This threads implementation currently works on i386 (486+) and amd64
- * platforms only.
- */
-
-
-char *ngx_freebsd_kern_usrstack;
-size_t ngx_thread_stack_size;
-
-
-static size_t rz_size;
-static size_t usable_stack_size;
-static char *last_stack;
-
-static ngx_uint_t nthreads;
-static ngx_uint_t max_threads;
-
-static ngx_uint_t nkeys;
-static ngx_tid_t *tids; /* the threads tids array */
-void **ngx_tls; /* the threads tls's array */
-
-/* the thread-safe libc errno */
-
-static int errno0; /* the main thread's errno */
-static int *errnos; /* the threads errno's array */
-
-int *
-__error()
-{
- int tid;
-
- tid = ngx_gettid();
-
- return tid ? &errnos[tid - 1] : &errno0;
-}
-
-
-/*
- * __isthreaded enables the spinlocks in some libc functions, i.e. in malloc()
- * and some other places. Nevertheless we protect our malloc()/free() calls
- * by own mutex that is more efficient than the spinlock.
- *
- * _spinlock() is a weak referenced stub in src/lib/libc/gen/_spinlock_stub.c
- * that does nothing.
- */
-
-extern int __isthreaded;
-
-void
-_spinlock(ngx_atomic_t *lock)
-{
- ngx_int_t tries;
-
- tries = 0;
-
- for ( ;; ) {
-
- if (*lock) {
- if (ngx_ncpu > 1 && tries++ < 1000) {
- continue;
- }
-
- sched_yield();
- tries = 0;
-
- } else {
- if (ngx_atomic_cmp_set(lock, 0, 1)) {
- return;
- }
- }
- }
-}
-
-
-/*
- * Before FreeBSD 5.1 _spinunlock() is a simple #define in
- * src/lib/libc/include/spinlock.h that zeroes lock.
- *
- * Since FreeBSD 5.1 _spinunlock() is a weak referenced stub in
- * src/lib/libc/gen/_spinlock_stub.c that does nothing.
- */
-
-#ifndef _spinunlock
-
-void
-_spinunlock(ngx_atomic_t *lock)
-{
- *lock = 0;
-}
-
-#endif
-
-
-ngx_err_t
-ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg),
- void *arg, ngx_log_t *log)
-{
- ngx_pid_t id;
- ngx_err_t err;
- char *stack, *stack_top;
-
- if (nthreads >= max_threads) {
- ngx_log_error(NGX_LOG_CRIT, log, 0,
- "no more than %ui threads can be created", max_threads);
- return NGX_ERROR;
- }
-
- last_stack -= ngx_thread_stack_size;
-
- stack = mmap(last_stack, usable_stack_size, PROT_READ|PROT_WRITE,
- MAP_STACK, -1, 0);
-
- if (stack == MAP_FAILED) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "mmap(%p:%uz, MAP_STACK) thread stack failed",
- last_stack, usable_stack_size);
- return NGX_ERROR;
- }
-
- if (stack != last_stack) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "stack %p address was changed to %p", last_stack, stack);
- return NGX_ERROR;
- }
-
- stack_top = stack + usable_stack_size;
-
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0,
- "thread stack: %p-%p", stack, stack_top);
-
- ngx_set_errno(0);
-
- id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top,
- (ngx_rfork_thread_func_pt) func, arg);
-
- err = ngx_errno;
-
- if (id == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, err, "rfork() failed");
-
- } else {
- *tid = id;
- nthreads = (ngx_freebsd_kern_usrstack - stack_top)
- / ngx_thread_stack_size;
- tids[nthreads] = id;
-
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %P", id);
- }
-
- return err;
-}
-
-
-ngx_int_t
-ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
-{
- char *red_zone, *zone;
- size_t len;
- ngx_int_t i;
- struct sigaction sa;
-
- max_threads = n + 1;
-
- for (i = 0; i < n; i++) {
- ngx_memzero(&sa, sizeof(struct sigaction));
- sa.sa_handler = SIG_IGN;
- sigemptyset(&sa.sa_mask);
- if (sigaction(NGX_CV_SIGNAL, &sa, NULL) == -1) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "sigaction(%d, SIG_IGN) failed", NGX_CV_SIGNAL);
- return NGX_ERROR;
- }
- }
-
- len = sizeof(ngx_freebsd_kern_usrstack);
- if (sysctlbyname("kern.usrstack", &ngx_freebsd_kern_usrstack, &len,
- NULL, 0) == -1)
- {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "sysctlbyname(kern.usrstack) failed");
- return NGX_ERROR;
- }
-
- /* the main thread stack red zone */
- rz_size = ngx_pagesize;
- red_zone = ngx_freebsd_kern_usrstack - (size + rz_size);
-
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "usrstack: %p red zone: %p",
- ngx_freebsd_kern_usrstack, red_zone);
-
- zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0);
- if (zone == MAP_FAILED) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
- "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed",
- red_zone, rz_size);
- return NGX_ERROR;
- }
-
- if (zone != red_zone) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "red zone %p address was changed to %p", red_zone, zone);
- return NGX_ERROR;
- }
-
- /* create the thread errno' array */
-
- errnos = ngx_calloc(n * sizeof(int), cycle->log);
- if (errnos == NULL) {
- return NGX_ERROR;
- }
-
- /* create the thread tids array */
-
- tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log);
- if (tids == NULL) {
- return NGX_ERROR;
- }
-
- tids[0] = ngx_pid;
-
- /* create the thread tls' array */
-
- ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *),
- cycle->log);
- if (ngx_tls == NULL) {
- return NGX_ERROR;
- }
-
- nthreads = 1;
-
- last_stack = zone + rz_size;
- usable_stack_size = size;
- ngx_thread_stack_size = size + rz_size;
-
- /* allow the spinlock in libc malloc() */
- __isthreaded = 1;
-
- ngx_threaded = 1;
More information about the nginx-devel
mailing list