mirror of
https://github.com/ChronosX88/psyced.git
synced 2024-11-08 19:41:00 +00:00
remove old queue
This commit is contained in:
parent
a3c6758bba
commit
6fcc4c7225
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -25,11 +25,7 @@
|
||||
// }}}
|
||||
|
||||
// {{{ queue-inherit
|
||||
#ifdef NEW_QUEUE
|
||||
inherit NET_PATH "queue2";
|
||||
#else
|
||||
inherit NET_PATH "queue";
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
// {{{ variables
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <net.h>
|
||||
#include <services.h>
|
||||
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.
|
||||
|
@ -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 <net.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user