diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2002-08-20 14:48:28 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2002-08-20 14:48:28 +0000 |
| commit | 2b54238a5f2edcca568c0676a779ef79ba152c91 (patch) | |
| tree | 2cb7eb660e691eaab2c4f031adf881b7c88bffc9 /src/os/unix | |
| parent | e0af1b89dcd100462a3195534b2f78a838ca85b5 (diff) | |
| download | nginx-2b54238a5f2edcca568c0676a779ef79ba152c91.tar.gz nginx-2b54238a5f2edcca568c0676a779ef79ba152c91.tar.bz2 | |
nginx-0.0.1-2002-08-20-18:48:28 import
Diffstat (limited to 'src/os/unix')
| -rw-r--r-- | src/os/unix/freebsd/ngx_rfork_thread.c | 64 | ||||
| -rw-r--r-- | src/os/unix/freebsd/ngx_rfork_thread.h | 24 | ||||
| -rw-r--r-- | src/os/unix/freebsd/ngx_sendfile.c (renamed from src/os/unix/ngx_sendfile.c) | 6 | ||||
| -rw-r--r-- | src/os/unix/ngx_errno.h | 1 | ||||
| -rw-r--r-- | src/os/unix/ngx_file.h | 29 | ||||
| -rw-r--r-- | src/os/unix/ngx_sendfile.h | 2 | ||||
| -rw-r--r-- | src/os/unix/ngx_sendv.c | 1 | ||||
| -rw-r--r-- | src/os/unix/ngx_sendv.h | 1 | ||||
| -rw-r--r-- | src/os/unix/ngx_socket.h | 3 | ||||
| -rw-r--r-- | src/os/unix/ngx_stat.h | 19 | ||||
| -rw-r--r-- | src/os/unix/ngx_time.h | 2 | ||||
| -rw-r--r-- | src/os/unix/ngx_types.h | 2 |
12 files changed, 131 insertions, 23 deletions
diff --git a/src/os/unix/freebsd/ngx_rfork_thread.c b/src/os/unix/freebsd/ngx_rfork_thread.c new file mode 100644 index 000000000..acd5ec6e2 --- /dev/null +++ b/src/os/unix/freebsd/ngx_rfork_thread.c @@ -0,0 +1,64 @@ + +#include <ngx_os_thread.h> + +char *ngx_stacks_start; +char *ngx_stacks_end; +size_t ngx_stack_size; + + +/* handle thread-safe errno */ +static int errno0; /* errno for main thread */ +static int *errnos; + +int *__error() +{ + ngx_tid_t tid = ngx_gettid(); + return tid ? &(errnos[ngx_gettid()]) : &errno0; +} + + +int ngx_create_thread(ngx_os_tid_t *tid, void *stack, + int (*func)(void *arg), void *arg, ngx_log_t log) +{ + int id, err; + + id = rfork_thread(RFPROC|RFMEM, stack, func, arg); + err = ngx_errno; + + if (id == -1) + ngx_log_error(NGX_LOG_ERR, log, err, + "ngx_create_os_thread: rfork failed"); + else + *tid = id; + + return err; +} + + +int ngx_create_thread_env(int n, size_t size, ngx_log_t log) +{ + char *addr; + + /* create thread stacks */ + addr = mmap(NULL, n * size, PROT_READ|PROT_WRITE, MAP_ANON, -1, NULL); + if (addr == MAP_FAILED) { + ngx_log_error(NGX_LOG_ERR, log, ngx_errno, + "ngx_create_os_thread_stacks: mmap failed"); + return -1; + } + + nxg_stacks_start = addr; + nxg_stacks_end = addr + n * size; + nxg_stack_size = size; + + /* create thread errno array */ + ngx_test_null(errnos, ngx_calloc(n * sizeof(int)), -1); + + /* create thread tid array */ + ngx_test_null(ngx_os_tids, ngx_calloc(n * sizeof(ngx_os_tid_t)), -1); + + /* allow spinlock in malloc() */ + __isthreaded = 1; + + return 0; +} diff --git a/src/os/unix/freebsd/ngx_rfork_thread.h b/src/os/unix/freebsd/ngx_rfork_thread.h new file mode 100644 index 000000000..bd500e1a4 --- /dev/null +++ b/src/os/unix/freebsd/ngx_rfork_thread.h @@ -0,0 +1,24 @@ +#ifndef _NGX_OS_THREAD_H_INCLUDED_ +#define _NGX_OS_THREAD_H_INCLUDED_ + + +typedef int ngx_os_tid_t; +typedef int ngx_tid_t; + + +extern char *ngx_stacks_start; +extern char *ngx_stacks_end; +extern size_t ngx_stack_size; + + +static inline ngx_tid_t ngx_gettid() +{ + char *sp; + + __asm__ ("mov %%esp,%0" : "=r" (sp)); + return (sp > ngx_stacks_end) ? 0: + (sp - ngx_stacks_start) / ngx_stack_size + 1; +} + + +#endif /* _NGX_OS_THREAD_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_sendfile.c b/src/os/unix/freebsd/ngx_sendfile.c index 2bc157361..31915e405 100644 --- a/src/os/unix/ngx_sendfile.c +++ b/src/os/unix/freebsd/ngx_sendfile.c @@ -1,6 +1,8 @@ #include <ngx_config.h> #include <ngx_types.h> +#include <ngx_file.h> +#include <ngx_socket.h> #include <ngx_errno.h> #include <ngx_log.h> #include <ngx_sendv.h> @@ -56,8 +58,8 @@ int ngx_sendfile(ngx_socket_t s, } } - ngx_log_debug(log, "ngx_sendfile: %d, @%qd %d:%qd" _ - rc _ offset _ nbytes _ *sent); + ngx_log_debug(log, "ngx_sendfile: %d, @%qd %qd:%d" _ + rc _ offset _ *sent _ nbytes); return 0; } diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h index c14a977fa..2649fe9b4 100644 --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -10,6 +10,7 @@ typedef int ngx_err_t; #define NGX_ENOENT ENOENT #define NGX_EINTR EINTR #define NGX_EAGAIN EWOULDBLOCK +#define NGX_EADDRINUSE EADDRINUSE #define ngx_errno errno #define ngx_socket_errno errno diff --git a/src/os/unix/ngx_file.h b/src/os/unix/ngx_file.h new file mode 100644 index 000000000..0e05b8424 --- /dev/null +++ b/src/os/unix/ngx_file.h @@ -0,0 +1,29 @@ +#ifndef _NGX_FILE_H_INCLUDED_ +#define _NGX_FILE_H_INCLUDED_ + + +#include <sys/types.h> +#include <sys/stat.h> + +typedef int ngx_file_t; +typedef struct stat ngx_file_info_t; + + +#define ngx_open_file open +#define ngx_open_file_n "open" + +#define NGX_FILE_RDONLY O_RDONLY + + +#define ngx_file_type(file, sb) stat(file, sb) +#define ngx_file_type_n "stat" + +#define ngx_stat_fd(fd, sb) fstat(fd, sb) +#define ngx_stat_fd_n "fstat" + +#define ngx_is_dir(sb) (S_ISDIR(sb.st_mode)) +#define ngx_file_size(sb) sb.st_size +#define ngx_file_mtime(sb) sb.st_mtime + + +#endif /* _NGX_FILE_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_sendfile.h b/src/os/unix/ngx_sendfile.h index a347c6c50..0a0a25e76 100644 --- a/src/os/unix/ngx_sendfile.h +++ b/src/os/unix/ngx_sendfile.h @@ -3,6 +3,8 @@ #include <ngx_types.h> +#include <ngx_file.h> +#include <ngx_socket.h> #include <ngx_log.h> #include <ngx_sendv.h> diff --git a/src/os/unix/ngx_sendv.c b/src/os/unix/ngx_sendv.c index bd95d7a7d..22838c2bb 100644 --- a/src/os/unix/ngx_sendv.c +++ b/src/os/unix/ngx_sendv.c @@ -1,5 +1,6 @@ #include <ngx_types.h> +#include <ngx_socket.h> #include <ngx_sendv.h> ssize_t ngx_sendv(ngx_socket_t s, ngx_iovec_t *iovec, int n, size_t *sent) diff --git a/src/os/unix/ngx_sendv.h b/src/os/unix/ngx_sendv.h index 16c24039b..5906e423b 100644 --- a/src/os/unix/ngx_sendv.h +++ b/src/os/unix/ngx_sendv.h @@ -3,6 +3,7 @@ #include <ngx_types.h> +#include <ngx_socket.h> typedef struct iovec ngx_iovec_t; #define ngx_iov_base iov_base diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h index 18c07f9b0..e9e797474 100644 --- a/src/os/unix/ngx_socket.h +++ b/src/os/unix/ngx_socket.h @@ -12,5 +12,8 @@ typedef int ngx_socket_t; #define ngx_nonblocking(s) fcntl(s, F_SETFL, O_NONBLOCK) #define ngx_nonblocking_n "fcntl (O_NONBLOCK)" +#define ngx_close_socket close +#define ngx_close_socket_n "close" + #endif /* _NGX_SOCKET_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_stat.h b/src/os/unix/ngx_stat.h deleted file mode 100644 index f42edff13..000000000 --- a/src/os/unix/ngx_stat.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _NGX_STAT_H_INCLUDED_ -#define _NGX_STAT_H_INCLUDED_ - - -#include <sys/types.h> -#include <sys/stat.h> - -typedef struct stat ngx_stat_t; - -#define ngx_is_dir(sb) (S_ISDIR(sb.st_mode)) - -#define ngx_stat(file, sb) stat(file, sb) -#define ngx_stat_n "stat" - -#define ngx_fstat(file, fd, sb) fstat(fd, sb) -#define ngx_fstat_n "stat" - - -#endif /* _NGX_STAT_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h index b262da7cf..f81ee4efc 100644 --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -14,6 +14,8 @@ typedef struct tm ngx_tm_t; #define ngx_tm_year tm_year #define ngx_tm_wday tm_wday +#define ngx_msleep(ms) usleep(ms * 1000) + void ngx_localtime(ngx_tm_t *tm); u_int ngx_msec(void); diff --git a/src/os/unix/ngx_types.h b/src/os/unix/ngx_types.h index ebcbb1fac..94417cba9 100644 --- a/src/os/unix/ngx_types.h +++ b/src/os/unix/ngx_types.h @@ -5,8 +5,6 @@ #include <ngx_config.h> -typedef int ngx_file_t; -typedef int ngx_socket_t; #endif /* _NGX_TYPES_H_INCLUDED_ */ |
