Removed old pthread implementation.

This commit is contained in:
Ruslan Ermilov 2015-03-20 06:43:19 +03:00
parent c84c19f5bf
commit d1ec868e32
6 changed files with 0 additions and 636 deletions

View File

@ -204,8 +204,6 @@ 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
PTHREAD_SRCS="src/os/unix/ngx_pthread_thread.c"
LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h"
LINUX_SRCS=src/os/unix/ngx_linux_init.c
LINUX_SENDFILE_SRCS=src/os/unix/ngx_linux_sendfile_chain.c

View File

@ -59,12 +59,6 @@ static ngx_event_t notify_event;
static struct kevent notify_kev;
#endif
#if (NGX_OLD_THREADS)
static ngx_mutex_t *list_mutex;
static ngx_mutex_t *kevent_mutex;
#endif
static ngx_str_t kqueue_name = ngx_string("kqueue");
@ -153,20 +147,6 @@ ngx_kqueue_init(ngx_cycle_t *cycle, ngx_msec_t timer)
if (ngx_kqueue_notify_init(cycle->log) != NGX_OK) {
return NGX_ERROR;
}
#endif
#if (NGX_OLD_THREADS)
list_mutex = ngx_mutex_init(cycle->log, 0);
if (list_mutex == NULL) {
return NGX_ERROR;
}
kevent_mutex = ngx_mutex_init(cycle->log, 0);
if (kevent_mutex == NULL) {
return NGX_ERROR;
}
#endif
}
@ -310,11 +290,6 @@ ngx_kqueue_done(ngx_cycle_t *cycle)
ngx_kqueue = -1;
#if (NGX_OLD_THREADS)
ngx_mutex_destroy(kevent_mutex);
ngx_mutex_destroy(list_mutex);
#endif
ngx_free(change_list1);
ngx_free(change_list0);
ngx_free(event_list);
@ -342,8 +317,6 @@ ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
ev->disabled = 0;
ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0;
ngx_mutex_lock(list_mutex);
#if 0
if (ev->index < nchanges
@ -368,8 +341,6 @@ ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
e->index = ev->index;
}
ngx_mutex_unlock(list_mutex);
return NGX_OK;
}
@ -378,8 +349,6 @@ ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
"previous event on #%d were not passed in kernel", c->fd);
ngx_mutex_unlock(list_mutex);
return NGX_ERROR;
}
@ -387,8 +356,6 @@ ngx_kqueue_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
rc = ngx_kqueue_set_event(ev, event, EV_ADD|EV_ENABLE|flags);
ngx_mutex_unlock(list_mutex);
return rc;
}
@ -402,8 +369,6 @@ ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
ev->active = 0;
ev->disabled = 0;
ngx_mutex_lock(list_mutex);
if (ev->index < nchanges
&& ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1)
== (uintptr_t) ev)
@ -423,8 +388,6 @@ ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
e->index = ev->index;
}
ngx_mutex_unlock(list_mutex);
return NGX_OK;
}
@ -435,7 +398,6 @@ ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
*/
if (flags & NGX_CLOSE_EVENT) {
ngx_mutex_unlock(list_mutex);
return NGX_OK;
}
@ -448,8 +410,6 @@ ngx_kqueue_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
rc = ngx_kqueue_set_event(ev, event, flags);
ngx_mutex_unlock(list_mutex);
return rc;
}
@ -756,13 +716,7 @@ ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try)
struct timespec ts;
struct kevent *changes;
ngx_mutex_lock(kevent_mutex);
ngx_mutex_lock(list_mutex);
if (nchanges == 0) {
ngx_mutex_unlock(list_mutex);
ngx_mutex_unlock(kevent_mutex);
return NGX_OK;
}
@ -776,8 +730,6 @@ ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try)
n = (int) nchanges;
nchanges = 0;
ngx_mutex_unlock(list_mutex);
ts.tv_sec = 0;
ts.tv_nsec = 0;
@ -794,8 +746,6 @@ ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try)
rc = NGX_OK;
}
ngx_mutex_unlock(kevent_mutex);
return rc;
}

View File

@ -23,10 +23,6 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
static void ngx_worker_process_exit(ngx_cycle_t *cycle);
static void ngx_channel_handler(ngx_event_t *ev);
#if (NGX_OLD_THREADS)
static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
static ngx_thread_value_t ngx_worker_thread_cycle(void *data);
#endif
static void ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data);
static void ngx_cache_manager_process_handler(ngx_event_t *ev);
static void ngx_cache_loader_process_handler(ngx_event_t *ev);
@ -56,12 +52,6 @@ ngx_uint_t ngx_noaccepting;
ngx_uint_t ngx_restart;
#if (NGX_OLD_THREADS)
volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
ngx_int_t ngx_threads_n;
#endif
static u_char master_process[] = "master process";
@ -747,52 +737,6 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
ngx_setproctitle("worker process");
#if (NGX_OLD_THREADS)
{
ngx_int_t n;
ngx_err_t err;
ngx_core_conf_t *ccf;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (ngx_threads_n) {
if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle)
== NGX_ERROR)
{
/* fatal */
exit(2);
}
err = ngx_thread_key_create(&ngx_core_tls_key);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
ngx_thread_key_create_n " failed");
/* fatal */
exit(2);
}
for (n = 0; n < ngx_threads_n; n++) {
ngx_threads[n].cv = ngx_cond_init(cycle->log);
if (ngx_threads[n].cv == NULL) {
/* fatal */
exit(2);
}
if (ngx_create_thread((ngx_tid_t *) &ngx_threads[n].tid,
ngx_worker_thread_cycle,
(void *) &ngx_threads[n], cycle->log)
!= 0)
{
/* fatal */
exit(2);
}
}
}
}
#endif
for ( ;; ) {
if (ngx_exiting) {
@ -1032,12 +976,6 @@ ngx_worker_process_exit(ngx_cycle_t *cycle)
ngx_uint_t i;
ngx_connection_t *c;
#if (NGX_OLD_THREADS)
ngx_terminate = 1;
ngx_wakeup_worker_threads(cycle);
#endif
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->exit_process) {
ngx_modules[i]->exit_process(cycle);
@ -1181,132 +1119,6 @@ ngx_channel_handler(ngx_event_t *ev)
}
#if (NGX_OLD_THREADS)
static void
ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
{
ngx_int_t i;
ngx_uint_t live;
for ( ;; ) {
live = 0;
for (i = 0; i < ngx_threads_n; i++) {
if (ngx_threads[i].state < NGX_THREAD_EXIT) {
if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) {
ngx_threads[i].state = NGX_THREAD_DONE;
} else {
live = 1;
}
}
if (ngx_threads[i].state == NGX_THREAD_EXIT) {
ngx_thread_join(ngx_threads[i].tid, NULL);
ngx_threads[i].state = NGX_THREAD_DONE;
}
}
if (live == 0) {
ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"all worker threads are joined");
/* STUB */
ngx_done_events(cycle);
return;
}
ngx_sched_yield();
}
}
static ngx_thread_value_t
ngx_worker_thread_cycle(void *data)
{
ngx_thread_t *thr = data;
sigset_t set;
ngx_err_t err;
ngx_core_tls_t *tls;
ngx_cycle_t *cycle;
cycle = (ngx_cycle_t *) ngx_cycle;
sigemptyset(&set);
sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL);
if (err) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
ngx_thread_sigmask_n " failed");
return (ngx_thread_value_t) 1;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"thread " NGX_TID_T_FMT " started", ngx_thread_self());
ngx_setthrtitle("worker thread");
tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log);
if (tls == NULL) {
return (ngx_thread_value_t) 1;
}
err = ngx_thread_set_tls(ngx_core_tls_key, tls);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
ngx_thread_set_tls_n " failed");
return (ngx_thread_value_t) 1;
}
for ( ;; ) {
thr->state = NGX_THREAD_FREE;
#if 0
if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) {
return (ngx_thread_value_t) 1;
}
#endif
if (ngx_terminate) {
thr->state = NGX_THREAD_EXIT;
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"thread " NGX_TID_T_FMT " is done",
ngx_thread_self());
return (ngx_thread_value_t) 0;
}
thr->state = NGX_THREAD_BUSY;
#if 0
if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
return (ngx_thread_value_t) 1;
}
if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
return (ngx_thread_value_t) 1;
}
#endif
if (ngx_process_changes) {
if (ngx_process_changes(cycle, 1) == NGX_ERROR) {
return (ngx_thread_value_t) 1;
}
}
}
}
#endif
static void
ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data)
{

View File

@ -1,278 +0,0 @@
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#include <ngx_config.h>
#include <ngx_core.h>
static ngx_uint_t nthreads;
static ngx_uint_t max_threads;
static pthread_attr_t thr_attr;
ngx_err_t
ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg),
void *arg, ngx_log_t *log)
{
int err;
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;
}
err = pthread_create(tid, &thr_attr, func, arg);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, log, err, "pthread_create() failed");
return err;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0,
"thread is created: " NGX_TID_T_FMT, *tid);
nthreads++;
return err;
}
ngx_int_t
ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
{
int err;
max_threads = n;
err = pthread_attr_init(&thr_attr);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
"pthread_attr_init() failed");
return NGX_ERROR;
}
err = pthread_attr_setstacksize(&thr_attr, size);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
"pthread_attr_setstacksize() failed");
return NGX_ERROR;
}
ngx_threaded = 1;
return NGX_OK;
}
ngx_mutex_t *
ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags)
{
int err;
ngx_mutex_t *m;
m = ngx_alloc(sizeof(ngx_mutex_t), log);
if (m == NULL) {
return NULL;
}
m->log = log;
err = pthread_mutex_init(&m->mutex, NULL);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
"pthread_mutex_init() failed");
return NULL;
}
return m;
}
void
ngx_mutex_destroy(ngx_mutex_t *m)
{
int err;
err = pthread_mutex_destroy(&m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
"pthread_mutex_destroy(%p) failed", m);
}
ngx_free(m);
}
void
ngx_mutex_lock(ngx_mutex_t *m)
{
int err;
if (!ngx_threaded) {
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex %p", m);
err = pthread_mutex_lock(&m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
"pthread_mutex_lock(%p) failed", m);
ngx_abort();
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return;
}
ngx_int_t
ngx_mutex_trylock(ngx_mutex_t *m)
{
int err;
if (!ngx_threaded) {
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "try lock mutex %p", m);
err = pthread_mutex_trylock(&m->mutex);
if (err == NGX_EBUSY) {
return NGX_AGAIN;
}
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
"pthread_mutex_trylock(%p) failed", m);
ngx_abort();
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return NGX_OK;
}
void
ngx_mutex_unlock(ngx_mutex_t *m)
{
int err;
if (!ngx_threaded) {
return;
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex %p", m);
err = pthread_mutex_unlock(&m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, m->log, err,
"pthread_mutex_unlock(%p) failed", m);
ngx_abort();
}
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m);
return;
}
ngx_cond_t *
ngx_cond_init(ngx_log_t *log)
{
int err;
ngx_cond_t *cv;
cv = ngx_alloc(sizeof(ngx_cond_t), log);
if (cv == NULL) {
return NULL;
}
cv->log = log;
err = pthread_cond_init(&cv->cond, NULL);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
"pthread_cond_init() failed");
return NULL;
}
return cv;
}
void
ngx_cond_destroy(ngx_cond_t *cv)
{
int err;
err = pthread_cond_destroy(&cv->cond);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
"pthread_cond_destroy(%p) failed", cv);
}
ngx_free(cv);
}
ngx_int_t
ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m)
{
int err;
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p wait", cv);
err = pthread_cond_wait(&cv->cond, &m->mutex);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
"pthread_cond_wait(%p) failed", cv);
return NGX_ERROR;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv);
ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m);
return NGX_OK;
}
ngx_int_t
ngx_cond_signal(ngx_cond_t *cv)
{
int err;
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p to signal", cv);
err = pthread_cond_signal(&cv->cond);
if (err != 0) {
ngx_log_error(NGX_LOG_ALERT, cv->log, err,
"pthread_cond_signal(%p) failed", cv);
return NGX_ERROR;
}
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv);
return NGX_OK;
}

