diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-06-04 14:21:58 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-06-04 14:22:03 +0400 |
commit | a7820a15e7eb4e57a4fe2f076e877dcc6069358c (patch) | |
tree | 47e6ba0c43a76064642415944ec981b8194bfa2e /src | |
parent | 72b92e92d39fa8c513d4166c1f0feed48241aac7 (diff) |
src: replace ngx-queue.h with queue.h
No functional changes, just one less entry in the LICENSE file.
Diffstat (limited to 'src')
-rw-r--r-- | src/handle_wrap.cc | 8 | ||||
-rw-r--r-- | src/handle_wrap.h | 4 | ||||
-rw-r--r-- | src/ngx-queue.h | 106 | ||||
-rw-r--r-- | src/node.cc | 12 | ||||
-rw-r--r-- | src/queue.h | 92 | ||||
-rw-r--r-- | src/req_wrap.h | 10 |
6 files changed, 109 insertions, 123 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 390f6864250..5de0daa0d24 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. #include "node.h" -#include "ngx-queue.h" +#include "queue.h" #include "handle_wrap.h" namespace node { @@ -43,7 +43,7 @@ using v8::Value; // defined in node.cc -extern ngx_queue_t handle_wrap_queue; +extern QUEUE handle_wrap_queue; static Persistent<String> close_sym; @@ -115,13 +115,13 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) { assert(object->InternalFieldCount() > 0); object_ = v8::Persistent<v8::Object>::New(node_isolate, object); object_->SetAlignedPointerInInternalField(0, this); - ngx_queue_insert_tail(&handle_wrap_queue, &handle_wrap_queue_); + QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_); } HandleWrap::~HandleWrap() { assert(object_.IsEmpty()); - ngx_queue_remove(&handle_wrap_queue_); + QUEUE_REMOVE(&handle_wrap_queue_); } diff --git a/src/handle_wrap.h b/src/handle_wrap.h index d77485cdf6f..3a42148a626 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -22,7 +22,7 @@ #ifndef HANDLE_WRAP_H_ #define HANDLE_WRAP_H_ -#include "ngx-queue.h" +#include "queue.h" namespace node { @@ -70,7 +70,7 @@ class HandleWrap { private: friend v8::Handle<v8::Value> GetActiveHandles(const v8::Arguments&); static void OnClose(uv_handle_t* handle); - ngx_queue_t handle_wrap_queue_; + QUEUE handle_wrap_queue_; // Using double underscore due to handle_ member in tcp_wrap. Probably // tcp_wrap should rename it's member to 'handle'. uv_handle_t* handle__; diff --git a/src/ngx-queue.h b/src/ngx-queue.h deleted file mode 100644 index 7058ce408d8..00000000000 --- a/src/ngx-queue.h +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - */ - - -#ifndef NGX_QUEUE_H_INCLUDED_ -#define NGX_QUEUE_H_INCLUDED_ - - -typedef struct ngx_queue_s ngx_queue_t; - -struct ngx_queue_s { - ngx_queue_t *prev; - ngx_queue_t *next; -}; - - -#define ngx_queue_init(q) \ - (q)->prev = q; \ - (q)->next = q - - -#define ngx_queue_empty(h) \ - (h == (h)->prev) - - -#define ngx_queue_insert_head(h, x) \ - (x)->next = (h)->next; \ - (x)->next->prev = x; \ - (x)->prev = h; \ - (h)->next = x - - -#define ngx_queue_insert_after ngx_queue_insert_head - - -#define ngx_queue_insert_tail(h, x) \ - (x)->prev = (h)->prev; \ - (x)->prev->next = x; \ - (x)->next = h; \ - (h)->prev = x - - -#define ngx_queue_head(h) \ - (h)->next - - -#define ngx_queue_last(h) \ - (h)->prev - - -#define ngx_queue_sentinel(h) \ - (h) - - -#define ngx_queue_next(q) \ - (q)->next - - -#define ngx_queue_prev(q) \ - (q)->prev - - -#if (NGX_DEBUG) - -#define ngx_queue_remove(x) \ - (x)->next->prev = (x)->prev; \ - (x)->prev->next = (x)->next; \ - (x)->prev = NULL; \ - (x)->next = NULL - -#else - -#define ngx_queue_remove(x) \ - (x)->next->prev = (x)->prev; \ - (x)->prev->next = (x)->next - -#endif - - -#define ngx_queue_split(h, q, n) \ - (n)->prev = (h)->prev; \ - (n)->prev->next = n; \ - (n)->next = q; \ - (h)->prev = (q)->prev; \ - (h)->prev->next = h; \ - (q)->prev = n; - - -#define ngx_queue_add(h, n) \ - (h)->prev->next = (n)->next; \ - (n)->next->prev = (h)->prev; \ - (h)->prev = (n)->prev; \ - (h)->prev->next = h; - - -#define ngx_queue_data(q, type, link) \ - (type *) ((unsigned char *) q - offsetof(type, link)) - - -#define ngx_queue_foreach(q, h) \ - for ((q) = ngx_queue_head(h); (q) != (h); (q) = ngx_queue_next(q)) - - -#endif /* NGX_QUEUE_H_INCLUDED_ */ diff --git a/src/node.cc b/src/node.cc index 461ecf4777b..ee364bd3a68 100644 --- a/src/node.cc +++ b/src/node.cc @@ -93,8 +93,8 @@ extern char **environ; namespace node { -ngx_queue_t handle_wrap_queue = { &handle_wrap_queue, &handle_wrap_queue }; -ngx_queue_t req_wrap_queue = { &req_wrap_queue, &req_wrap_queue }; +QUEUE handle_wrap_queue = { &handle_wrap_queue, &handle_wrap_queue }; +QUEUE req_wrap_queue = { &req_wrap_queue, &req_wrap_queue }; // declared in req_wrap.h Persistent<String> process_symbol; @@ -1249,10 +1249,10 @@ static Handle<Value> GetActiveRequests(const Arguments& args) { HandleScope scope(node_isolate); Local<Array> ary = Array::New(); - ngx_queue_t* q = NULL; + QUEUE* q = NULL; int i = 0; - ngx_queue_foreach(q, &req_wrap_queue) { + QUEUE_FOREACH(q, &req_wrap_queue) { ReqWrap<uv_req_t>* w = container_of(q, ReqWrap<uv_req_t>, req_wrap_queue_); if (w->object_.IsEmpty()) continue; ary->Set(i++, w->object_); @@ -1268,12 +1268,12 @@ Handle<Value> GetActiveHandles(const Arguments& args) { HandleScope scope(node_isolate); Local<Array> ary = Array::New(); - ngx_queue_t* q = NULL; + QUEUE* q = NULL; int i = 0; Local<String> owner_sym = String::New("owner"); - ngx_queue_foreach(q, &handle_wrap_queue) { + QUEUE_FOREACH(q, &handle_wrap_queue) { HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_); if (w->object_.IsEmpty() || (w->flags_ & HandleWrap::kUnref)) continue; Local<Value> obj = w->object_->Get(owner_sym); diff --git a/src/queue.h b/src/queue.h new file mode 100644 index 00000000000..0a3783b9f13 --- /dev/null +++ b/src/queue.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef QUEUE_H_ +#define QUEUE_H_ + +typedef void *QUEUE[2]; + +/* Private macros. */ +#define QUEUE_NEXT(q) ((*(q))[0]) +#define QUEUE_PREV(q) ((*(q))[1]) +#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT((QUEUE *) QUEUE_PREV(q))) +#define QUEUE_NEXT_PREV(q) (QUEUE_PREV((QUEUE *) QUEUE_NEXT(q))) + +/* Public macros. */ +#define QUEUE_DATA(ptr, type, field) \ + ((type *) ((char *) (ptr) - ((long) &((type *) 0)->field))) + +#define QUEUE_FOREACH(q, h) \ + for ((q) = (QUEUE *) (*(h))[0]; (q) != (h); (q) = (QUEUE *) (*(q))[0]) + +#define QUEUE_EMPTY(q) \ + (QUEUE_NEXT(q) == (q)) + +#define QUEUE_HEAD(q) \ + (QUEUE_NEXT(q)) + +#define QUEUE_INIT(q) \ + do { \ + QUEUE_NEXT(q) = (q); \ + QUEUE_PREV(q) = (q); \ + } \ + while (0) + +#define QUEUE_ADD(h, n) \ + do { \ + QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \ + QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \ + QUEUE_PREV(h) = QUEUE_PREV(n); \ + QUEUE_PREV_NEXT(h) = (h); \ + } \ + while (0) + +#define QUEUE_SPLIT(h, q, n) \ + do { \ + QUEUE_PREV(n) = QUEUE_PREV(h); \ + QUEUE_PREV_NEXT(n) = (n); \ + QUEUE_NEXT(n) = (q); \ + QUEUE_PREV(h) = QUEUE_PREV(q); \ + QUEUE_PREV_NEXT(h) = (h); \ + QUEUE_PREV(q) = (n); \ + } \ + while (0) + +#define QUEUE_INSERT_HEAD(h, q) \ + do { \ + QUEUE_NEXT(q) = QUEUE_NEXT(h); \ + QUEUE_PREV(q) = (h); \ + QUEUE_NEXT_PREV(q) = (q); \ + QUEUE_NEXT(h) = (q); \ + } \ + while (0) + +#define QUEUE_INSERT_TAIL(h, q) \ + do { \ + QUEUE_NEXT(q) = (h); \ + QUEUE_PREV(q) = QUEUE_PREV(h); \ + QUEUE_PREV_NEXT(q) = (q); \ + QUEUE_PREV(h) = (q); \ + } \ + while (0) + +#define QUEUE_REMOVE(q) \ + do { \ + QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \ + QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \ + } \ + while (0) + +#endif /* QUEUE_H_ */ diff --git a/src/req_wrap.h b/src/req_wrap.h index 587111b415c..60e4184d56c 100644 --- a/src/req_wrap.h +++ b/src/req_wrap.h @@ -22,7 +22,7 @@ #ifndef REQ_WRAP_H_ #define REQ_WRAP_H_ -#include "ngx-queue.h" +#include "queue.h" #include "node_internals.h" namespace node { @@ -30,7 +30,7 @@ namespace node { // defined in node.cc extern v8::Persistent<v8::String> process_symbol; extern v8::Persistent<v8::String> domain_symbol; -extern ngx_queue_t req_wrap_queue; +extern QUEUE req_wrap_queue; template <typename T> class ReqWrap { @@ -51,12 +51,12 @@ class ReqWrap { } } - ngx_queue_insert_tail(&req_wrap_queue, &req_wrap_queue_); + QUEUE_INSERT_TAIL(&req_wrap_queue, &req_wrap_queue_); } ~ReqWrap() { - ngx_queue_remove(&req_wrap_queue_); + QUEUE_REMOVE(&req_wrap_queue_); // Assert that someone has called Dispatched() assert(req_.data == this); assert(!object_.IsEmpty()); @@ -70,7 +70,7 @@ class ReqWrap { } v8::Persistent<v8::Object> object_; - ngx_queue_t req_wrap_queue_; + QUEUE req_wrap_queue_; void* data_; T req_; // *must* be last, GetActiveRequests() in node.cc depends on it }; |