From 6fcc4c7225266d541e629c20b4efd8919987856c Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Thu, 18 Nov 2010 13:15:38 +0100 Subject: [PATCH] remove old queue --- world/net/circuit.c | 4 - world/net/entity.c | 6 - world/net/http/fetch.c | 4 - world/net/include/net.h | 1 - world/net/library/dns.c | 4 - world/net/nntp/common.c | 2 +- world/net/queue.c | 275 ++++++++++++++++++---------------------- world/net/queue2.c | 166 ------------------------ 8 files changed, 125 insertions(+), 337 deletions(-) delete mode 100644 world/net/queue2.c diff --git a/world/net/circuit.c b/world/net/circuit.c index f3b65a1..d8495f0 100644 --- a/world/net/circuit.c +++ b/world/net/circuit.c @@ -44,11 +44,7 @@ volatile int retry; volatile int waitforme; volatile int time_of_connect_attempt; -#ifdef NEW_QUEUE -inherit NET_PATH "queue2"; -#else inherit NET_PATH "queue"; -#endif #if 0 //def PSYC_SYNCHRONIZE # define ISSYNC issync diff --git a/world/net/entity.c b/world/net/entity.c index 682abf5..0fbfc42 100644 --- a/world/net/entity.c +++ b/world/net/entity.c @@ -35,11 +35,7 @@ # define MAXIMUM_TRUST 10 #endif -#ifdef NEW_QUEUE -inherit NET_PATH "queue2"; -#else inherit NET_PATH "queue"; -#endif inherit NET_PATH "name"; inherit NET_PATH "storage"; #ifdef ENTITY_STATE //{{{ @@ -530,9 +526,7 @@ create() { _memory = ([ ]); temp = ([]); #endif //}}} -#ifdef NEW_QUEUE qCreate(); -#endif #ifdef TAGGING _tags = ([ ]); #endif diff --git a/world/net/http/fetch.c b/world/net/http/fetch.c index 0502524..47eeade 100644 --- a/world/net/http/fetch.c +++ b/world/net/http/fetch.c @@ -19,11 +19,7 @@ virtual inherit NET_PATH "output"; // virtual: in case we get inherited.. inherit NET_PATH "connect"; //inherit NET_PATH "place/master"; -#ifdef NEW_QUEUE -inherit NET_PATH "queue2"; -#else inherit NET_PATH "queue"; -#endif // additional headers. we keep them lower-case to ensure we have no // double items in there. HTTP ignores case by spec. diff --git a/world/net/include/net.h b/world/net/include/net.h index 38b013d..e11194a 100644 --- a/world/net/include/net.h +++ b/world/net/include/net.h @@ -206,7 +206,6 @@ # define MEMBERS_BY_SOURCE # define TAGGING # define TAGS_ONLY -# define NEW_QUEUE //# define CACHE_PRESENCE // gut gut.. dann testen wir diesen kram halt auch # define QUIET_REMOTE_MEMBERS diff --git a/world/net/library/dns.c b/world/net/library/dns.c index cd96d42..866b576 100644 --- a/world/net/library/dns.c +++ b/world/net/library/dns.c @@ -25,11 +25,7 @@ // }}} // {{{ queue-inherit -#ifdef NEW_QUEUE -inherit NET_PATH "queue2"; -#else inherit NET_PATH "queue"; -#endif // }}} // {{{ variables diff --git a/world/net/nntp/common.c b/world/net/nntp/common.c index 9da89a6..bd15e6a 100644 --- a/world/net/nntp/common.c +++ b/world/net/nntp/common.c @@ -1,7 +1,7 @@ #include #include inherit NET_PATH "connect"; -inherit NET_PATH "queue2"; +inherit NET_PATH "queue"; /* * this connects to a nntp server as client and does some fancy things. diff --git a/world/net/queue.c b/world/net/queue.c index d730bfd..c76415b 100644 --- a/world/net/queue.c +++ b/world/net/queue.c @@ -1,193 +1,166 @@ -// $Id: queue.c,v 1.40 2007/06/22 13:14:48 lynx Exp $ // vim:syntax=lpc +// $Id: queue.c,v 1.19 2008/03/29 20:05:32 lynx Exp $ // vim:syntax=lpc +// +// the *better* queue #include -#define Q_ARRAY 0 -#define Q_BEGIN 1 -#define Q_END 2 -#define Q_SIZE 3 -#define Q_RSIZE 4 -#define Q_MAX 5 +#define Q_TOP 0 +#define Q_BOTTOM 1 +#define Q_SIZE 2 +#define Q_MAX 3 +#define Q_WIDTH 4 -#define STEP 10 +//#define I_PRE 0 +#ifdef I_PRE +# define I_DATA 1 +# define I_NEXT 2 +#else +# define I_DATA 0 +# define I_NEXT 1 +#endif -#define push enqueue - -static int enqueue(mixed name, mixed item); -static varargs int qInit(mixed name, int max, int pre); -static mixed qExists(varargs mixed * names); -static mixed qSize(varargs mixed * names); -static mixed shift(mixed name); -static varargs int unshift(mixed name); -static int enlarge(mixed name); -// tell me: is there a reason for qRename being public? -public int qRename(mixed old, mixed new); -static int qDel(mixed name); - -volatile mapping q; // mapping containing queues +volatile mapping q; mapping qDebug() { return q; } -static varargs int qInit(mixed name, int max, int pre) { - unless(mappingp(q)) q = ([ ]); - if(q[name]) return 0; - q += ([ name : allocate(pre); 0; -1; 0; pre; max ]); - // name : array, bottom, top, q_size, r_size, max - return 1; +static varargs int qInit(mixed name, int max, int stinkt) { + if (member(q, name)) return 0; + q[name, Q_MAX] = max; + return 1; } static int enqueue(mixed name, mixed item) { - int number; - - P3(("enqueue %O: %O\n", name, item)) - if(q[name, Q_SIZE] == q[name, Q_MAX]) { - P1(("queue %O has reached maximum size when trying to add %O\n", - name, item)) - return 0; // maximum reached - } - // array needs to grow - if(q[name, Q_SIZE] == q[name, Q_RSIZE]) { - if(!enlarge(name)) { - D2(D("queue: enlarge failed!\n");) - return 0; - } - } - if(q[name, Q_END] + 1 == q[name, Q_RSIZE]) { - q[name, Q_END] = 0; - } else { - q[name, Q_END]++; - } - q[name, Q_ARRAY][q[name, Q_END]] = item; - q[name, Q_SIZE]++; + mixed *a, *n; -// D2(D("enqueue into "+to_string(name)+" Q_BEGIN:"+q[name, Q_BEGIN]+" into:"+q[name, Q_END]+"\n");) - return 1; -} - -static mixed qExists(varargs mixed * names) { - mixed name; - if (!mappingp(q)) return 0; - foreach (name : names) { - if(member(q, name)) return name; - } + P4(("queue:enqueue(%O.. in %O from %O\n", + name, ME, previous_object())) + if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) { + P1(("queue %O has reached maximum size (enqueue(%O))\n", name, item)) return 0; + } + +#ifdef I_PRE + n = allocate(3); +#else + n = allocate(2); +#endif + n[I_DATA] = item; + if (a = q[name, Q_BOTTOM]) { +#ifdef I_PRE + n[I_PRE] = a; +#endif + q[name, Q_BOTTOM] = a[I_NEXT] = n; + } else + q[name, Q_BOTTOM] = q[name, Q_TOP] = n; + + q[name, Q_SIZE]++; + + return 1; } -// should probably be renamed into qNotEmpty() or something -static mixed qSize(varargs mixed * names) { - mixed name; - if (!mappingp(q)) return 0; - if (sizeof(names) == 1) { - return q[names[0], Q_SIZE]; - } - foreach (name : names) { - if(member(q, name) && q[name, Q_SIZE]) return name; - } - return 0; +static mixed qExists(varargs mixed *names) { + foreach(mixed name : names) + if (member(q, name)) return name; + return 0; } -public int qRename(mixed old, mixed new) { - if(!q[old] || q[new]) return 0; - //q[new] = q[old]; - // that doesn't work.. ldmud bug? well, some keys (like size) weren't - // copied. therefore: - q += ([ new : q[old, Q_ARRAY]; q[old, Q_BEGIN]; q[old, Q_END]; - q[old, Q_SIZE]; q[old, Q_RSIZE]; q[old, Q_MAX] ]); - m_delete(q,old); - return 1; +static mixed qSize(varargs mixed *names) { + if (sizeof(names) == 1) { + return q[names[0], Q_SIZE]; + } + foreach (mixed name : names) + if (q[name, Q_SIZE]) return name; + return 0; } -static int qDel(mixed name) { - ASSERT("qDel (mappingp(q))", mappingp(q), q) - //if (mappingp(q)) - m_delete(q,name); - return 1; +static int qRename(mixed old, mixed new) { + if (!member(q, old) || member(q, new)) return 0; + q += ([ new : q[old, Q_TOP]; q[old, Q_BOTTOM]; q[old, Q_SIZE]; + q[old, Q_MAX] ]); + m_delete(q, old); + return 1; } static mixed shift(mixed name) { - // NEVER use shift whithout - // qSize before!! - int number; + mixed *a +#ifdef I_PRE + , *b +#endif + ; + + if (a = q[name, Q_TOP]) { + if (a[I_NEXT]) { +#ifdef I_PRE + q[name, Q_TOP] = b = a[I_NEXT]; + b[I_PRE] = 0; +#else + q[name, Q_TOP] = a[I_NEXT]; +#endif + } else + q[name, Q_TOP] = q[name, Q_BOTTOM] = 0; q[name, Q_SIZE]--; - - number = q[name, Q_BEGIN]; - if((q[name, Q_BEGIN] + 1) == q[name, Q_RSIZE]) { - q[name, Q_BEGIN] = 0; - } else { - q[name, Q_BEGIN]++; - } -// D2(D("shift from "+to_string(name)+" Q_BEGIN: " + q[name, Q_BEGIN] + " from:"+number+"\n");) - return q[name, Q_ARRAY][number]; + return a[I_DATA]; + } + return 0; } -static varargs int unshift(mixed name, mixed item) { -// D2(D("unshift Q_BEGIN:" + q[name, Q_BEGIN]+"\n");) - if(q[name, Q_RSIZE] == q[name, Q_SIZE]) { - if(!enlarge( name )) { - return 0; - } - } - if(q[name, Q_BEGIN] == 0) { - q[name, Q_BEGIN] = q[name, Q_RSIZE] - 1; - } else { - q[name, Q_BEGIN]--; - } - if(item) - q[name, Q_ARRAY][q[name, Q_BEGIN]] = item; - q[name, Q_SIZE]++; - return 1; +static int unshift(mixed name, mixed item) { + mixed *a, *n; + + if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) { + P1(("queue %O has maximum size (unshift(%O))\n", name, item)) + return 0; + } + +#ifdef I_PRE + n = allocate(3); +#else + n = allocate(2); +#endif + n[I_DATA] = item; + + if (a = q[name, Q_TOP]) { + n[I_NEXT] = a; +#ifdef I_PRE + q[name, Q_TOP] = a[I_PRE] = n; +#else + q[name, Q_TOP] = n; +#endif + } else + q[name, Q_TOP] = q[name, Q_BOTTOM] = n; + + q[name, Q_SIZE]++; + + return 1; } -static int enlarge(mixed name) { - int step; - - // das will ich mir doch mal näher ansehen.. - P1(("%O queue enlarge for %O\n", ME, name)) - if((q[name, Q_RSIZE] + STEP) > q[name, Q_MAX]) { - step = q[name, Q_MAX] - q[name, Q_RSIZE]; - } else { - step = STEP; - } - if(step == 0) - return 0; - if(q[name, Q_END] < q[name, Q_BEGIN]) { - q[name, Q_ARRAY] = q[name, Q_ARRAY][q[name, Q_BEGIN]..] + q[name, Q_ARRAY][0..q[name, Q_END]] + allocate(step); - q[name, Q_BEGIN] = 0; - q[name, Q_END] = q[name, Q_SIZE] - 1; - q[name, Q_RSIZE] += step; - return 1; - } else { - q[name, Q_ARRAY] = q[name, Q_ARRAY][q[name, Q_BEGIN]..q[name, Q_END]] + allocate(step); - - q[name, Q_BEGIN] = 0; - q[name, Q_END] = q[name, Q_SIZE] - 1; - q[name, Q_RSIZE] += step; - return 1; - } +static int qDel(mixed name) { + ASSERT("qDel (mappingp(q))", mappingp(q), q) + m_delete(q, name); + return 1; } -static void qCreate() { - unless (mappingp(q) && widthof(q) == 1) q = ([]); +static mapping qCreate() { + unless (mappingp(q) && widthof(q) == Q_WIDTH) q = m_allocate(0, Q_WIDTH); + P3(("qCreate in %O produces %O (%O)\n", ME, q, widthof(q))) + return q; } -// for compatibility to queue2, won't give performance boosts for -// array-append-like operations as queue2 (most probably) does static mixed *qToArray(mixed name) { - mixed *tmp, *qarr; - int max, cur, mod; + mixed *tmp, *cur; + int max; ASSERT("qToArray (mappingp(q))", mappingp(q), q) unless (member(q, name)) return 0; tmp = allocate(max = q[name, Q_SIZE]); - qarr = q[name, Q_ARRAY]; - cur = q[name, Q_BEGIN]; - mod = q[name, Q_RSIZE]; + + cur = q[name]; for (int i = 0; i < max; i++) { - tmp[i] = qarr[cur++]; - cur %= mod; + tmp[i] = cur[I_DATA]; + cur = cur[I_NEXT]; } - + return tmp; } diff --git a/world/net/queue2.c b/world/net/queue2.c deleted file mode 100644 index d8296ca..0000000 --- a/world/net/queue2.c +++ /dev/null @@ -1,166 +0,0 @@ -// $Id: queue2.c,v 1.19 2008/03/29 20:05:32 lynx Exp $ // vim:syntax=lpc -// -// the *better* queue - -#include - -#define Q_TOP 0 -#define Q_BOTTOM 1 -#define Q_SIZE 2 -#define Q_MAX 3 -#define Q_WIDTH 4 - -//#define I_PRE 0 -#ifdef I_PRE -# define I_DATA 1 -# define I_NEXT 2 -#else -# define I_DATA 0 -# define I_NEXT 1 -#endif - -volatile mapping q; - -mapping qDebug() { return q; } - -static varargs int qInit(mixed name, int max, int stinkt) { - if (member(q, name)) return 0; - q[name, Q_MAX] = max; - return 1; -} - -static int enqueue(mixed name, mixed item) { - mixed *a, *n; - - P4(("queue2:enqueue(%O.. in %O from %O\n", - name, ME, previous_object())) - if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) { - P1(("queue %O has reached maximum size (enqueue(%O))\n", name, item)) - return 0; - } - -#ifdef I_PRE - n = allocate(3); -#else - n = allocate(2); -#endif - n[I_DATA] = item; - if (a = q[name, Q_BOTTOM]) { -#ifdef I_PRE - n[I_PRE] = a; -#endif - q[name, Q_BOTTOM] = a[I_NEXT] = n; - } else - q[name, Q_BOTTOM] = q[name, Q_TOP] = n; - - q[name, Q_SIZE]++; - - return 1; -} - -static mixed qExists(varargs mixed *names) { - foreach(mixed name : names) - if (member(q, name)) return name; - return 0; -} - -static mixed qSize(varargs mixed *names) { - if (sizeof(names) == 1) { - return q[names[0], Q_SIZE]; - } - foreach (mixed name : names) - if (q[name, Q_SIZE]) return name; - return 0; -} - -static int qRename(mixed old, mixed new) { - if (!member(q, old) || member(q, new)) return 0; - q += ([ new : q[old, Q_TOP]; q[old, Q_BOTTOM]; q[old, Q_SIZE]; - q[old, Q_MAX] ]); - m_delete(q, old); - return 1; -} - -static mixed shift(mixed name) { - mixed *a -#ifdef I_PRE - , *b -#endif - ; - - if (a = q[name, Q_TOP]) { - if (a[I_NEXT]) { -#ifdef I_PRE - q[name, Q_TOP] = b = a[I_NEXT]; - b[I_PRE] = 0; -#else - q[name, Q_TOP] = a[I_NEXT]; -#endif - } else - q[name, Q_TOP] = q[name, Q_BOTTOM] = 0; - q[name, Q_SIZE]--; - return a[I_DATA]; - } - return 0; -} - -static int unshift(mixed name, mixed item) { - mixed *a, *n; - - if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) { - P1(("queue %O has maximum size (unshift(%O))\n", name, item)) - return 0; - } - -#ifdef I_PRE - n = allocate(3); -#else - n = allocate(2); -#endif - n[I_DATA] = item; - - if (a = q[name, Q_TOP]) { - n[I_NEXT] = a; -#ifdef I_PRE - q[name, Q_TOP] = a[I_PRE] = n; -#else - q[name, Q_TOP] = n; -#endif - } else - q[name, Q_TOP] = q[name, Q_BOTTOM] = n; - - q[name, Q_SIZE]++; - - return 1; -} - -static int qDel(mixed name) { - ASSERT("qDel (mappingp(q))", mappingp(q), q) - m_delete(q, name); - return 1; -} - -static mapping qCreate() { - unless (mappingp(q) && widthof(q) == Q_WIDTH) q = m_allocate(0, Q_WIDTH); - P3(("qCreate in %O produces %O (%O)\n", ME, q, widthof(q))) - return q; -} - -static mixed *qToArray(mixed name) { - mixed *tmp, *cur; - int max; - - ASSERT("qToArray (mappingp(q))", mappingp(q), q) - unless (member(q, name)) return 0; - - tmp = allocate(max = q[name, Q_SIZE]); - - cur = q[name]; - - for (int i = 0; i < max; i++) { - tmp[i] = cur[I_DATA]; - cur = cur[I_NEXT]; - } - - return tmp; -}