View File

@ -12,97 +12,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
#if (NGX_OLD_THREADS)
#define NGX_MAX_THREADS 128
#include <pthread.h>
typedef pthread_t ngx_tid_t;
#define ngx_thread_self() pthread_self()
#define ngx_log_tid (int) ngx_thread_self()
#if (NGX_FREEBSD) && !(NGX_LINUXTHREADS)
#define NGX_TID_T_FMT "%p"
#else
#define NGX_TID_T_FMT "%d"
#endif
typedef pthread_key_t ngx_tls_key_t;
#define ngx_thread_key_create(key) pthread_key_create(key, NULL)
#define ngx_thread_key_create_n "pthread_key_create()"
#define ngx_thread_set_tls pthread_setspecific
#define ngx_thread_set_tls_n "pthread_setspecific()"
#define ngx_thread_get_tls pthread_getspecific
#define NGX_MUTEX_LIGHT 0
typedef struct {
pthread_mutex_t mutex;
ngx_log_t *log;
} ngx_mutex_t;
typedef struct {
pthread_cond_t cond;
ngx_log_t *log;
} ngx_cond_t;
#define ngx_thread_sigmask pthread_sigmask
#define ngx_thread_sigmask_n "pthread_sigmask()"
#define ngx_thread_join(t, p) pthread_join(t, p)
#define ngx_setthrtitle(n)
ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m);
void ngx_mutex_lock(ngx_mutex_t *m);
void ngx_mutex_unlock(ngx_mutex_t *m);
#define ngx_thread_volatile volatile
typedef struct {
ngx_tid_t tid;
ngx_cond_t *cv;
ngx_uint_t state;
} ngx_thread_t;
#define NGX_THREAD_FREE 1
#define NGX_THREAD_BUSY 2
#define NGX_THREAD_EXIT 3
#define NGX_THREAD_DONE 4
extern ngx_int_t ngx_threads_n;
extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
typedef void * ngx_thread_value_t;
ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle);
ngx_err_t ngx_create_thread(ngx_tid_t *tid,
ngx_thread_value_t (*func)(void *arg), void *arg, ngx_log_t *log);
ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags);
void ngx_mutex_destroy(ngx_mutex_t *m);
ngx_cond_t *ngx_cond_init(ngx_log_t *log);
void ngx_cond_destroy(ngx_cond_t *cv);
ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m);
ngx_int_t ngx_cond_signal(ngx_cond_t *cv);
#else /* !NGX_OLD_THREADS */
#define ngx_thread_volatile
#if (NGX_THREADS)
#include <pthread.h>
@ -158,15 +67,8 @@ ngx_tid_t ngx_thread_tid(void);
#endif
#define ngx_mutex_trylock(m) NGX_OK
#define ngx_mutex_lock(m)
#define ngx_mutex_unlock(m)
#define ngx_cond_signal(cv)
#define ngx_thread_main() 1
#endif
#endif /* _NGX_THREAD_H_INCLUDED_ */

