diff options
Diffstat (limited to '')
| -rw-r--r-- | src/os/unix/ngx_pthread.c | 26 | ||||
| -rw-r--r-- | src/os/unix/ngx_pthread.h | 14 | ||||
| -rw-r--r-- | src/os/win32/ngx_os_thread.c | 26 | ||||
| -rw-r--r-- | src/os/win32/ngx_os_thread.h | 14 |
4 files changed, 80 insertions, 0 deletions
diff --git a/src/os/unix/ngx_pthread.c b/src/os/unix/ngx_pthread.c new file mode 100644 index 000000000..2491032a4 --- /dev/null +++ b/src/os/unix/ngx_pthread.c @@ -0,0 +1,26 @@ + + +#include <ngx_config.h> + +#include <ngx_log.h> +#include <ngx_pthread.h> + + +int ngx_create_os_thread(ngx_os_tid_t *tid, void *stack, + ngx_thread_start_routine_t func, void *arg, + ngx_log_t log) +{ + int err; + pthread_attr_t *attr; + + attr = NULL; + + err = pthread_create(tid, attr, func, arg); + + if (err != 0) { + ngx_log_error(NGX_LOG_ERR, log, err, "pthread_create() failed"); + return NGX_ERROR; + } + + return NGX_OK; +} diff --git a/src/os/unix/ngx_pthread.h b/src/os/unix/ngx_pthread.h new file mode 100644 index 000000000..845655f57 --- /dev/null +++ b/src/os/unix/ngx_pthread.h @@ -0,0 +1,14 @@ +#ifndef _NGX_OS_THREAD_H_INCLUDED_ +#define _NGX_OS_THREAD_H_INCLUDED_ + + +#include <pthread.h> + + +typedef pthread_t ngx_os_tid_t; +typedef int ngx_tid_t; + +typedef void *(*)(void *) ngx_thread_start_routine_t + + +#endif /* _NGX_OS_THREAD_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_os_thread.c b/src/os/win32/ngx_os_thread.c new file mode 100644 index 000000000..c9d540cc1 --- /dev/null +++ b/src/os/win32/ngx_os_thread.c @@ -0,0 +1,26 @@ + + +#include <ngx_config.h> + +#include <ngx_log.h> +#include <ngx_os_thread.h> + + +int ngx_create_os_thread(ngx_os_tid_t *tid, void *stack, + ngx_thread_start_routine_t func, void *arg, + ngx_log_t log) +{ + ngx_os_tid_t id; + int dummy; /* needed in Win9X only, in NT can be NULL */ + + id = CreateThread(NULL, stack_size, func, arg, 0, &dummy); + + if (id == NULL) { + ngx_log_error(NGX_LOG_ERR, log, err, "CreateThread() failed"); + return NGX_ERROR; + } + + *tid = id; + + return NGX_OK; +} diff --git a/src/os/win32/ngx_os_thread.h b/src/os/win32/ngx_os_thread.h new file mode 100644 index 000000000..81eb3b968 --- /dev/null +++ b/src/os/win32/ngx_os_thread.h @@ -0,0 +1,14 @@ +#ifndef _NGX_OS_THREAD_H_INCLUDED_ +#define _NGX_OS_THREAD_H_INCLUDED_ + + +#include <ngx_config.h> + + +typedef HANDLE ngx_os_tid_t; +typedef int ngx_tid_t; + +typedef LPTHREAD_START_ROUTINE ngx_thread_start_routine_t + + +#endif /* _NGX_OS_THREAD_H_INCLUDED_ */ |
