aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-07-06 16:12:16 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-07-06 16:12:16 +0000
commit81a432a185bc61d46a4d5eb1f96773ee7b3dc6a3 (patch)
tree2fc767b2b984c999342761308464c701c6d09457 /src/os/unix
parent40e877165a22f19359344d897c68da4fce62f6c1 (diff)
downloadnginx-81a432a185bc61d46a4d5eb1f96773ee7b3dc6a3.tar.gz
nginx-81a432a185bc61d46a4d5eb1f96773ee7b3dc6a3.zip
nginx-0.0.7-2004-07-06-20:12:16 import
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.c59
-rw-r--r--src/os/unix/ngx_freebsd_rfork_thread.h8
-rw-r--r--src/os/unix/ngx_process_cycle.c20
-rw-r--r--src/os/unix/ngx_pthread_thread.c15
-rw-r--r--src/os/unix/ngx_thread.h12
5 files changed, 82 insertions, 32 deletions
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c
index fcc716c99..bb638fa62 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.c
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c
@@ -30,18 +30,18 @@
*/
-char *ngx_freebsd_kern_usrstack;
-size_t ngx_thread_stack_size;
+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_tid_t *tids; /* the threads tids array */
+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_tid_t *tids; /* the threads tids array */
+void **ngx_tls; /* the threads tls's array */
/* the thread-safe libc errno */
@@ -220,19 +220,26 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
"red zone address was changed");
}
- /* create the threads errno array */
+ /* create the threads errno's array */
if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) {
return NGX_ERROR;
}
- /* create the threads tid array */
+ /* create the threads tids array */
if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) {
return NGX_ERROR;
}
tids[0] = ngx_pid;
+
+ /* create the threads tls's array */
+
+ if (!(ngx_tls = ngx_calloc((n + 1) * sizeof(void *), cycle->log))) {
+ return NGX_ERROR;
+ }
+
nthreads = 1;
last_stack = zone + rz_size;
@@ -263,6 +270,14 @@ ngx_tid_t ngx_thread_self()
}
+ngx_int_t ngx_thread_set_tls(void *value)
+{
+ ngx_tls[ngx_gettid()] = value;
+
+ return NGX_OK;
+}
+
+
ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags)
{
ngx_mutex_t *m;
@@ -326,10 +341,10 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
#if (NGX_DEBUG)
if (try) {
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"try lock mutex " PTR_FMT " lock:%X", m, m->lock);
} else {
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"lock mutex " PTR_FMT " lock:%X", m, m->lock);
}
#endif
@@ -360,7 +375,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
continue;
}
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " lock:%X", m, m->lock);
/*
@@ -380,7 +395,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (ngx_atomic_cmp_set(&m->lock, old, lock)) {
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"wait mutex " PTR_FMT " lock:%X", m, m->lock);
/*
@@ -401,7 +416,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
return NGX_ERROR;
}
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex waked up " PTR_FMT " lock:%X",
m, m->lock);
@@ -427,7 +442,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
if (tries++ > 1000) {
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is contested", m);
/* the mutex is probably contested so we are giving up now */
@@ -439,7 +454,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try)
}
}
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is locked, lock:%X", m, m->lock);
return NGX_OK;
@@ -466,7 +481,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
/* free the mutex */
#if 0
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"unlock mutex " PTR_FMT " lock:%X", m, old);
#endif
@@ -481,7 +496,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
}
if (m->semid == -1) {
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is unlocked", m);
return NGX_OK;
@@ -511,7 +526,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
/* wake up the thread that waits on semaphore */
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"wake up mutex " PTR_FMT "", m);
op.sem_num = 0;
@@ -531,7 +546,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
old = m->lock;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is unlocked", m);
return NGX_OK;
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h
index a9eb1d824..462554f28 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.h
+++ b/src/os/unix/ngx_freebsd_rfork_thread.h
@@ -15,6 +15,14 @@ typedef pid_t ngx_tid_t;
#define TID_T_FMT PID_T_FMT
+extern void **ngx_tls;
+
+#define ngx_thread_create_tls() 0
+#define ngx_thread_create_tls_n ""
+#define ngx_thread_get_tls() ngx_tls[ngx_gettid()]
+ngx_int_t ngx_thread_set_tls(void *value);
+
+
#define NGX_MUTEX_LIGHT 1
#define NGX_MUTEX_LOCK_BUSY 0x80000000
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 1a5e5c420..ffb8e58bc 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -826,9 +826,10 @@ static void* ngx_worker_thread_cycle(void *data)
{
ngx_thread_t *thr = data;
- sigset_t set;
- ngx_err_t err;
- struct timeval tv;
+ sigset_t set;
+ ngx_err_t err;
+ ngx_tls_t *tls;
+ struct timeval tv;
thr->cv->tid = ngx_thread_self();
@@ -849,6 +850,19 @@ static void* ngx_worker_thread_cycle(void *data)
ngx_setthrtitle("worker thread");
+ if (!(tls = ngx_calloc(sizeof(ngx_tls_t), ngx_cycle->log))) {
+ return (void *) 1;
+ }
+
+ err = ngx_thread_create_tls();
+ if (err != 0) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err,
+ ngx_thread_create_tls_n " failed");
+ return (void *) 1;
+ }
+
+ ngx_thread_set_tls(tls);
+
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return (void *) 1;
}
diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c
index 951123cb4..d5d816f2e 100644
--- a/src/os/unix/ngx_pthread_thread.c
+++ b/src/os/unix/ngx_pthread_thread.c
@@ -116,7 +116,7 @@ ngx_int_t ngx_mutex_lock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0, "lock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex " PTR_FMT, m);
err = pthread_mutex_lock(&m->mutex);
@@ -126,7 +126,7 @@ ngx_int_t ngx_mutex_lock(ngx_mutex_t *m)
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is locked", m);
return NGX_OK;
@@ -141,7 +141,8 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0, "try lock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
+ "try lock mutex " PTR_FMT, m);
err = pthread_mutex_trylock(&m->mutex);
@@ -151,7 +152,7 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m)
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is locked", m);
return NGX_OK;
@@ -166,7 +167,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
return NGX_OK;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0, "unlock mutex " PTR_FMT, m);
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex " PTR_FMT, m);
err = pthread_mutex_unlock(&m->mutex);
@@ -176,7 +177,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m)
return NGX_ERROR;
}
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is unlocked", m);
return NGX_OK;
@@ -239,7 +240,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0,
"cv " PTR_FMT " is waked up", cv);
- ngx_log_debug1(NGX_LOG_DEBUG_CORE, m->log, 0,
+ ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0,
"mutex " PTR_FMT " is locked", m);
return NGX_OK;
diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h
index 3bd9753d7..e30a148dd 100644
--- a/src/os/unix/ngx_thread.h
+++ b/src/os/unix/ngx_thread.h
@@ -27,6 +27,12 @@ typedef pthread_t ngx_tid_t;
#define TID_T_FMT PTR_FMT
+#define ngx_thread_create_tls() pthread_key_create(0, NULL)
+#define ngx_thread_create_tls_n "pthread_key_create(0, NULL)"
+#define ngx_thread_get_tls() pthread_getspecific(0)
+#define ngx_thread_set_tls(v) pthread_setspecific(0, v)
+
+
#define NGX_MUTEX_LIGHT 0
typedef struct {
@@ -106,4 +112,10 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv);
#endif
+typedef struct {
+ ngx_event_t *event;
+} ngx_tls_t;
+
+
+
#endif /* _NGX_THREAD_H_INCLUDED_ */