Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/event/modules/ngx_devpoll_module.c1
-rw-r--r--src/event/modules/ngx_kqueue_module.c7
-rw-r--r--src/event/modules/ngx_poll_module.c1
-rw-r--r--src/event/modules/ngx_select_module.c1
-rw-r--r--src/event/ngx_event.h18
-rw-r--r--src/event/ngx_event_close.c2
-rw-r--r--src/event/ngx_event_timer.c42
-rw-r--r--src/event/ngx_event_timer.h65
-rw-r--r--src/http/ngx_http.h2
-rw-r--r--src/http/ngx_http_event.c2
-rw-r--r--src/os/unix/ngx_time.h1
-rw-r--r--src/os/win32/ngx_time.h2
12 files changed, 138 insertions, 6 deletions
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 29cd298b1..ad44743a7 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -9,6 +9,7 @@
#include <ngx_log.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_devpoll_module.h>
#if (USE_DEVPOLL) && !(HAVE_DEVPOLL)
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index 49a2cb9e9..4662e816d 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -9,6 +9,7 @@
#include <ngx_log.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_kqueue_module.h>
#if (USE_KQUEUE) && !(HAVE_KQUEUE)
@@ -50,8 +51,14 @@ int ngx_kqueue_init(int max_connections, ngx_log_t *log)
ngx_test_null(change_list, ngx_alloc(change_size, log), NGX_ERROR);
ngx_test_null(event_list, ngx_alloc(event_size, log), NGX_ERROR);
+ if (ngx_event_init_timer(log) == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+
+#if 0
timer_queue.timer_prev = &timer_queue;
timer_queue.timer_next = &timer_queue;
+#endif
#if !(USE_KQUEUE)
ngx_event_actions.add = ngx_kqueue_add_event;
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 0338f7db6..4b2434a5d 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -7,6 +7,7 @@
#include <ngx_time.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_poll_module.h>
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 2fabf37fc..5b62dfd04 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -6,6 +6,7 @@
#include <ngx_time.h>
#include <ngx_connection.h>
#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_select_module.h>
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index c8365f17d..1b0ac062d 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -10,6 +10,7 @@
#include <ngx_alloc.h>
#include <ngx_array.h>
+
#define NGX_INVALID_INDEX 0x80000000
typedef struct ngx_event_s ngx_event_t;
@@ -31,8 +32,8 @@ struct ngx_event_s {
ngx_event_t *timer_prev;
ngx_event_t *timer_next;
- u_int timer_delta;
- u_int timer;
+ ngx_msec_t timer_delta;
+ ngx_msec_t timer;
ngx_log_t *log;
@@ -150,7 +151,11 @@ NGX_CLOSE_EVENT kqueue: kqueue deletes events for file that closed
#define ngx_process_events ngx_kqueue_process_events
#define ngx_add_event ngx_kqueue_add_event
#define ngx_del_event ngx_kqueue_del_event
+#if 0
#define ngx_add_timer ngx_kqueue_add_timer
+#else
+#define ngx_add_timer ngx_event_add_timer
+#endif
#define ngx_event_recv ngx_event_recv_core
#else
@@ -159,12 +164,19 @@ NGX_CLOSE_EVENT kqueue: kqueue deletes events for file that closed
#define ngx_process_events ngx_event_actions.process
#define ngx_add_event ngx_event_actions.add
#define ngx_del_event ngx_event_actions.del
+#if 0
#define ngx_add_timer ngx_event_actions.timer
+#else
+#define ngx_add_timer ngx_event_add_timer
+#endif
#define ngx_event_recv ngx_event_recv_core
#endif
+#define ngx_del_timer ngx_event_del_timer
+
+#if 0
ngx_inline static void ngx_del_timer(ngx_event_t *ev)
{
#if (NGX_DEBUG_EVENT)
@@ -186,7 +198,7 @@ ngx_inline static void ngx_del_timer(ngx_event_t *ev)
ev->timer_prev = NULL;
}
}
-
+#endif
diff --git a/src/event/ngx_event_close.c b/src/event/ngx_event_close.c
index 715a14b1a..c829c7172 100644
--- a/src/event/ngx_event_close.c
+++ b/src/event/ngx_event_close.c
@@ -3,6 +3,8 @@
#include <ngx_core.h>
#include <ngx_types.h>
#include <ngx_connection.h>
+#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_event_close.h>
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index f4222ccb7..4b5b83c83 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -1,7 +1,43 @@
+#include <ngx_config.h>
-void ngx_add_timer(ngx_event_t *ev, ngx_msec_t timer)
+#include <ngx_core.h>
+#include <ngx_log.h>
+#include <ngx_alloc.h>
+#include <ngx_connection.h>
+#include <ngx_event.h>
+
+#include <ngx_event_timer.h>
+
+/* STUB */
+#define NGX_TIMER_HASH_SIZE 5
+
+ngx_event_t *ngx_timer_queue;
+int ngx_timer_hash_size;
+
+
+int ngx_event_init_timer(ngx_log_t *log)
+{
+ int i;
+
+ ngx_timer_hash_size = NGX_TIMER_HASH_SIZE;
+
+ ngx_test_null(ngx_timer_queue,
+ ngx_alloc(ngx_timer_hash_size * sizeof(ngx_event_t), log),
+ NGX_ERROR);
+
+ for (i = 0; i < ngx_timer_hash_size; i++) {
+ ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
+ ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
+ }
+
+ return NGX_OK;
+}
+
+
+void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer)
{
+ int n;
ngx_event_t *e;
#if (NGX_DEBUG_EVENT)
@@ -16,8 +52,8 @@ void ngx_add_timer(ngx_event_t *ev, ngx_msec_t timer)
n = timer % ngx_timer_hash_size;
- for (e = timer_queue[n].timer_next;
- e != &timer_queue[n] && timer > e->timer_delta;
+ for (e = ngx_timer_queue[n].timer_next;
+ e != &ngx_timer_queue[n] && timer > e->timer_delta;
e = e->timer_next)
{
timer -= e->timer_delta;
diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h
new file mode 100644
index 000000000..27c301aab
--- /dev/null
+++ b/src/event/ngx_event_timer.h
@@ -0,0 +1,65 @@
+#ifndef _NGX_EVENT_TIMER_H_INCLUDED_
+#define _NGX_EVENT_TIMER_H_INCLUDED_
+
+
+#include <ngx_config.h>
+
+#include <ngx_log.h>
+#include <ngx_connection.h>
+#include <ngx_event.h>
+
+
+int ngx_event_init_timer(ngx_log_t *log);
+void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer);
+
+extern ngx_event_t *ngx_timer_queue;
+extern int ngx_timer_hash_size;
+
+
+ngx_inline static int ngx_event_get_timer()
+{
+ int i;
+ ngx_msec_t timer;
+
+ timer = NGX_MAX_MSEC;
+
+ for (i = 0; i < ngx_timer_hash_size; i++) {
+ if (ngx_timer_queue[i].timer_next != &ngx_timer_queue[i]) {
+ if (timer > ngx_timer_queue[i].timer_next->timer_delta) {
+ timer = ngx_timer_queue[i].timer_next->timer_delta;
+ }
+ }
+ }
+
+ if (timer == NGX_MAX_MSEC) {
+ return 0;
+ } else {
+ return timer;
+ }
+}
+
+
+ngx_inline static void ngx_event_del_timer(ngx_event_t *ev)
+{
+#if (NGX_DEBUG_EVENT)
+ /* STUB - we can not cast (ngx_connection_t *) here */
+ ngx_log_debug(ev->log, "del timer: %d" _ *(int *)(ev->data));
+#endif
+
+ if (ev->timer_prev) {
+ ev->timer_prev->timer_next = ev->timer_next;
+ }
+
+ if (ev->timer_next) {
+ ev->timer_next->timer_delta += ev->timer_delta;
+ ev->timer_next->timer_prev = ev->timer_prev;
+ ev->timer_next = NULL;
+ }
+
+ if (ev->timer_prev) {
+ ev->timer_prev = NULL;
+ }
+}
+
+
+#endif _NGX_EVENT_TIMER_H_INCLUDED_
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index c818b5a88..8d0596ab4 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -12,6 +12,8 @@
#include <ngx_connection.h>
#include <ngx_conf_file.h>
+/* STUB */
+#include <ngx_event_timer.h>
#define NGX_HTTP_VERSION_10 1000
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c
index 948b3f726..b30050561 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -9,6 +9,8 @@
#include <ngx_table.h>
#include <ngx_hunk.h>
#include <ngx_connection.h>
+#include <ngx_event.h>
+#include <ngx_event_timer.h>
#include <ngx_inet.h>
#include <ngx_http.h>
#include <ngx_http_config.h>
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index 5da536a49..fac71adf4 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -5,6 +5,7 @@
#include <ngx_config.h>
typedef u_int ngx_msec_t;
+#define NGX_MAX_MSEC ~0
typedef struct tm ngx_tm_t;
diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h
index 57bd421da..25eef9556 100644
--- a/src/os/win32/ngx_time.h
+++ b/src/os/win32/ngx_time.h
@@ -5,6 +5,8 @@
#include <windows.h>
typedef unsigned int ngx_msec_t;
+#define NGX_MAX_MSEC ~0
+
typedef SYSTEMTIME ngx_tm_t;
typedef FILETIME ngx_mtime_t;