diff options
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/unix/ngx_atomic.h | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_files.c | 61 | ||||
-rw-r--r-- | src/os/unix/ngx_files.h | 9 | ||||
-rw-r--r-- | src/os/unix/ngx_gcc_atomic_amd64.h | 4 | ||||
-rw-r--r-- | src/os/unix/ngx_gcc_atomic_ppc.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_gcc_atomic_sparc64.h | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_gcc_atomic_x86.h | 3 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_sunpro_atomic_sparc64.h | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_atomic.h | 9 |
10 files changed, 65 insertions, 34 deletions
diff --git a/src/os/unix/ngx_atomic.h b/src/os/unix/ngx_atomic.h index 50d6354d5..c505027fd 100644 --- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -34,6 +34,7 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); /* the code in src/os/unix/ngx_sunpro_x86.il */ #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") +#define ngx_cpu_pause() __asm ("pause") #else /* ( __GNUC__ || __INTEL_COMPILER ) */ @@ -67,6 +68,7 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); /* the code in src/os/unix/ngx_sunpro_amd64.il */ #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") +#define ngx_cpu_pause() __asm ("pause") #else /* ( __GNUC__ || __INTEL_COMPILER ) */ @@ -175,10 +177,11 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) } #define ngx_memory_barrier() +#define ngx_cpu_pause() #endif -void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); +void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) #define ngx_unlock(lock) *(lock) = 0 diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c index b5a807bb6..f89147df1 100644 --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -235,59 +235,58 @@ ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) } -ngx_int_t -ngx_lock_file(ngx_file_t *file) +ngx_err_t +ngx_trylock_fd(ngx_fd_t fd) { - ngx_err_t err; struct flock fl; - fl.l_whence = SEEK_SET; + fl.l_start = 0; fl.l_len = 0; fl.l_pid = 0; fl.l_type = F_WRLCK; - fl.l_start = 0; + fl.l_whence = SEEK_SET; - if (fcntl(file->fd, F_SETLK, &fl) == -1) { - err = ngx_errno; + if (fcntl(fd, F_SETLK, &fl) == -1) { + return ngx_errno; + } - if (err == NGX_EAGAIN) { - return NGX_BUSY; - } + return 0; +} - ngx_log_error(NGX_LOG_ALERT, file->log, err, - "fcntl(%s, F_SETLK, F_WRLCK) failed", file->name.data); - return NGX_ERROR; +ngx_err_t +ngx_lock_fd(ngx_fd_t fd) +{ + struct flock fl; + + fl.l_start = 0; + fl.l_len = 0; + fl.l_pid = 0; + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + + if (fcntl(fd, F_SETLKW, &fl) == -1) { + return ngx_errno; } - return NGX_OK; + return 0; } -ngx_int_t -ngx_unlock_file(ngx_file_t *file) +ngx_err_t +ngx_unlock_fd(ngx_fd_t fd) { - ngx_err_t err; struct flock fl; - fl.l_whence = SEEK_SET; + fl.l_start = 0; fl.l_len = 0; fl.l_pid = 0; fl.l_type = F_UNLCK; - fl.l_start = 0; - - if (fcntl(file->fd, F_SETLK, &fl) == -1) { - err = ngx_errno; - - if (err == NGX_EAGAIN) { - return NGX_BUSY; - } - - ngx_log_error(NGX_LOG_ALERT, file->log, err, - "fcntl(%s, F_SETLK, F_UNLCK) failed", file->name.data); + fl.l_whence = SEEK_SET; - return NGX_ERROR; + if (fcntl(fd, F_SETLK, &fl) == -1) { + return ngx_errno; } - return NGX_OK; + return 0; } diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h index a361fe4cd..fcf5da4ad 100644 --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -119,4 +119,13 @@ ngx_int_t ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir); #define ngx_de_mtime(dir) (dir)->info.st_mtime +ngx_err_t ngx_trylock_fd(ngx_fd_t fd); +ngx_err_t ngx_lock_fd(ngx_fd_t fd); +ngx_err_t ngx_unlock_fd(ngx_fd_t fd); + +#define ngx_trylock_fd_n "fcntl(F_SETLK, F_WRLCK)" +#define ngx_lock_fd_n "fcntl(F_SETLKW, F_WRLCK)" +#define ngx_unlock_fd_n "fcntl(F_SETLK, F_UNLCK)" + + #endif /* _NGX_FILES_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_gcc_atomic_amd64.h b/src/os/unix/ngx_gcc_atomic_amd64.h index 2183e738e..289cd614e 100644 --- a/src/os/unix/ngx_gcc_atomic_amd64.h +++ b/src/os/unix/ngx_gcc_atomic_amd64.h @@ -74,4 +74,6 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) } -#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") +#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") + +#define ngx_cpu_pause() __asm__ ("pause") diff --git a/src/os/unix/ngx_gcc_atomic_ppc.h b/src/os/unix/ngx_gcc_atomic_ppc.h index a6bbb39d1..5339ba98c 100644 --- a/src/os/unix/ngx_gcc_atomic_ppc.h +++ b/src/os/unix/ngx_gcc_atomic_ppc.h @@ -71,3 +71,5 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) #else #define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") #endif + +#define ngx_cpu_pause() diff --git a/src/os/unix/ngx_gcc_atomic_sparc64.h b/src/os/unix/ngx_gcc_atomic_sparc64.h index fc6bacee2..e5a6254ec 100644 --- a/src/os/unix/ngx_gcc_atomic_sparc64.h +++ b/src/os/unix/ngx_gcc_atomic_sparc64.h @@ -77,3 +77,5 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) #else #define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") #endif + +#define ngx_cpu_pause() diff --git a/src/os/unix/ngx_gcc_atomic_x86.h b/src/os/unix/ngx_gcc_atomic_x86.h index 8e3480d71..1e1582580 100644 --- a/src/os/unix/ngx_gcc_atomic_x86.h +++ b/src/os/unix/ngx_gcc_atomic_x86.h @@ -118,3 +118,6 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) */ #define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") + +/* old as does not support "pause" opcode */ +#define ngx_cpu_pause() __asm__ (".byte 0xf3, 0x90") diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 83d5f3024..a44a89cb8 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -45,6 +45,8 @@ ngx_os_init(ngx_log_t *log) ngx_ncpu = 1; } + ngx_cpuinfo(); + if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) { ngx_log_error(NGX_LOG_ALERT, log, errno, "getrlimit(RLIMIT_NOFILE) failed)"); diff --git a/src/os/unix/ngx_sunpro_atomic_sparc64.h b/src/os/unix/ngx_sunpro_atomic_sparc64.h index 691e94ee5..db852114b 100644 --- a/src/os/unix/ngx_sunpro_atomic_sparc64.h +++ b/src/os/unix/ngx_sunpro_atomic_sparc64.h @@ -56,3 +56,5 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) __asm (".volatile"); \ __asm ("membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); \ __asm (".nonvolatile") + +#define ngx_cpu_pause() diff --git a/src/os/win32/ngx_atomic.h b/src/os/win32/ngx_atomic.h index 8003b740f..5e32f1f33 100644 --- a/src/os/win32/ngx_atomic.h +++ b/src/os/win32/ngx_atomic.h @@ -45,7 +45,14 @@ typedef volatile ngx_atomic_uint_t ngx_atomic_t; #define ngx_memory_barrier() -void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); +#ifdef __BORLANDC__ +#define ngx_cpu_pause() +#else +#define ngx_cpu_pause() __asm { pause } +#endif + + +void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) #define ngx_unlock(lock) *(lock) = 0 |