Commit 2e4c846c authored by Christoffer Ackelman's avatar Christoffer Ackelman

Refactored pwr_lst to remove redundant pointer to data,

the data struct already contain the linked list,
so the linked list do not need pointers to the data.
parent a557a8ee
...@@ -59,27 +59,24 @@ typedef struct sAttribute sAttribute; ...@@ -59,27 +59,24 @@ typedef struct sAttribute sAttribute;
typedef struct sObject sObject; typedef struct sObject sObject;
typedef struct sSupObject sSupObject; typedef struct sSupObject sSupObject;
LstType(sAttribute);
LstType(sSupObject);
struct sObject { struct sObject {
tree_sNode tn; tree_sNode tn;
pwr_tObjid oid; pwr_tObjid oid;
int sup_c; int sup_c;
int attr_c; int attr_c;
LstHead(sAttribute) attr_l; struct LstHead attr_l;
}; };
struct sAttribute { struct sAttribute {
LstLink(sAttribute) attr_l; struct LstHead attr_l;
pwr_sAttrRef aref; pwr_sAttrRef aref;
pwr_tClassId cid; pwr_tClassId cid;
int sup_c; int sup_c;
LstHead(sSupObject) sup_l; struct LstHead sup_l;
}; };
struct sSupObject { struct sSupObject {
LstLink(sSupObject) sup_l; struct LstHead sup_l;
pwr_tObjid oid; pwr_tObjid oid;
void* p; void* p;
}; };
...@@ -100,8 +97,8 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -100,8 +97,8 @@ static alimsrv_sSupDataBuf* buildBuffer(
sObject* op; sObject* op;
sAttribute* ap; sAttribute* ap;
sSupObject* sp; sSupObject* sp;
LstLink(sAttribute) * al; struct LstHead * al;
LstLink(sSupObject) * sl; struct LstHead * sl;
pwr_tStatus sts; pwr_tStatus sts;
*size = 0; *size = 0;
...@@ -123,15 +120,15 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -123,15 +120,15 @@ static alimsrv_sSupDataBuf* buildBuffer(
bp->NoOfSupAttr = op->attr_c; bp->NoOfSupAttr = op->attr_c;
bap = bp->AttrSupList; bap = bp->AttrSupList;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { LstForEach(al, &op->attr_l) {
ap = LstObj(al); ap = LstEntry(al, sAttribute, attr_l);
bap->SupAttr = ap->aref; bap->SupAttr = ap->aref;
bap->NoOfSupObjs = ap->sup_c; bap->NoOfSupObjs = ap->sup_c;
bap->SupClass = ap->cid; bap->SupClass = ap->cid;
bsp = bap->SupList; bsp = bap->SupList;
for (sl = LstFir(&ap->sup_l); sl != LstEnd(&ap->sup_l); sl = LstNex(sl)) { LstForEach(sl, &ap->sup_l) {
sp = LstObj(sl); sp = LstEntry(sl, sSupObject, sup_l);
bsp->SupObjid = sp->oid; bsp->SupObjid = sp->oid;
if (ap->cid == pwr_cClass_ASup) { if (ap->cid == pwr_cClass_ASup) {
pwr_sClass_ASup* asup = (pwr_sClass_ASup*)sp->p; pwr_sClass_ASup* asup = (pwr_sClass_ASup*)sp->p;
...@@ -160,12 +157,12 @@ static alimsrv_sSupDataBuf* buildBuffer( ...@@ -160,12 +157,12 @@ static alimsrv_sSupDataBuf* buildBuffer(
static sAttribute* findAttribute( static sAttribute* findAttribute(
sObject* op, pwr_sAttrRef* aref, pwr_tClassId cid) sObject* op, pwr_sAttrRef* aref, pwr_tClassId cid)
{ {
LstLink(sAttribute) * al; struct LstHead * al;
sAttribute* ap = NULL; sAttribute* ap = NULL;
for (al = LstFir(&op->attr_l); al != LstEnd(&op->attr_l); al = LstNex(al)) { LstForEach(al, &op->attr_l) {
if (aref->Offset == LstObj(al)->aref.Offset) { if (aref->Offset == LstEntry(al, sAttribute, attr_l)->aref.Offset) {
ap = LstObj(al); ap = LstEntry(al, sAttribute, attr_l);
break; break;
} }
} }
...@@ -175,9 +172,9 @@ static sAttribute* findAttribute( ...@@ -175,9 +172,9 @@ static sAttribute* findAttribute(
if (ap == NULL) if (ap == NULL)
exit(2); exit(2);
LstIni(&ap->attr_l); LstInit(&ap->attr_l);
LstIni(&ap->sup_l); LstInit(&ap->sup_l);
(void)LstIns(&op->attr_l, ap, attr_l); LstInsert(&op->attr_l, &ap->attr_l);
op->attr_c++; op->attr_c++;
ap->cid = cid; ap->cid = cid;
ap->aref = *aref; ap->aref = *aref;
...@@ -204,13 +201,13 @@ static void init() ...@@ -204,13 +201,13 @@ static void init()
op = tree_Find(&sts, ltp, &asp->Attribute.Objid); op = tree_Find(&sts, ltp, &asp->Attribute.Objid);
if (op == NULL) { if (op == NULL) {
op = tree_Insert(&sts, ltp, &asp->Attribute.Objid); op = tree_Insert(&sts, ltp, &asp->Attribute.Objid);
LstIni(&op->attr_l); LstInit(&op->attr_l);
} }
ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup); ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup);
sp = calloc(1, sizeof(*sp)); sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid; sp->oid = oid;
sp->p = asp; sp->p = asp;
op->sup_c++; op->sup_c++;
...@@ -225,13 +222,13 @@ static void init() ...@@ -225,13 +222,13 @@ static void init()
op = tree_Find(&sts, ltp, &dsp->Attribute.Objid); op = tree_Find(&sts, ltp, &dsp->Attribute.Objid);
if (op == NULL) { if (op == NULL) {
op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid); op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid);
LstIni(&op->attr_l); LstInit(&op->attr_l);
} }
ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup); ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup);
sp = calloc(1, sizeof(*sp)); sp = calloc(1, sizeof(*sp));
(void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); LstInsert(&ap->sup_l, &sp->sup_l);
sp->oid = oid; sp->oid = oid;
sp->p = dsp; sp->p = dsp;
op->sup_c++; op->sup_c++;
......
This diff is collapsed.
...@@ -69,11 +69,9 @@ typedef enum { eTimer_ScanMessage = 1 } eTimer; ...@@ -69,11 +69,9 @@ typedef enum { eTimer_ScanMessage = 1 } eTimer;
typedef struct s_Node sNode; typedef struct s_Node sNode;
LstType(sNode);
struct s_Node { struct s_Node {
LstLink(sNode) node_l; struct LstHead node_l;
LstLink(sNode) timer_l; struct LstHead timer_l;
pwr_tObjid oid; pwr_tObjid oid;
pwr_sClass_NodeLinkSup node; pwr_sClass_NodeLinkSup node;
pwr_sClass_NodeLinkSup* o; pwr_sClass_NodeLinkSup* o;
...@@ -84,8 +82,8 @@ struct s_Node { ...@@ -84,8 +82,8 @@ struct s_Node {
}; };
static eListState list_state = eListState_Init; static eListState list_state = eListState_Init;
static LstHead(sNode) node_l; static struct LstHead node_l;
static LstHead(sNode) timer_l; static struct LstHead timer_l;
static void detect(pwr_sClass_NodeLinkSup*, pwr_tBoolean, sNode*); static void detect(pwr_sClass_NodeLinkSup*, pwr_tBoolean, sNode*);
static void event(qcom_sGet*); static void event(qcom_sGet*);
...@@ -137,11 +135,11 @@ int main(int argc, char** argv) ...@@ -137,11 +135,11 @@ int main(int argc, char** argv)
plc_UtlWaitForPlc(); plc_UtlWaitForPlc();
LstIni(&node_l); LstInit(&node_l);
LstIni(&timer_l); LstInit(&timer_l);
init_nodes(); init_nodes();
if (!LstEmp(&node_l)) { if (!LstEmpty(&node_l)) {
list_state = eListState_Scan; list_state = eListState_Scan;
} else { } else {
errh_Info("No nodes to supervise, exiting"); errh_Info("No nodes to supervise, exiting");
...@@ -195,8 +193,8 @@ static void detect(pwr_sClass_NodeLinkSup* o, pwr_tBoolean con, sNode* np) ...@@ -195,8 +193,8 @@ static void detect(pwr_sClass_NodeLinkSup* o, pwr_tBoolean con, sNode* np)
if (o->DetectCheck) { if (o->DetectCheck) {
o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect; o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect;
if (!o->TimerFlag && o->TimerCount > 0) { if (!o->TimerFlag && o->TimerCount > 0) {
if (!LstInl(&np->timer_l)) { if (LstIsNull(&np->timer_l)) {
LstIns(&timer_l, np, timer_l); LstInsert(&timer_l, &np->timer_l);
} }
o->TimerFlag = TRUE; o->TimerFlag = TRUE;
} }
...@@ -229,7 +227,7 @@ static void event(qcom_sGet* get) ...@@ -229,7 +227,7 @@ static void event(qcom_sGet* get)
if (new_event.b.swapDone & !cur_event.b.swapDone) { if (new_event.b.swapDone & !cur_event.b.swapDone) {
errh_Info("Warm restart completed."); errh_Info("Warm restart completed.");
reinit_nodes(); reinit_nodes();
if (!LstEmp(&node_l)) { if (!LstEmpty(&node_l)) {
list_state = eListState_Scan; list_state = eListState_Scan;
scan_timers(); scan_timers();
scan_nodes(); scan_nodes();
...@@ -322,21 +320,22 @@ static sNode* init_node(pwr_tObjid oid, sNode* np, pwr_tBoolean new_sub) ...@@ -322,21 +320,22 @@ static sNode* init_node(pwr_tObjid oid, sNode* np, pwr_tBoolean new_sub)
static pwr_tStatus init_nodes() static pwr_tStatus init_nodes()
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sNode) * nl; struct LstHead * nl;
sNode* np; sNode* np;
pwr_tObjid oid; pwr_tObjid oid;
nl = LstEnd(&node_l); nl = &node_l;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
np = init_node(oid, NULL, 1); np = init_node(oid, NULL, 1);
if (np != NULL) { if (np != NULL) {
nl = LstIns(nl, np, node_l); LstInsert(nl, &np->node_l);
nl = &np->node_l;
} }
} }
if (LstEmp(&node_l)) if (LstEmpty(&node_l))
errh_Info("No NodeLink objects"); errh_Info("No NodeLink objects");
return (sts); return (sts);
...@@ -346,11 +345,11 @@ static pwr_tStatus init_nodes() ...@@ -346,11 +345,11 @@ static pwr_tStatus init_nodes()
static sNode* get_nodes(pwr_tObjid oid) static sNode* get_nodes(pwr_tObjid oid)
{ {
LstLink(sNode) * nl; struct LstHead * nl;
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
if (cdh_ObjidIsEqual(LstObj(nl)->oid, oid)) if (cdh_ObjidIsEqual(LstEntry(nl, sNode, node_l)->oid, oid))
return LstObj(nl); return LstEntry(nl, sNode, node_l);
} }
return NULL; return NULL;
...@@ -359,20 +358,21 @@ static sNode* get_nodes(pwr_tObjid oid) ...@@ -359,20 +358,21 @@ static sNode* get_nodes(pwr_tObjid oid)
static void reinit_nodes() static void reinit_nodes()
{ {
pwr_tStatus sts; pwr_tStatus sts;
LstLink(sNode) * nl; struct LstHead * nl;
sNode* np; sNode* np;
pwr_tObjid oid; pwr_tObjid oid;
/* Mark all links in the NodeLink list */ /* Mark all links in the NodeLink list */
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) LstForEach(nl, &node_l)
LstObj(nl)->found = FALSE; LstEntry(nl, sNode, node_l)->found = FALSE;
for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts); for (sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid); ODD(sts);
sts = gdh_GetNextObject(oid, &oid)) { sts = gdh_GetNextObject(oid, &oid)) {
if ((np = get_nodes(oid)) == NULL) { if ((np = get_nodes(oid)) == NULL) {
np = init_node(oid, NULL, 1); np = init_node(oid, NULL, 1);
if (np != NULL) { if (np != NULL) {
nl = LstIns(nl, np, node_l); LstInsert(nl, &np->node_l);
nl = &np->node_l;
np->found = TRUE; np->found = TRUE;
} }
} else { } else {
...@@ -380,12 +380,12 @@ static void reinit_nodes() ...@@ -380,12 +380,12 @@ static void reinit_nodes()
} }
} }
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
np = LstObj(nl); np = LstEntry(nl, sNode, node_l);
if (!np->found) { if (!np->found) {
nl = LstPre(&np->node_l); nl = np->node_l.prev;
LstRem(&np->node_l); LstRemove(&np->node_l);
LstNul(&np->node_l); LstNull(&np->node_l);
gdh_SubUnrefObjectInfo(np->o->SubId); gdh_SubUnrefObjectInfo(np->o->SubId);
gdh_DLUnrefObjectInfo(np->dlid); gdh_DLUnrefObjectInfo(np->dlid);
free(np); free(np);
...@@ -395,7 +395,7 @@ static void reinit_nodes() ...@@ -395,7 +395,7 @@ static void reinit_nodes()
static void scan_nodes() static void scan_nodes()
{ {
LstLink(sNode) * nl; struct LstHead * nl;
pwr_tStatus sts; pwr_tStatus sts;
pwr_tBoolean Old; pwr_tBoolean Old;
pwr_tTime LastUpdate, Timeout, CurrentTime; pwr_tTime LastUpdate, Timeout, CurrentTime;
...@@ -404,8 +404,8 @@ static void scan_nodes() ...@@ -404,8 +404,8 @@ static void scan_nodes()
time_GetTime(&CurrentTime); time_GetTime(&CurrentTime);
for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { LstForEach(nl, &node_l) {
sNode* np = LstObj(nl); sNode* np = LstEntry(nl, sNode, node_l);
pwr_sClass_NodeLinkSup* o = np->o; pwr_sClass_NodeLinkSup* o = np->o;
LinkUp = 0; LinkUp = 0;
sts = gdh_GetSubscriptionOldness(o->SubId, &Old, &LastUpdate, NULL); sts = gdh_GetSubscriptionOldness(o->SubId, &Old, &LastUpdate, NULL);
...@@ -435,17 +435,17 @@ static void scan_nodes() ...@@ -435,17 +435,17 @@ static void scan_nodes()
static void scan_timers() static void scan_timers()
{ {
LstLink(sNode) * nl, *nxtnl; struct LstHead * nl, *nxtnl;
plc_sTimer* tp; plc_sTimer* tp;
for (nl = LstFir(&timer_l); nl != LstEnd(&timer_l); nl = nxtnl) { for (nl = timer_l.next; nl != &timer_l; nl = nxtnl) {
tp = LstObj(nl)->timer; tp = LstEntry(nl, sNode, timer_l)->timer;
nxtnl = LstNex(nl); nxtnl = nl->next;
if (tp->TimerCount <= 1 || !tp->TimerFlag) { if (tp->TimerCount <= 1 || !tp->TimerFlag) {
tp->TimerCount = 0; tp->TimerCount = 0;
tp->TimerFlag = FALSE; tp->TimerFlag = FALSE;
LstRem(nl); LstRemove(nl);
LstNul(nl); LstNull(nl);
} else { } else {
tp->TimerCount--; tp->TimerCount--;
} }
......
...@@ -57,19 +57,17 @@ ...@@ -57,19 +57,17 @@
typedef struct s_Timer sTimer; typedef struct s_Timer sTimer;
LstType(sTimer);
struct s_Timer { struct s_Timer {
LstLink(sTimer) ll; struct LstHead ll;
time_tClock clock; time_tClock clock;
pwr_tBoolean wrapped; pwr_tBoolean wrapped;
void* data; void* data;
void (*exec)(); void (*exec)();
}; };
static LstHead(sTimer) timer_lh; static struct LstHead timer_lh;
static LstHead(sTimer) wrap_lh; static struct LstHead wrap_lh;
static LstHead(sTimer) free_lh; static struct LstHead free_lh;
static time_tClock now_clock; static time_tClock now_clock;
static time_tClock last_clock; static time_tClock last_clock;
...@@ -104,7 +102,7 @@ static void waitClock(time_tClock c, int* tmo_ms); ...@@ -104,7 +102,7 @@ static void waitClock(time_tClock c, int* tmo_ms);
static void setInterval(time_tClock* c, pwr_tUInt32 i); static void setInterval(time_tClock* c, pwr_tUInt32 i);
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force); static void executeExpired(struct LstHead * lh, pwr_tBoolean force);
static void getNewTimers(); static void getNewTimers();
...@@ -370,16 +368,16 @@ static void cacheTrim(sTimer* tp) ...@@ -370,16 +368,16 @@ static void cacheTrim(sTimer* tp)
static void insertTimer(sTimer* tp) static void insertTimer(sTimer* tp)
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tip; sTimer* tip;
if (LstEmp(&timer_lh)) { if (LstEmpty(&timer_lh)) {
(void)LstIns(LstEnd(&timer_lh), tp, ll); LstInsert(&timer_lh, &tp->ll);
return; return;
} }
for (tl = LstLas(&timer_lh); tl != LstEnd(&timer_lh); tl = LstPre(tl)) { for (tl = timer_lh.prev; tl != &timer_lh; tl = tl->prev) {
tip = LstObj(tl); tip = LstEntry(tl, sTimer, ll);
if (tp->wrapped) { if (tp->wrapped) {
if (!tip->wrapped || tip->clock < tp->clock) if (!tip->wrapped || tip->clock < tp->clock)
...@@ -388,8 +386,8 @@ static void insertTimer(sTimer* tp) ...@@ -388,8 +386,8 @@ static void insertTimer(sTimer* tp)
break; break;
} }
tl = LstNex(tl); tl = tl->next;
(void)LstIns(tl, tp, ll); LstInsert(tl, &tp->ll);
} }
/* . */ /* . */
...@@ -416,7 +414,7 @@ static sTimer* newTimer(time_tClock* clock, void* data, void (*exec)()) ...@@ -416,7 +414,7 @@ static sTimer* newTimer(time_tClock* clock, void* data, void (*exec)())
static void freeTimer(sTimer* tp) static void freeTimer(sTimer* tp)
{ {
memset(tp, 0, sizeof(*tp)); memset(tp, 0, sizeof(*tp));
LstIns(&LstEnd(free_lh), tp, ll); LstInsert(&free_lh, &tp->ll);
} }
/* . */ /* . */
...@@ -425,19 +423,19 @@ static sTimer* allocTimer() ...@@ -425,19 +423,19 @@ static sTimer* allocTimer()
{ {
const int cAllocCount = 100; const int cAllocCount = 100;
sTimer* ftp; sTimer* ftp;
LstLink(sTimer) * ftl; struct LstHead * ftl;
int i; int i;
if (LstEmp(&free_lh)) { if (LstEmpty(&free_lh)) {
ftp = (sTimer*)calloc(cAllocCount, sizeof(sTimer)); ftp = (sTimer*)calloc(cAllocCount, sizeof(sTimer));
for (i = 0; i < cAllocCount; i++, ftp++) { for (i = 0; i < cAllocCount; i++, ftp++) {
LstIns(&LstEnd(free_lh), ftp, ll); LstInsert(&free_lh, &ftp->ll);
} }
} }
ftl = LstFir(&free_lh); ftl = free_lh.next;
LstRem(ftl); LstRemove(ftl);
return LstObj(ftl); return LstEntry(ftl, sTimer, ll);
} }
static void setTimer(sTimer* tp, time_tClock offs) static void setTimer(sTimer* tp, time_tClock offs)
...@@ -498,21 +496,21 @@ static void setInterval(time_tClock* c, ...@@ -498,21 +496,21 @@ static void setInterval(time_tClock* c,
#endif #endif
} }
static void executeExpired(LstHead(sTimer) * lh, pwr_tBoolean force) static void executeExpired(struct LstHead * lh, pwr_tBoolean force)
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tp; sTimer* tp;
gdb_AssumeUnlocked; gdb_AssumeUnlocked;
gdb_ScopeLock gdb_ScopeLock
{ {
for (tl = LstFir(lh); tl != LstEnd(lh); tl = LstFir(lh)) { LstForEach(tl, lh) {
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
if (force || (!tp->wrapped && tp->clock <= now_clock)) { if (force || (!tp->wrapped && tp->clock <= now_clock)) {
LstRem(tl); LstRemove(tl);
LstNul(tl); LstNull(tl);
tp->exec(tp); tp->exec(tp);
} else } else
break; break;
...@@ -560,11 +558,11 @@ static void getNewTimers() ...@@ -560,11 +558,11 @@ static void getNewTimers()
static void getWaitClock(time_tClock* wait_clock, time_tClock last_clock) static void getWaitClock(time_tClock* wait_clock, time_tClock last_clock)
{ {
int diff; int diff;
LstLink(sTimer) * tl; struct LstHead * tl;
sTimer* tp; sTimer* tp;
tl = LstFir(&timer_lh); tl = timer_lh.next;
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
if (now_clock < last_clock) { if (now_clock < last_clock) {
if (tp->wrapped) { if (tp->wrapped) {
...@@ -610,9 +608,9 @@ static void init() ...@@ -610,9 +608,9 @@ static void init()
gdbroot->db->tmon = gdbroot->my_qid; gdbroot->db->tmon = gdbroot->my_qid;
gdbroot->is_tmon = 1; gdbroot->is_tmon = 1;
LstIni(&timer_lh); LstInit(&timer_lh);
LstIni(&wrap_lh); LstInit(&wrap_lh);
LstIni(&free_lh); LstInit(&free_lh);
last_clock = now_clock = time_Clock(NULL, NULL); last_clock = now_clock = time_Clock(NULL, NULL);
...@@ -631,18 +629,18 @@ static void init() ...@@ -631,18 +629,18 @@ static void init()
static void toggleWrapped() static void toggleWrapped()
{ {
LstLink(sTimer) * tl; struct LstHead * tl;
LstLink(sTimer) * ntl; struct LstHead * ntl;
sTimer* tp; sTimer* tp;
LstHead(sTimer)* tlh = &timer_lh; struct LstHead* tlh = &timer_lh;
for (tl = LstFir(tlh); tl != LstEnd(tlh); tl = ntl) { for (tl = tlh->next; tl != tlh; tl = ntl) {
tp = LstObj(tl); tp = LstEntry(tl, sTimer, ll);
ntl = LstNex(tl); ntl = tl->next;
if (!tp->wrapped) { if (!tp->wrapped) {
LstRem(tl); LstRemove(tl);
(void)LstIns(LstEnd(&wrap_lh), tp, ll); LstInsert(&wrap_lh, &tp->ll);
} else } else
tp->wrapped = 0; tp->wrapped = 0;
} }
......
...@@ -40,33 +40,96 @@ ...@@ -40,33 +40,96 @@
/* pwr_lst.h -- list macros /* pwr_lst.h -- list macros
*/ */
#define LstType(a) \ struct LstHead {
typedef struct s_LstLink_##a sLstLink_##a; \ struct LstHead *next, *prev;
struct s_LstLink_##a { \ };
sLstLink_##a* nex; \
sLstLink_##a* pre; \
a* obj; \
}
#define LstLink(a) sLstLink_##a /*
* LstInsert(s_LstLink_T* next, s_LstLink_T elem) inserts the element \a into
* the linked list before the element \a next.
*
* Before:
* a <-> c
*
* Calling LstInsert(c, b)
* a <- b (a <- b)
* b -> c (a <- b -> c)
* a -> b (a <-> b -> c)
* b <- c (a <-> b <-> c)
*/
static inline void LstInsert(struct LstHead *p, struct LstHead *e)
{
e->prev = p->prev;
e->next = p;
p->prev->next = e;
p->prev = e;
}
/*
* LstRemove(s_LstLink_T) removes the element from the linked list, which is
* done by modifying the next element to point at the previous and vice versa.
*/
static inline void LstRemove(struct LstHead *p)
{
p->next->prev = p->prev;
p->prev->next = p->next;
}
#define LstHead(a) sLstLink_##a /*
* LstNull(s_LstLink_T) sets the linked list to NULL.
*/
static inline void LstNull(struct LstHead *p)
{
p->next = p->prev = NULL;
}
#define LstNex(p) ((p)->nex) /*
#define LstPre(p) ((p)->pre) * LstIsNull(s_LstLink_T) checks if the linked list is NULL.
#define LstLas(h) ((h)->pre) */
#define LstFir(h) ((h)->nex) static inline int LstIsNull(struct LstHead *p)
#define LstEnd(h) (h) {
#define LstIns(p, o, e) \ return (p->next == NULL && p->prev == NULL);
((o)->e.obj = (void*)o, (o)->e.pre = (void*)((p)->pre), \ }
(o)->e.nex = (void*)(p), (p)->pre->nex = (void*)(&(o)->e), \
(p)->pre = (void*)(&(o)->e)) /*
#define LstRem(p) ((p)->nex->pre = (p)->pre, (p)->pre->nex = (p)->nex) * LstInit(s_LstLink_T) initializes the linked list.
#define LstNul(p) ((p)->nex = (p)->pre = NULL) */
#define LstIsNul(p) ((p)->nex == NULL && (p)->pre == NULL) static inline void LstInit(struct LstHead *h)
#define LstInl(p) ((p)->nex != NULL && (p)->pre != NULL) {
#define LstIni(h) ((h)->nex = (h)->pre = (h)) h->next = h->prev = h;
#define LstObj(p) ((p)->obj) }
#define LstEmp(h) ((h) == (h)->nex)
/*
* LstEntry(s_LstLink_T*, sTimer, ll) fetches the struct sTimer corresponding to
* the list pointer \a ptr.
* It does this by calculating the offset of a list pointers \a ll within the
* struct sTimer, and then subtracts that from the list pointer \a ptr.
*/
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#define LstEntry(ptr, type, member) container_of(ptr, type, member)
/*
* LstEmpty(s_LstLink_T) checks if the linked list is empty.
*/
static inline int LstEmpty(struct LstHead *h)
{
return h->next == h;
}
/*
* LstForEach(i, listHead) is a convenience macro for:
* for (i = listHead->next; i != listHead, i = i->next)
*/
#define LstForEach(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#endif #endif
This diff is collapsed.
...@@ -64,10 +64,8 @@ ...@@ -64,10 +64,8 @@
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
LstType(sFacilityCB);
struct s_FacilityCB { struct s_FacilityCB {
LstLink(sFacilityCB) FacL; struct LstHead FacL;
char* facnam; char* facnam;
int facnum; int facnum;
}; };
...@@ -76,7 +74,7 @@ extern int lineno; ...@@ -76,7 +74,7 @@ extern int lineno;
static int SyntaxError; static int SyntaxError;
static LstHead(sFacilityCB) lFacH; static struct LstHead lFacH;
static sFacilityCB* CurrFac = NULL; static sFacilityCB* CurrFac = NULL;
static void CopyFile(FILE* ifp, FILE* ofp); static void CopyFile(FILE* ifp, FILE* ofp);
...@@ -122,7 +120,7 @@ int main(int argc, char** argv) ...@@ -122,7 +120,7 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
LstIni(&lFacH); LstInit(&lFacH);
SyntaxError = 0; SyntaxError = 0;
lineno = 1; lineno = 1;
...@@ -159,7 +157,7 @@ void lex_FacName(char* facnam) ...@@ -159,7 +157,7 @@ void lex_FacName(char* facnam)
void lex_FacNum(int facnum) void lex_FacNum(int facnum)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
/* /*
* To do: Check that the facility number is within the valid range * To do: Check that the facility number is within the valid range
...@@ -167,14 +165,14 @@ void lex_FacNum(int facnum) ...@@ -167,14 +165,14 @@ void lex_FacNum(int facnum)
*/ */
/* Insert in ascending order */ /* Insert in ascending order */
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
if (LstObj(fl)->facnum > facnum) { if (LstEntry(fl, sFacilityCB, FacL)->facnum > facnum) {
break; break;
} }
} }
CurrFac->facnum = facnum; CurrFac->facnum = facnum;
LstIns(fl, CurrFac, FacL); LstInsert(fl, &CurrFac->FacL);
CurrFac = NULL; CurrFac = NULL;
} }
...@@ -192,20 +190,20 @@ static void CopyFile(FILE* ifp, FILE* ofp) ...@@ -192,20 +190,20 @@ static void CopyFile(FILE* ifp, FILE* ofp)
static void WriteFacility(FILE* cfp, char* branch) static void WriteFacility(FILE* cfp, char* branch)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
int i = 0; int i = 0;
fprintf(cfp, "static msg_sFacility *Facilities[] = {\n"); fprintf(cfp, "static msg_sFacility *Facilities[] = {\n");
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
if (i++) if (i++)
fprintf(cfp, ",\n"); fprintf(cfp, ",\n");
fprintf(cfp, "\t%-20s /* %4d */", LstObj(fl)->facnam, LstObj(fl)->facnum); fprintf(cfp, "\t%-20s /* %4d */", LstEntry(fl, sFacilityCB, FacL)->facnam, LstEntry(fl, sFacilityCB, FacL)->facnum);
} }
fprintf(cfp, "};\n\n"); fprintf(cfp, "};\n\n");
if (LstFir(&lFacH) == LstEnd(&lFacH)) if (LstEmpty(&lFacH))
fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp"); fprintf(cfp, "msg_sHead %sMsgHead = {0, 0};\n", branch ? branch : "pwrp");
else else
fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n", fprintf(cfp, "msg_sHead %sMsgHead = {MSG_NOF(Facilities), Facilities};\n",
......
...@@ -61,18 +61,15 @@ ...@@ -61,18 +61,15 @@
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
typedef struct s_MsgCB sMsgCB; typedef struct s_MsgCB sMsgCB;
LstType(sFacilityCB);
LstType(sMsgCB);
struct s_MsgCB { struct s_MsgCB {
LstLink(sMsgCB) MsgL; struct LstHead MsgL;
msg_sMsg m; msg_sMsg m;
msg_eSeverity Severity; msg_eSeverity Severity;
}; };
struct s_FacilityCB { struct s_FacilityCB {
LstLink(sFacilityCB) FacL; struct LstHead FacL;
LstHead(sMsgCB) MsgH; struct LstHead MsgH;
msg_sFacility f; msg_sFacility f;
}; };
...@@ -81,7 +78,7 @@ extern int lineno; ...@@ -81,7 +78,7 @@ extern int lineno;
static int SyntaxError; static int SyntaxError;
static LstHead(sFacilityCB) lFacH; static struct LstHead lFacH;
/* /*
* Local functions * Local functions
...@@ -125,7 +122,7 @@ int main(int argc, char** argv) ...@@ -125,7 +122,7 @@ int main(int argc, char** argv)
exit(2); exit(2);
} }
LstIni(&lFacH); LstInit(&lFacH);
SyntaxError = 0; SyntaxError = 0;
lineno = 1; lineno = 1;
yylex(); yylex();
...@@ -160,20 +157,20 @@ void lex_FacName(const char* FacName) ...@@ -160,20 +157,20 @@ void lex_FacName(const char* FacName)
{ {
sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB)); sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB));
LstIni(&facp->MsgH); LstInit(&facp->MsgH);
facp->f.FacName = MSG_NEW_STRING(FacName); facp->f.FacName = MSG_NEW_STRING(FacName);
LstIns(&lFacH, facp, FacL); LstInsert(&lFacH, &facp->FacL);
} }
void lex_FacNum(int FacNum) void lex_FacNum(int FacNum)
{ {
LstObj(LstLas(&lFacH))->f.FacNum = FacNum; LstEntry(lFacH.prev, sFacilityCB, FacL)->f.FacNum = FacNum;
} }
void lex_FacPrefix(const char* Prefix) void lex_FacPrefix(const char* Prefix)
{ {
LstObj(LstLas(&lFacH))->f.Prefix = MSG_NEW_STRING(Prefix); LstEntry(lFacH.prev, sFacilityCB, FacL)->f.Prefix = MSG_NEW_STRING(Prefix);
} }
void lex_MsgName(const char* MsgName) void lex_MsgName(const char* MsgName)
...@@ -187,21 +184,21 @@ void lex_MsgName(const char* MsgName) ...@@ -187,21 +184,21 @@ void lex_MsgName(const char* MsgName)
msgp->m.MsgName[i] = toupper(MsgName[i]); msgp->m.MsgName[i] = toupper(MsgName[i]);
msgp->m.MsgName[i] = '\0'; msgp->m.MsgName[i] = '\0';
(void)LstIns(&LstObj(LstLas(&lFacH))->MsgH, msgp, MsgL); LstInsert(&LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH, &msgp->MsgL);
} }
void lex_MsgText(const char* Text) void lex_MsgText(const char* Text)
{ {
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
TranslateFormatSpec( TranslateFormatSpec(
Text, &LstObj(ml)->m.MsgTxt); /* convert any VMS-style form spec */ Text, &LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt); /* convert any VMS-style form spec */
} }
void lex_MsgSeverity(msg_eSeverity Severity) void lex_MsgSeverity(msg_eSeverity Severity)
{ {
LstLink(sMsgCB)* ml = LstLas(&LstObj(LstLas(&lFacH))->MsgH); struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
LstObj(ml)->Severity = Severity; LstEntry(ml, sMsgCB, MsgL)->Severity = Severity;
} }
void lex_LexError(int Lineno, char* Str) void lex_LexError(int Lineno, char* Str)
...@@ -215,8 +212,8 @@ void lex_LexError(int Lineno, char* Str) ...@@ -215,8 +212,8 @@ void lex_LexError(int Lineno, char* Str)
*/ */
static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
{ {
LstLink(sFacilityCB) * fl; struct LstHead * fl;
LstLink(sMsgCB) * ml; struct LstHead * ml;
int idx; int idx;
int facid; int facid;
char prefix[32]; char prefix[32];
...@@ -227,37 +224,38 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) ...@@ -227,37 +224,38 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
fprintf(hfp, "#ifndef %s_h\n", fname); fprintf(hfp, "#ifndef %s_h\n", fname);
fprintf(hfp, "#define %s_h\n\n", fname); fprintf(hfp, "#define %s_h\n\n", fname);
for (fl = LstFir(&lFacH); fl != LstEnd(&lFacH); fl = LstNex(fl)) { LstForEach(fl, &lFacH) {
facid = 0x800 + LstObj(fl)->f.FacNum; facid = 0x800 + LstEntry(fl, sFacilityCB, FacL)->f.FacNum;
snprintf(name, sizeof(name), "%s_FACILITY", LstObj(fl)->f.FacName); snprintf(name, sizeof(name), "%s_FACILITY", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid); fprintf(hfp, "#define %-29s %9d /* x%08x */\n", name, facid, facid);
facid = facid << 16; facid = facid << 16;
if (LstObj(fl)->f.Prefix) if (LstEntry(fl, sFacilityCB, FacL)->f.Prefix)
strncpy(prefix, LstObj(fl)->f.Prefix, sizeof(prefix)); strncpy(prefix, LstEntry(fl, sFacilityCB, FacL)->f.Prefix, sizeof(prefix));
else else
snprintf(prefix, sizeof(prefix), "%s_", LstObj(fl)->f.FacName); snprintf(prefix, sizeof(prefix), "%s_", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
snprintf(msgName, sizeof(msgName), "%smsg", LstObj(fl)->f.FacName); snprintf(msgName, sizeof(msgName), "%smsg", LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName); fprintf(cfp, "static msg_sMsg %s[] = {\n", msgName);
for (idx = 1, ml = LstFir(&LstObj(fl)->MsgH); idx = 1;
ml != LstEnd(&LstObj(fl)->MsgH); ml = LstNex(ml), idx++) { LstForEach(ml, &LstEntry(fl, sFacilityCB, FacL)->MsgH) {
if (idx != 1) if (idx != 1)
fprintf(cfp, ",\n"); fprintf(cfp, ",\n");
msg = facid + 0x8000 + (idx << 3) + LstObj(ml)->Severity; msg = facid + 0x8000 + (idx << 3) + LstEntry(ml, sMsgCB, MsgL)->Severity;
snprintf(name, sizeof(name), "%s%s", prefix, LstObj(ml)->m.MsgName); snprintf(name, sizeof(name), "%s%s", prefix, LstEntry(ml, sMsgCB, MsgL)->m.MsgName);
fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg); fprintf(hfp, "#define %-29s %9.9d /* x%08x */\n", name, msg, msg);
fprintf(cfp, "\t{\"%s\", \"%s\"}", LstObj(ml)->m.MsgName, fprintf(cfp, "\t{\"%s\", \"%s\"}", LstEntry(ml, sMsgCB, MsgL)->m.MsgName,
LstObj(ml)->m.MsgTxt); LstEntry(ml, sMsgCB, MsgL)->m.MsgTxt);
idx++;
} }
fprintf(cfp, "\n};\n\n"); fprintf(cfp, "\n};\n\n");
fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t", fprintf(cfp, "static msg_sFacility %sfacility[] = {\n\t",
LstObj(fl)->f.FacName); LstEntry(fl, sFacilityCB, FacL)->f.FacName);
fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n", fprintf(cfp, "{%d, \"%s\", \"%s\", MSG_NOF(%s), %s}\n",
LstObj(fl)->f.FacNum, LstObj(fl)->f.FacName, prefix, msgName, msgName); LstEntry(fl, sFacilityCB, FacL)->f.FacNum, LstEntry(fl, sFacilityCB, FacL)->f.FacName, prefix, msgName, msgName);
fprintf(cfp, "};\n\n"); fprintf(cfp, "};\n\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment