summaryrefslogtreecommitdiffstats
path: root/util/shmctl.c
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-17 11:35:31 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-17 11:35:31 +0800
commit000083cc87916be528e889208126e700918c313e (patch)
tree2c0dacc861e0700fb3cc1705080f282117ab21eb /util/shmctl.c
parent86dbcf633bd13c10081ee3414c136c299a4c7e13 (diff)
downloadpttbbs-000083cc87916be528e889208126e700918c313e.tar
pttbbs-000083cc87916be528e889208126e700918c313e.tar.gz
pttbbs-000083cc87916be528e889208126e700918c313e.tar.bz2
pttbbs-000083cc87916be528e889208126e700918c313e.tar.lz
pttbbs-000083cc87916be528e889208126e700918c313e.tar.xz
pttbbs-000083cc87916be528e889208126e700918c313e.tar.zst
pttbbs-000083cc87916be528e889208126e700918c313e.zip
rewrite SHM->HBcache sorted bsorted as offset value.
git-svn-id: http://opensvn.csie.org/pttbbs/branches/ptt.linux@2334 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/shmctl.c')
-rw-r--r--util/shmctl.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/util/shmctl.c b/util/shmctl.c
index 493e7c35..531f5235 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -42,7 +42,7 @@ int logout_friend_online(userinfo_t *utmp)
void purge_utmp(userinfo_t *uentp)
{
logout_friend_online(uentp);
- //memset(uentp, 0, sizeof(userinfo_t));
+ //memset(uentp, 0, sizeof(int));
}
typedef struct {
@@ -203,7 +203,7 @@ int utmpfix(int argc, char **argv)
if( clean ){
printf("clean %06d(%s), userid: %s\n",
i, clean, SHM->uinfo[which].userid);
- memset(&SHM->uinfo[which], 0, sizeof(userinfo_t));
+ memset(&SHM->uinfo[which], 0, sizeof(int));
--nownum;
changeflag = 1;
}
@@ -224,33 +224,33 @@ int utmpfix(int argc, char **argv)
/* utmpsortd --------------------------------------------------------------- */
static int
-cmputmpuserid(const void *i, const void *j)
+cmputmpuserid(int i, int j)
{
- return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid);
+ return strcasecmp(SHM->uinfo[i].userid, SHM->uinfo[j].userid);
}
static int
-cmputmpmode(const void *i, const void *j)
+cmputmpmode(int i, int j)
{
- return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode;
+ return SHM->uinfo[i].mode - SHM->uinfo[j].mode;
}
static int
-cmputmpidle(const void *i, const void *j)
+cmputmpidle(int i, int j)
{
- return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact;
+ return SHM->uinfo[i].lastact - SHM->uinfo[j].lastact;
}
static int
-cmputmpfrom(const void *i, const void *j)
+cmputmpfrom(int i, int j)
{
- return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from);
+ return strcmp(SHM->uinfo[i].from, SHM->uinfo[j].from);
}
static int
-cmputmpfive(const void *i, const void *j)
+cmputmpfive(int i, int j)
{
- userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j));
+ userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[j];
int played_a=(a->five_win+a->five_lose+a->five_lose)!=0;
int played_b=(b->five_win+b->five_lose+b->five_lose)!=0;
int type;
@@ -267,9 +267,9 @@ cmputmpfive(const void *i, const void *j)
}
static int
-cmputmpchc(const void *i, const void *j)
+cmputmpchc(int i, int j)
{
- userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j));
+ userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[j];
int total_a=a->chc_win+a->chc_lose+a->chc_lose;
int total_b=b->chc_win+b->chc_lose+b->chc_lose;
int played_a=(total_a!=0);
@@ -303,15 +303,15 @@ cmputmpchc(const void *i, const void *j)
}
static int
-cmputmppid(const void *i, const void *j)
+cmputmppid(int i, int j)
{
- return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid;
+ return SHM->uinfo[i].pid - SHM->uinfo[j].pid;
}
static int
-cmputmpuid(const void *i, const void *j)
+cmputmpuid(int i, int j)
{
- return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid;
+ return SHM->uinfo[i].uid - SHM->uinfo[j].uid;
}
inline void utmpsort(int sortall)
@@ -336,36 +336,36 @@ inline void utmpsort(int sortall)
if (uentp->sex < 0 || uentp->sex > 7)
purge_utmp(uentp);
else
- SHM->sorted[ns][0][count++] = uentp;
+ SHM->sorted[ns][0][count++] = i;
}
}
SHM->UTMPnumber = count;
- qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid);
+ qsort(SHM->sorted[ns][0], count, sizeof(int), cmputmpuserid);
memcpy(SHM->sorted[ns][6],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][7],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
- qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid);
- qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid);
+ SHM->sorted[ns][0], sizeof(int) * count);
+ qsort(SHM->sorted[ns][6], count, sizeof(int), cmputmpuid);
+ qsort(SHM->sorted[ns][7], count, sizeof(int), cmputmppid);
if( sortall ){
memcpy(SHM->sorted[ns][1],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][2],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][3],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][4],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][5],
- SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
- qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode);
- qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle);
- qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom);
- qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive);
- qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc);
+ SHM->sorted[ns][0], sizeof(int) * count);
+ qsort(SHM->sorted[ns][1], count, sizeof(int), cmputmpmode);
+ qsort(SHM->sorted[ns][2], count, sizeof(int), cmputmpidle);
+ qsort(SHM->sorted[ns][3], count, sizeof(int), cmputmpfrom);
+ qsort(SHM->sorted[ns][4], count, sizeof(int), cmputmpfive);
+ qsort(SHM->sorted[ns][5], count, sizeof(int), cmputmpchc);
memset(nusers, 0, sizeof(nusers));
for (i = 0; i < count; ++i) {
- uentp = SHM->sorted[ns][0][i];
+ uentp = &SHM->bcache[SHM->sorted[ns][0][i]];
if (uentp && uentp->pid &&
0 < uentp->brc_id && uentp->brc_id < MAX_BOARD)
++nusers[uentp->brc_id - 1];
@@ -373,9 +373,10 @@ inline void utmpsort(int sortall)
{
#if HOTBOARDCACHE
int k, r, last = 0, top = 0;
- boardheader_t *HBcache[HOTBOARDCACHE];
+ int HBcache[HOTBOARDCACHE];
+ for (i = 0; i < HOTBOARDCACHE; i++) HBcache[i]=-1;
#endif
- for (i = 0; i < SHM->Bnumber; ++i)
+ for (i = 0; i < SHM->Bnumber; i++)
if (SHM->bcache[i].brdname[0] != 0){
SHM->bcache[i].nuser = nusers[i];
#if HOTBOARDCACHE
@@ -384,14 +385,15 @@ inline void utmpsort(int sortall)
IS_BOARD(&SHM->bcache[i]) &&
IS_OPENBRD(&SHM->bcache[i]) ){
for( k = top - 1 ; k >= 0 ; --k )
- if( nusers[i] < HBcache[k]->nuser )
+ if(HBcache[k]>=0 &&
+ nusers[i] < SHM->bcache[HBcache[k]].nuser )
break;
if( top < HOTBOARDCACHE )
++top;
for( r = top - 1 ; r > (k + 1) ; --r )
HBcache[r] = HBcache[r - 1];
- HBcache[k + 1] = &SHM->bcache[i];
- last = nusers[(HBcache[top - 1] - SHM->bcache)];
+ HBcache[k + 1] = i;
+ last = nusers[HBcache[top - 1]];
}
#endif
}