summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-26 04:14:25 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-02-26 04:14:25 +0800
commit3b64a185e87fdfd39db71bca063b6efb0c7ec92e (patch)
tree8678540a15b6a541d21f176ab46dbeb48d6cdfde /mbbsd
parent58490fa9b998ccd714de75f48a9c1eb5f914995d (diff)
downloadpttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar.gz
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar.bz2
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar.lz
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar.xz
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.tar.zst
pttbbs-3b64a185e87fdfd39db71bca063b6efb0c7ec92e.zip
* use fnv hash function for all hash.
* add version field in SHM. * clean up & reorder SHM, add gaps between arrays. * enlarge USHM_SIZE. * remove unused shmsweep.c. * WARNING, you need to stop bbs and clean old shm before run this revision. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2549 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/cache.c30
-rw-r--r--mbbsd/cal.c13
-rw-r--r--mbbsd/read.c1
-rw-r--r--mbbsd/stuff.c8
-rw-r--r--mbbsd/var.c1
-rw-r--r--mbbsd/xyz.c14
6 files changed, 30 insertions, 37 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 469acc46..4345e282 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -65,6 +65,12 @@ void
attach_SHM(void)
{
SHM = attach_shm(SHM_KEY, sizeof(SHM_t));
+ if(SHM->version != SHM_VERSION) {
+ fprintf(stderr, "Error: SHM->version(%d) != SHM_VERSION(%d)\n", SHM->version, SHM_VERSION);
+ fprintf(stderr, "Please use the source code version corresponding to SHM,\n"
+ "or use ipcrm(1) command to clean share memory.\n");
+ exit(1);
+ }
if (!SHM->loaded) /* (uhash) assume fresh shared memory is
* zeroed */
exit(1);
@@ -73,7 +79,6 @@ attach_SHM(void)
bcache = SHM->bcache;
numboards = SHM->Bnumber;
- GLOBALVAR = SHM->GLOBALVAR;
if (SHM->Ptouchtime == 0)
SHM->Ptouchtime = 1;
@@ -142,9 +147,12 @@ sem_lock(int op, int semid)
void
add_to_uhash(int n, char *id)
{
- int *p, h = StringHash(id);
+ int *p, h = StringHash(id)%(1<<HASH_BITS);
int times;
strlcpy(SHM->userid[n], id, sizeof(SHM->userid[n]));
+#if (1<<HASH_BITS)*2 < MAX_USERS
+#error "HASH_BITS too small"
+#endif
p = &(SHM->hash_head[h]);
@@ -164,7 +172,7 @@ remove_from_uhash(int n)
* note: after remove_from_uhash(), you should add_to_uhash() (likely with a
* different name)
*/
- int h = StringHash(SHM->userid[n]);
+ int h = StringHash(SHM->userid[n])%(1<<HASH_BITS);
int *p = &(SHM->hash_head[h]);
int times;
@@ -182,7 +190,7 @@ int
searchuser(char *userid)
{
int h, p, times;
- h = StringHash(userid);
+ h = StringHash(userid)%(1<<HASH_BITS);
p = SHM->hash_head[h];
for (times = 0; times < MAX_USERS && p != -1 && p < MAX_USERS ; ++times) {
@@ -265,9 +273,10 @@ void
getnewutmpent(userinfo_t * up)
{
/* Ptt:這裡加上 hash 觀念找空的 utmp */
- register int i, p;
+ register int i;
register userinfo_t *uentp;
- for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) {
+ unsigned int p = StringHash(up->userid) % USHM_SIZE;
+ for (i = 0; i < USHM_SIZE; i++, p++) {
if (p == USHM_SIZE)
p = 0;
uentp = &(SHM->uinfo[p]);
@@ -1000,7 +1009,7 @@ hbflreload(int bid)
fclose(fp);
}
hbfl[0] = COMMON_TIME;
- memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); // FIXME bid-1 ?
+ memcpy(SHM->hbfl[bid-1], hbfl, sizeof(hbfl));
}
/* 是否"不"通過板友測試. 如果在板友名單中的話傳回 0, 否則為 1 */
@@ -1009,11 +1018,10 @@ hbflcheck(int bid, int uid)
{
int i;
- // FIXME bid-1?
- if (SHM->hbfl[bid][0] < login_start_time - HBFLexpire)
+ if (SHM->hbfl[bid-1][0] < login_start_time - HBFLexpire)
hbflreload(bid);
- for (i = 1; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND; ++i) {
- if (SHM->hbfl[bid][i] == uid)
+ for (i = 1; SHM->hbfl[bid-1][i] != 0 && i <= MAX_FRIEND; ++i) {
+ if (SHM->hbfl[bid-1][i] == uid)
return 0;
}
return 1;
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index 1c997836..d0fb17b3 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -3,18 +3,21 @@
/* 防堵 Multi play */
static int
-count_multiplay(int unmode)
+is_playing(int unmode)
{
register int i, j;
register userinfo_t *uentp;
+ unsigned int p = StringHash(cuser.userid) % USHM_SIZE;
for (i = j = 0; i < USHM_SIZE; i++) { // XXX linear search
- uentp = &(SHM->uinfo[i]);
+ if (p == USHM_SIZE)
+ p = 0;
+ uentp = &(SHM->uinfo[p]);
if (uentp->uid == usernum)
if (uentp->lockmode == unmode)
- j++;
+ return 1;
}
- return j;
+ return 0;
}
int
@@ -24,7 +27,7 @@ lockutmpmode(int unmode, int state)
if (currutmp->lockmode)
errorno = 1;
- else if (count_multiplay(unmode))
+ else if (is_playing(unmode))
errorno = 2;
if (errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) {
diff --git a/mbbsd/read.c b/mbbsd/read.c
index 58a8678f..cf471688 100644
--- a/mbbsd/read.c
+++ b/mbbsd/read.c
@@ -208,6 +208,7 @@ getkeep(char *s, int def_topline, int def_cursline)
* 一方面 size 小, malloc space overhead 就高, 因此改成 link block,
* 以 KEEPSLOT 為一個 block 的 link list.
* 只有第一個 block 可能沒滿. */
+ /* TODO LRU recycle? 麻煩在於別處可能把 keeploc_t pointer 記著... */
#define KEEPSLOT 10
struct keepsome {
unsigned char used;
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 2ea16fec..3d3b90f8 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -1,5 +1,6 @@
/* $Id$ */
#include "bbs.h"
+#include "fnv_hash.h"
/* ----------------------------------------------------- */
/* set file path for boards/user home */
@@ -895,12 +896,7 @@ void FREE(void *ptr)
unsigned
StringHash(unsigned char *s)
{
- unsigned int v = 0;
- while (*s) {
- v = (v << 8) | (v >> 24);
- v ^= toupper(*s++); /* note this is case insensitive */
- }
- return (v * 2654435769U) >> (32 - HASH_BITS);
+ return fnv1a_32_strcase(s, FNV1_32_INIT);
}
inline int *intbsearch(int key, int *base0, int nmemb)
diff --git a/mbbsd/var.c b/mbbsd/var.c
index ff880155..95cdad2e 100644
--- a/mbbsd/var.c
+++ b/mbbsd/var.c
@@ -356,7 +356,6 @@ int wmofo = NOTREPLYING;
/* cache.c */
int numboards = -1;
-int *GLOBALVAR;
SHM_t *SHM;
boardheader_t *bcache;
userinfo_t *currutmp;
diff --git a/mbbsd/xyz.c b/mbbsd/xyz.c
index b757392d..003f5a51 100644
--- a/mbbsd/xyz.c
+++ b/mbbsd/xyz.c
@@ -335,19 +335,6 @@ m_sysop()
return 0;
}
-void
-log_memoryusage(void)
-{
-#ifdef IA32
- int use=((int)sbrk(0)-0x8048000)/1024;
- if(use<500)
- use=499;
- if(use>1000)
- use=1000;
- GLOBALVAR[use/100-4]++; // use [0]~[6]
-#endif
-}
-
int
Goodbye()
{
@@ -369,7 +356,6 @@ Goodbye()
else if (genbuf[0] == 'n')
note();
}
- log_memoryusage();
clear();
prints("\033[1;36m親愛的 \033[33m%s(%s)\033[36m,別忘了再度光臨\033[45;33m"
" %s \033[40;36m!\n以下是您在站內的註冊資料:\033[0m\n",