summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2011-05-10 12:27:59 +0000
committerJonathan Kolb <jon@b0g.us>2011-05-10 12:27:59 +0000
commit1b122b0876a0f0e1efcb4be6d730f353b04759ea (patch)
tree58497c7a5811e177d11558dc83ae728d5ad2f9fc
parenta6bc51d66d27bb318bfb1d4139e72cb61c7151a6 (diff)
downloadnginx-1b122b0876a0f0e1efcb4be6d730f353b04759ea.tar.gz
Changes with nginx 1.0.2 10 May 2011v1.0.2
*) Feature: now shared zones and caches use POSIX semaphores. *) Bugfix: in the "rotate" parameter of the "image_filter" directive. Thanks to Adam Bocim. *) Bugfix: nginx could not be built on Solaris; the bug had appeared in 1.0.1.
-rw-r--r--CHANGES14
-rw-r--r--CHANGES.ru10
-rw-r--r--auto/os/freebsd9
-rwxr-xr-xauto/unix14
-rw-r--r--src/core/nginx.h4
-rw-r--r--src/core/ngx_shmtx.c215
-rw-r--r--src/core/ngx_shmtx.h88
-rw-r--r--src/event/ngx_event.c1
-rw-r--r--src/http/modules/ngx_http_image_filter_module.c20
-rw-r--r--src/http/modules/perl/nginx.pm2
-rw-r--r--src/os/unix/ngx_darwin_config.h5
-rw-r--r--src/os/unix/ngx_freebsd_config.h5
-rw-r--r--src/os/unix/ngx_linux_config.h5
-rw-r--r--src/os/unix/ngx_posix_config.h5
-rw-r--r--src/os/unix/ngx_solaris_config.h5
15 files changed, 313 insertions, 89 deletions
diff --git a/CHANGES b/CHANGES
index d3925000e..fc2bb213d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,15 @@
+Changes with nginx 1.0.2 10 May 2011
+
+ *) Feature: now shared zones and caches use POSIX semaphores.
+
+ *) Bugfix: in the "rotate" parameter of the "image_filter" directive.
+ Thanks to Adam Bocim.
+
+ *) Bugfix: nginx could not be built on Solaris; the bug had appeared in
+ 1.0.1.
+
+
Changes with nginx 1.0.1 03 May 2011
*) Change: now the "split_clients" directive uses MurmurHash2 algorithm
@@ -69,8 +80,7 @@ Changes with nginx 0.9.6 21 Mar 2011
Changes with nginx 0.9.5 21 Feb 2011
- *) Change: now nginx uses a default listen backlog value -1 on
- Linux.
+ *) Change: now nginx uses a default listen backlog value -1 on Linux.
Thanks to Andrei Nigmatulin.
*) Feature: the "utf8" parameter of "geoip_country" and "geoip_city"
diff --git a/CHANGES.ru b/CHANGES.ru
index 587db9727..78bbb9b17 100644
--- a/CHANGES.ru
+++ b/CHANGES.ru
@@ -1,4 +1,14 @@
+Изменения в nginx 1.0.2 10.05.2011
+
+ *) Добавление: теперь разделяемые зоны и кэши используют семафоры POSIX.
+
+ *) Исправление: в работе параметра rotate директивы image_filter.
+ Спасибо Adam Bocim.
+
+ *) Исправление: nginx не собирался на Solaris; ошибка появилась в 1.0.1.
+
+
Изменения в nginx 1.0.1 03.05.2011
*) Изменение: теперь директива split_clients использует алгоритм
diff --git a/auto/os/freebsd b/auto/os/freebsd
index 20985294f..082938800 100644
--- a/auto/os/freebsd
+++ b/auto/os/freebsd
@@ -49,6 +49,15 @@ if [ $osreldate -gt 502103 ]; then
have=NGX_HAVE_AIO_SENDFILE . auto/have
fi
+# POSIX semaphores
+# http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/127545
+
+if [ $osreldate -ge 701106 ]; then
+ echo " + POSIX semaphores should work"
+else
+ have=NGX_HAVE_POSIX_SEM . auto/nohave
+fi
+
# kqueue
diff --git a/auto/unix b/auto/unix
index fadf7dd76..669314b42 100755
--- a/auto/unix
+++ b/auto/unix
@@ -141,7 +141,7 @@ if [ $ngx_found = no ]; then
ngx_feature_name=NGX_SYS_NERR
ngx_feature_run=value
ngx_feature_incs='#include <errno.h>
- #include <string.h>'
+ #include <string.h>
#include <stdio.h>'
ngx_feature_path=
ngx_feature_libs=
@@ -234,6 +234,18 @@ ngx_feature_test="int id;
. auto/feature
+ngx_feature="POSIX semaphores"
+ngx_feature_name="NGX_HAVE_POSIX_SEM"
+ngx_feature_run=yes
+ngx_feature_incs="#include <semaphore.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="sem_t sem;
+ if (sem_init(&sem, 1, 0) == -1) return 1;
+ sem_destroy(&sem);"
+. auto/feature
+
+
ngx_feature="struct msghdr.msg_control"
ngx_feature_name="NGX_HAVE_MSGHDR_MSG_CONTROL"
ngx_feature_run=no
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 484d214b6..c2e56221f 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,8 +8,8 @@
#define _NGINX_H_INCLUDED_
-#define nginx_version 1000001
-#define NGINX_VERSION "1.0.1"
+#define nginx_version 1000002
+#define NGINX_VERSION "1.0.2"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"
diff --git a/src/core/ngx_shmtx.c b/src/core/ngx_shmtx.c
index ead94e484..3b429c4f9 100644
--- a/src/core/ngx_shmtx.c
+++ b/src/core/ngx_shmtx.c
@@ -16,9 +16,166 @@ ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name)
{
mtx->lock = addr;
+ if (mtx->spin == (ngx_uint_t) -1) {
+ return NGX_OK;
+ }
+
+ mtx->spin = 2048;
+
+#if (NGX_HAVE_POSIX_SEM)
+
+ if (sem_init(&mtx->sem, 1, 0) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "sem_init() failed");
+ } else {
+ mtx->semaphore = 1;
+ }
+
+#endif
+
return NGX_OK;
}
+
+void
+ngx_shmtx_destory(ngx_shmtx_t *mtx)
+{
+#if (NGX_HAVE_POSIX_SEM)
+
+ if (mtx->semaphore) {
+ if (sem_destroy(&mtx->sem) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "sem_destroy() failed");
+ }
+ }
+
+#endif
+}
+
+
+ngx_uint_t
+ngx_shmtx_trylock(ngx_shmtx_t *mtx)
+{
+ ngx_atomic_uint_t val;
+
+ val = *mtx->lock;
+
+ return ((val & 0x80000000) == 0
+ && ngx_atomic_cmp_set(mtx->lock, val, val | 0x80000000));
+}
+
+
+void
+ngx_shmtx_lock(ngx_shmtx_t *mtx)
+{
+ ngx_uint_t i, n;
+ ngx_atomic_uint_t val;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "shmtx lock");
+
+ for ( ;; ) {
+
+ val = *mtx->lock;
+
+ if ((val & 0x80000000) == 0
+ && ngx_atomic_cmp_set(mtx->lock, val, val | 0x80000000))
+ {
+ return;
+ }
+
+ if (ngx_ncpu > 1) {
+
+ for (n = 1; n < mtx->spin; n <<= 1) {
+
+ for (i = 0; i < n; i++) {
+ ngx_cpu_pause();
+ }
+
+ val = *mtx->lock;
+
+ if ((val & 0x80000000) == 0
+ && ngx_atomic_cmp_set(mtx->lock, val, val | 0x80000000))
+ {
+ return;
+ }
+ }
+ }
+
+#if (NGX_HAVE_POSIX_SEM)
+
+ if (mtx->semaphore) {
+ val = *mtx->lock;
+
+ if ((val & 0x80000000)
+ && ngx_atomic_cmp_set(mtx->lock, val, val + 1))
+ {
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
+ "shmtx wait %XA", val);
+
+ while (sem_wait(&mtx->sem) == -1) {
+ ngx_err_t err;
+
+ err = ngx_errno;
+
+ if (err != NGX_EINTR) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err,
+ "sem_wait() failed while waiting on shmtx");
+ break;
+ }
+ }
+
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
+ "shmtx awoke");
+ }
+
+ continue;
+ }
+
+#endif
+
+ ngx_sched_yield();
+ }
+}
+
+
+void
+ngx_shmtx_unlock(ngx_shmtx_t *mtx)
+{
+ ngx_atomic_uint_t val, old, wait;
+
+ if (mtx->spin != (ngx_uint_t) -1) {
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0, "shmtx unlock");
+ }
+
+ for ( ;; ) {
+
+ old = *mtx->lock;
+ wait = old & 0x7fffffff;
+ val = wait ? wait - 1 : 0;
+
+ if (ngx_atomic_cmp_set(mtx->lock, old, val)) {
+ break;
+ }
+ }
+
+#if (NGX_HAVE_POSIX_SEM)
+
+ if (wait == 0 || !mtx->semaphore) {
+ return;
+ }
+
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
+ "shmtx wake %XA", old);
+
+ if (sem_post(&mtx->sem) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
+ "sem_post() failed while wake shmtx");
+ }
+
+#endif
+}
+
+
#else
@@ -65,4 +222,62 @@ ngx_shmtx_destory(ngx_shmtx_t *mtx)
}
+ngx_uint_t
+ngx_shmtx_trylock(ngx_shmtx_t *mtx)
+{
+ ngx_err_t err;
+
+ err = ngx_trylock_fd(mtx->fd);
+
+ if (err == 0) {
+ return 1;
+ }
+
+ if (err == NGX_EAGAIN) {
+ return 0;
+ }
+
+#if __osf__ /* Tru64 UNIX */
+
+ if (err == NGX_EACCESS) {
+ return 0;
+ }
+
+#endif
+
+ ngx_log_abort(err, ngx_trylock_fd_n " %s failed", mtx->name);
+
+ return 0;
+}
+
+
+void
+ngx_shmtx_lock(ngx_shmtx_t *mtx)
+{
+ ngx_err_t err;
+
+ err = ngx_lock_fd(mtx->fd);
+
+ if (err == 0) {
+ return;
+ }
+
+ ngx_log_abort(err, ngx_lock_fd_n " %s failed", mtx->name);
+}
+
+
+void
+ngx_shmtx_unlock(ngx_shmtx_t *mtx)
+{
+ ngx_err_t err;
+
+ err = ngx_unlock_fd(mtx->fd);
+
+ if (err == 0) {
+ return;
+ }
+
+ ngx_log_abort(err, ngx_unlock_fd_n " %s failed", mtx->name);
+}
+
#endif
diff --git a/src/core/ngx_shmtx.h b/src/core/ngx_shmtx.h
index 57fe0b9f5..714f73aa6 100644
--- a/src/core/ngx_shmtx.h
+++ b/src/core/ngx_shmtx.h
@@ -15,95 +15,23 @@
typedef struct {
#if (NGX_HAVE_ATOMIC_OPS)
ngx_atomic_t *lock;
+#if (NGX_HAVE_POSIX_SEM)
+ ngx_uint_t semaphore;
+ sem_t sem;
+#endif
#else
ngx_fd_t fd;
u_char *name;
#endif
+ ngx_uint_t spin;
} ngx_shmtx_t;
ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, void *addr, u_char *name);
-
-
-#if (NGX_HAVE_ATOMIC_OPS)
-
-static ngx_inline ngx_uint_t
-ngx_shmtx_trylock(ngx_shmtx_t *mtx)
-{
- return (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid));
-}
-
-#define ngx_shmtx_lock(mtx) ngx_spinlock((mtx)->lock, ngx_pid, 1024)
-
-#define ngx_shmtx_unlock(mtx) (void) ngx_atomic_cmp_set((mtx)->lock, ngx_pid, 0)
-
-#define ngx_shmtx_destory(mtx)
-
-
-#else
-
-static ngx_inline ngx_uint_t
-ngx_shmtx_trylock(ngx_shmtx_t *mtx)
-{
- ngx_err_t err;
-
- err = ngx_trylock_fd(mtx->fd);
-
- if (err == 0) {
- return 1;
- }
-
- if (err == NGX_EAGAIN) {
- return 0;
- }
-
-#if __osf__ /* Tru64 UNIX */
-
- if (err == NGX_EACCESS) {
- return 0;
- }
-
-#endif
-
- ngx_log_abort(err, ngx_trylock_fd_n " %s failed", mtx->name);
-
- return 0;
-}
-
-
-static ngx_inline void
-ngx_shmtx_lock(ngx_shmtx_t *mtx)
-{
- ngx_err_t err;
-
- err = ngx_lock_fd(mtx->fd);
-
- if (err == 0) {
- return;
- }
-
- ngx_log_abort(err, ngx_lock_fd_n " %s failed", mtx->name);
-}
-
-
-static ngx_inline void
-ngx_shmtx_unlock(ngx_shmtx_t *mtx)
-{
- ngx_err_t err;
-
- err = ngx_unlock_fd(mtx->fd);
-
- if (err == 0) {
- return;
- }
-
- ngx_log_abort(err, ngx_unlock_fd_n " %s failed", mtx->name);
-}
-
-
void ngx_shmtx_destory(ngx_shmtx_t *mtx);
-
-#endif
+ngx_uint_t ngx_shmtx_trylock(ngx_shmtx_t *mtx);
+void ngx_shmtx_lock(ngx_shmtx_t *mtx);
+void ngx_shmtx_unlock(ngx_shmtx_t *mtx);
#endif /* _NGX_SHMTX_H_INCLUDED_ */
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index 3922b0e20..c57d37ec4 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -519,6 +519,7 @@ ngx_event_module_init(ngx_cycle_t *cycle)
shared = shm.addr;
ngx_accept_mutex_ptr = (ngx_atomic_t *) shared;
+ ngx_accept_mutex.spin = (ngx_uint_t) -1;
if (ngx_shmtx_create(&ngx_accept_mutex, shared, cycle->lock_file.data)
!= NGX_OK)
diff --git a/src/http/modules/ngx_http_image_filter_module.c b/src/http/modules/ngx_http_image_filter_module.c
index ecbfd158b..dd3803fe3 100644
--- a/src/http/modules/ngx_http_image_filter_module.c
+++ b/src/http/modules/ngx_http_image_filter_module.c
@@ -723,7 +723,7 @@ ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
static ngx_buf_t *
ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
{
- int sx, sy, dx, dy, ox, oy, size,
+ int sx, sy, dx, dy, ox, oy, ax, ay, size,
colors, palette, transparent,
red, green, blue, t;
u_char *out;
@@ -852,6 +852,9 @@ transparent:
if (ctx->angle) {
src = dst;
+ ax = (dx % 2 == 0) ? 1 : 0;
+ ay = (dy % 2 == 0) ? 1 : 0;
+
switch (ctx->angle) {
case 90:
@@ -861,7 +864,17 @@ transparent:
gdImageDestroy(src);
return NULL;
}
- gdImageCopyRotated(dst, src, dy/2, dx/2, 0, 0, dx, dy, ctx->angle);
+ if (ctx->angle == 90) {
+ ox = dy / 2 + ay;
+ oy = dx / 2 - ax;
+
+ } else {
+ ox = dy / 2 - ay;
+ oy = dx / 2 + ax;
+ }
+
+ gdImageCopyRotated(dst, src, ox, oy, 0, 0,
+ dx + ax, dy + ay, ctx->angle);
gdImageDestroy(src);
t = dx;
@@ -875,7 +888,8 @@ transparent:
gdImageDestroy(src);
return NULL;
}
- gdImageCopyRotated(dst, src, dx/2, dy/2, 0, 0, dx, dy, ctx->angle);
+ gdImageCopyRotated(dst, src, dx / 2 - ax, dy / 2 - ay, 0, 0,
+ dx + ax, dy + ay, ctx->angle);
gdImageDestroy(src);
break;
}
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index 098d45b47..bc9790193 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -48,7 +48,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
-our $VERSION = '1.0.1';
+our $VERSION = '1.0.2';
require XSLoader;
XSLoader::load('nginx', $VERSION);
diff --git a/src/os/unix/ngx_darwin_config.h b/src/os/unix/ngx_darwin_config.h
index 39009768f..88aa6f502 100644
--- a/src/os/unix/ngx_darwin_config.h
+++ b/src/os/unix/ngx_darwin_config.h
@@ -56,6 +56,11 @@
#include <ngx_auto_config.h>
+#if (NGX_HAVE_POSIX_SEM)
+#include <semaphore.h>
+#endif
+
+
#if (NGX_HAVE_POLL)
#include <poll.h>
#endif
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index 20cb66640..ec7a375a8 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -68,6 +68,11 @@
#include <ngx_auto_config.h>
+#if (NGX_HAVE_POSIX_SEM)
+#include <semaphore.h>
+#endif
+
+
#if (NGX_HAVE_POLL)
#include <poll.h>
#endif
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index cf45e54a1..046095d1d 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -58,6 +58,11 @@
#include <ngx_auto_config.h>
+#if (NGX_HAVE_POSIX_SEM)
+#include <semaphore.h>
+#endif
+
+
#if (NGX_HAVE_SYS_PRCTL_H)
#include <sys/prctl.h>
#endif
diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h
index 86a80d701..aec8a0a35 100644
--- a/src/os/unix/ngx_posix_config.h
+++ b/src/os/unix/ngx_posix_config.h
@@ -96,6 +96,11 @@
#include <ngx_auto_config.h>
+#if (NGX_HAVE_POSIX_SEM)
+#include <semaphore.h>
+#endif
+
+
#if (NGX_HAVE_POLL)
#include <poll.h>
#endif
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index ae8212d8a..6b3d42eaa 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -57,6 +57,11 @@
#include <ngx_auto_config.h>
+#if (NGX_HAVE_POSIX_SEM)
+#include <semaphore.h>
+#endif
+
+
#if (NGX_HAVE_POLL)
#include <poll.h>
#endif