View File

@ -64,16 +64,6 @@ ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
size_t len;
ngx_err_t err;
#if (NGX_OLD_THREADS && NGX_NONREENTRANT_CRYPT)
/* crypt() is a time consuming function, so we only try to lock */
if (ngx_mutex_trylock(ngx_crypt_mutex) != NGX_OK) {
return NGX_AGAIN;
}
#endif
value = crypt((char *) key, (char *) salt);
if (value) {
@ -81,25 +71,15 @@ ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
*encrypted = ngx_pnalloc(pool, len);
if (*encrypted == NULL) {
#if (NGX_OLD_THREADS && NGX_NONREENTRANT_CRYPT)
ngx_mutex_unlock(ngx_crypt_mutex);
#endif
return NGX_ERROR;
}
ngx_memcpy(*encrypted, value, len);
#if (NGX_OLD_THREADS && NGX_NONREENTRANT_CRYPT)
ngx_mutex_unlock(ngx_crypt_mutex);
#endif
return NGX_OK;
}
err = ngx_errno;
#if (NGX_OLD_THREADS && NGX_NONREENTRANT_CRYPT)
ngx_mutex_unlock(ngx_crypt_mutex);
#endif
ngx_log_error(NGX_LOG_CRIT, pool->log, err, "crypt() failed");
return NGX_ERROR;