/*********************************/
+#if (NGX_DEBUG)
+
#if (HAVE_VARIADIC_MACROS)
-#if (NGX_DEBUG)
#define ngx_log_debug0(level, log, err, fmt) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt)
-#else
-#define ngx_log_debug0(level, log, err, fmt)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug1(level, log, err, fmt, arg1) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1)
-#else
-#define ngx_log_debug1(level, log, err, fmt, arg1)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2)
-#else
-#define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2, arg3)
-#else
-#define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, arg1, arg2, arg3, arg4)
-#else
-#define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \
arg1, arg2, arg3, arg4, arg5)
-#else
-#define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug6(level, log, err, fmt, \
arg1, arg2, arg3, arg4, arg5, arg6) \
if (log->log_level & level) \
ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, \
arg1, arg2, arg3, arg4, arg5, arg6)
-#else
-#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
-#endif
-
-/*********************************/
#else /* NO VARIADIC MACROS */
-#if (NGX_DEBUG)
#define ngx_log_debug0(level, log, err, fmt) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt)
-#else
-#define ngx_log_debug0(level, log, err, fmt)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug1(level, log, err, fmt, arg1) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1)
-#else
-#define ngx_log_debug1(level, log, err, fmt, arg1)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug2(level, log, err, fmt, arg1, arg2) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1, arg2)
-#else
-#define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3)
-#else
-#define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4)
-#else
-#define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5)
-#else
-#define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
-#endif
-#if (NGX_DEBUG)
#define ngx_log_debug6(level, log, err, fmt, \
arg1, arg2, arg3, arg4, arg5, arg6) \
if (log->log_level & level) \
ngx_log_debug_core(log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
-#else
-#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
-#endif
#endif
+#else /* NO NGX_DEBUG */
+
+#define ngx_log_debug0(level, log, err, fmt)
+#define ngx_log_debug1(level, log, err, fmt, arg1)
+#define ngx_log_debug2(level, log, err, fmt, arg1, arg2)
+#define ngx_log_debug3(level, log, err, fmt, arg1, arg2, arg3)
+#define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4)
+#define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5)
+#define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
+
+#endif
/*********************************/
#include <ngx_core.h>
#include <ngx_event.h>
-/*
- * TODO: eliminate mutex and use atomic_xchg():
- * ev->next = ev; ngx_atomic_xchg(ngx_posted_events, ev->next);
- * in ngx_event_busy_unlock() and ngx_event_busy_lock_handler()
- */
-
static int ngx_event_busy_lock_look_cachable(ngx_event_busy_lock_t *bl,
ngx_event_busy_lock_ctx_t *ctx);
{
ngx_int_t rc;
-#if (NGX_THREADS)
if (ngx_mutex_lock(bl->mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ctx->event->log, 0,
"event busy lock: b:%d mb:%d",
rc = NGX_BUSY;
}
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
return rc;
}
{
ngx_int_t rc;
-#if (NGX_THREADS)
if (ngx_mutex_lock(bl->mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
rc = ngx_event_busy_lock_look_cachable(bl, ctx);
}
}
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
return rc;
}
ngx_event_t *ev;
ngx_event_busy_lock_ctx_t *wakeup;
-#if (NGX_THREADS)
if (ngx_mutex_lock(bl->mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
if (bl->events) {
wakeup = bl->events;
}
/*
- * MP:
- * nocachable (bl->md5 == NULL): ngx_shared_mutex_unlock(mutex, !wakeup)
- * cachable (bl->md5): ???
+ * MP: all ctx's and their queue must be in shared memory,
+ * each ctx has pid to wake up
*/
if (wakeup == NULL) {
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
return NGX_OK;
}
if (ctx->md5) {
for (wakeup = bl->events; wakeup; wakeup = wakeup->next) {
- if (wakeup->md5 == NULL) {
+ if (wakeup->md5 == NULL || wakeup->slot != ctx->slot) {
continue;
}
- if (ngx_memcmp(ctx->md5, wakeup->md5, 16) != 0) {
- continue;
- }
-
wakeup->handler = ngx_event_busy_lock_posted_handler;
wakeup->cache_updated = 1;
ev = wakeup->event;
-#if (NGX_THREADS)
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
ev->next = (ngx_event_t *) ngx_posted_events;
ngx_posted_events = ev;
-#if (NGX_THREADS)
ngx_mutex_unlock(ngx_posted_events_mutex);
-#endif
}
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
} else {
bl->waiting--;
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
wakeup->handler = ngx_event_busy_lock_posted_handler;
wakeup->locked = 1;
ngx_del_timer(ev);
}
-#if (NGX_THREADS)
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
ev->next = (ngx_event_t *) ngx_posted_events;
ngx_posted_events = ev;
-#if (NGX_THREADS)
ngx_mutex_unlock(ngx_posted_events_mutex);
-#endif
}
return NGX_OK;
{
ngx_event_busy_lock_ctx_t *c, *p;
-#if (NGX_THREADS)
if (ngx_mutex_lock(bl->mutex) == NGX_ERROR) {
return NGX_ERROR;
}
-#endif
bl->waiting--;
}
}
-#if (NGX_THREADS)
ngx_mutex_unlock(bl->mutex);
-#endif
return NGX_OK;
}
if (mask & 1) {
if (ngx_memcmp(&bl->md5[i * 16], ctx->md5, 16) == 0) {
+ ctx->waiting = 1;
+ ctx->slot = i;
return NGX_AGAIN;
}
cachable++;
static void ngx_event_busy_lock_handler(ngx_event_t *ev)
{
- ev->event_handler = ngx_event_busy_lock_posted_handler;
-
-#if (NGX_THREADS)
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
return;
}
-#endif
ev->next = (ngx_event_t *) ngx_posted_events;
ngx_posted_events = ev;
-#if (NGX_THREADS)
ngx_mutex_unlock(ngx_posted_events_mutex);
-#endif
+
+ ev->event_handler = ngx_event_busy_lock_posted_handler;
}