remove old queue

This commit is contained in:
psyc://psyced.org/~lynX 2010-11-18 13:15:38 +01:00
parent a3c6758bba
commit 6fcc4c7225
8 changed files with 125 additions and 337 deletions

View File

@ -44,11 +44,7 @@ volatile int retry;
volatile int waitforme; volatile int waitforme;
volatile int time_of_connect_attempt; volatile int time_of_connect_attempt;
#ifdef NEW_QUEUE
inherit NET_PATH "queue2";
#else
inherit NET_PATH "queue"; inherit NET_PATH "queue";
#endif
#if 0 //def PSYC_SYNCHRONIZE #if 0 //def PSYC_SYNCHRONIZE
# define ISSYNC issync # define ISSYNC issync

View File

@ -35,11 +35,7 @@
# define MAXIMUM_TRUST 10 # define MAXIMUM_TRUST 10
#endif #endif
#ifdef NEW_QUEUE
inherit NET_PATH "queue2";
#else
inherit NET_PATH "queue"; inherit NET_PATH "queue";
#endif
inherit NET_PATH "name"; inherit NET_PATH "name";
inherit NET_PATH "storage"; inherit NET_PATH "storage";
#ifdef ENTITY_STATE //{{{ #ifdef ENTITY_STATE //{{{
@ -530,9 +526,7 @@ create() {
_memory = ([ ]); _memory = ([ ]);
temp = ([]); temp = ([]);
#endif //}}} #endif //}}}
#ifdef NEW_QUEUE
qCreate(); qCreate();
#endif
#ifdef TAGGING #ifdef TAGGING
_tags = ([ ]); _tags = ([ ]);
#endif #endif

View File

@ -19,11 +19,7 @@ virtual inherit NET_PATH "output"; // virtual: in case we get inherited..
inherit NET_PATH "connect"; inherit NET_PATH "connect";
//inherit NET_PATH "place/master"; //inherit NET_PATH "place/master";
#ifdef NEW_QUEUE
inherit NET_PATH "queue2";
#else
inherit NET_PATH "queue"; inherit NET_PATH "queue";
#endif
// additional headers. we keep them lower-case to ensure we have no // additional headers. we keep them lower-case to ensure we have no
// double items in there. HTTP ignores case by spec. // double items in there. HTTP ignores case by spec.

View File

@ -206,7 +206,6 @@
# define MEMBERS_BY_SOURCE # define MEMBERS_BY_SOURCE
# define TAGGING # define TAGGING
# define TAGS_ONLY # define TAGS_ONLY
# define NEW_QUEUE
//# define CACHE_PRESENCE //# define CACHE_PRESENCE
// gut gut.. dann testen wir diesen kram halt auch // gut gut.. dann testen wir diesen kram halt auch
# define QUIET_REMOTE_MEMBERS # define QUIET_REMOTE_MEMBERS

View File

@ -25,11 +25,7 @@
// }}} // }}}
// {{{ queue-inherit // {{{ queue-inherit
#ifdef NEW_QUEUE
inherit NET_PATH "queue2";
#else
inherit NET_PATH "queue"; inherit NET_PATH "queue";
#endif
// }}} // }}}
// {{{ variables // {{{ variables

View File

@ -1,7 +1,7 @@
#include <net.h> #include <net.h>
#include <services.h> #include <services.h>
inherit NET_PATH "connect"; 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. * this connects to a nntp server as client and does some fancy things.

View File

@ -1,192 +1,165 @@
// $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 <net.h> #include <net.h>
#define Q_ARRAY 0 #define Q_TOP 0
#define Q_BEGIN 1 #define Q_BOTTOM 1
#define Q_END 2 #define Q_SIZE 2
#define Q_SIZE 3 #define Q_MAX 3
#define Q_RSIZE 4 #define Q_WIDTH 4
#define Q_MAX 5
#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 volatile mapping q;
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
mapping qDebug() { return q; } mapping qDebug() { return q; }
static varargs int qInit(mixed name, int max, int pre) { static varargs int qInit(mixed name, int max, int stinkt) {
unless(mappingp(q)) q = ([ ]); if (member(q, name)) return 0;
if(q[name]) return 0; q[name, Q_MAX] = max;
q += ([ name : allocate(pre); 0; -1; 0; pre; max ]); return 1;
// name : array, bottom, top, q_size, r_size, max
return 1;
} }
static int enqueue(mixed name, mixed item) { static int enqueue(mixed name, mixed item) {
int number; mixed *a, *n;
P3(("enqueue %O: %O\n", name, item)) P4(("queue:enqueue(%O.. in %O from %O\n",
if(q[name, Q_SIZE] == q[name, Q_MAX]) { name, ME, previous_object()))
P1(("queue %O has reached maximum size when trying to add %O\n", if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) {
name, item)) P1(("queue %O has reached maximum size (enqueue(%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]++;
// 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;
}
return 0; 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 qExists(varargs mixed *names) {
static mixed qSize(varargs mixed * names) { foreach(mixed name : names)
mixed name; if (member(q, name)) return name;
if (!mappingp(q)) return 0; 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;
} }
public int qRename(mixed old, mixed new) { static mixed qSize(varargs mixed *names) {
if(!q[old] || q[new]) return 0; if (sizeof(names) == 1) {
//q[new] = q[old]; return q[names[0], Q_SIZE];
// that doesn't work.. ldmud bug? well, some keys (like size) weren't }
// copied. therefore: foreach (mixed name : names)
q += ([ new : q[old, Q_ARRAY]; q[old, Q_BEGIN]; q[old, Q_END]; if (q[name, Q_SIZE]) return name;
q[old, Q_SIZE]; q[old, Q_RSIZE]; q[old, Q_MAX] ]); return 0;
m_delete(q,old);
return 1;
} }
static int qDel(mixed name) { static int qRename(mixed old, mixed new) {
ASSERT("qDel (mappingp(q))", mappingp(q), q) if (!member(q, old) || member(q, new)) return 0;
//if (mappingp(q)) q += ([ new : q[old, Q_TOP]; q[old, Q_BOTTOM]; q[old, Q_SIZE];
m_delete(q,name); q[old, Q_MAX] ]);
return 1; m_delete(q, old);
return 1;
} }
static mixed shift(mixed name) { static mixed shift(mixed name) {
// NEVER use shift whithout mixed *a
// qSize before!! #ifdef I_PRE
int number; , *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]--; q[name, Q_SIZE]--;
return a[I_DATA];
number = q[name, Q_BEGIN]; }
if((q[name, Q_BEGIN] + 1) == q[name, Q_RSIZE]) { return 0;
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];
} }
static varargs int unshift(mixed name, mixed item) { static int unshift(mixed name, mixed item) {
// D2(D("unshift Q_BEGIN:" + q[name, Q_BEGIN]+"\n");) mixed *a, *n;
if(q[name, Q_RSIZE] == q[name, Q_SIZE]) {
if(!enlarge( name )) { if (q[name, Q_MAX] && (q[name, Q_SIZE] == q[name, Q_MAX])) {
return 0; P1(("queue %O has maximum size (unshift(%O))\n", name, item))
} return 0;
} }
if(q[name, Q_BEGIN] == 0) {
q[name, Q_BEGIN] = q[name, Q_RSIZE] - 1; #ifdef I_PRE
} else { n = allocate(3);
q[name, Q_BEGIN]--; #else
} n = allocate(2);
if(item) #endif
q[name, Q_ARRAY][q[name, Q_BEGIN]] = item; n[I_DATA] = item;
q[name, Q_SIZE]++;
return 1; 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) { static int qDel(mixed name) {
int step; ASSERT("qDel (mappingp(q))", mappingp(q), q)
m_delete(q, name);
// das will ich mir doch mal näher ansehen.. return 1;
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 void qCreate() { static mapping qCreate() {
unless (mappingp(q) && widthof(q) == 1) q = ([]); 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) { static mixed *qToArray(mixed name) {
mixed *tmp, *qarr; mixed *tmp, *cur;
int max, cur, mod; int max;
ASSERT("qToArray (mappingp(q))", mappingp(q), q) ASSERT("qToArray (mappingp(q))", mappingp(q), q)
unless (member(q, name)) return 0; unless (member(q, name)) return 0;
tmp = allocate(max = q[name, Q_SIZE]); tmp = allocate(max = q[name, Q_SIZE]);
qarr = q[name, Q_ARRAY];
cur = q[name, Q_BEGIN]; cur = q[name];
mod = q[name, Q_RSIZE];
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
tmp[i] = qarr[cur++]; tmp[i] = cur[I_DATA];
cur %= mod; cur = cur[I_NEXT];
} }
return tmp; return tmp;

View File

@ -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 <net.h>
#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;
}