Commit b4ef65d6 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

NXresource.c: rework marked nx code

Improve visibility by unindenting. Also move the ifdefs _before_ the according comments. Finally merge ifdefs to fewer blocks.
parent 7a8eea1f
...@@ -248,14 +248,12 @@ AddResource(XID id, RESTYPE type, void * value) ...@@ -248,14 +248,12 @@ AddResource(XID id, RESTYPE type, void * value)
} }
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
nxagentSwitchResourceType(client, type, value); nxagentSwitchResourceType(client, type, value);
#ifdef TEST #ifdef TEST
fprintf(stderr, "AddResource: Adding resource for client [%d] type [%lu] value [%p] id [%lu].\n", fprintf(stderr, "AddResource: Adding resource for client [%d] type [%lu] value [%p] id [%lu].\n",
client, (unsigned long) type, (void *) value, (unsigned long) id); client, (unsigned long) type, (void *) value, (unsigned long) id);
#endif #endif
#endif #endif
if ((rrec->elements >= 4*rrec->buckets) && if ((rrec->elements >= 4*rrec->buckets) &&
...@@ -274,9 +272,9 @@ AddResource(XID id, RESTYPE type, void * value) ...@@ -274,9 +272,9 @@ AddResource(XID id, RESTYPE type, void * value)
res->value = value; res->value = value;
*head = res; *head = res;
rrec->elements++; rrec->elements++;
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
nxagentResChangedFlag = 1; nxagentResChangedFlag = 1;
#endif #endif
if (!(id & SERVER_BIT) && (id >= rrec->expectID)) if (!(id & SERVER_BIT) && (id >= rrec->expectID))
rrec->expectID = id + 1; rrec->expectID = id + 1;
return TRUE; return TRUE;
...@@ -293,11 +291,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) ...@@ -293,11 +291,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
Bool gotOne = FALSE; Bool gotOne = FALSE;
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
#ifdef TEST #ifdef TEST
fprintf(stderr, "FreeResource: Freeing resource id [%lu].\n", (unsigned long) id); fprintf(stderr, "FreeResource: Freeing resource id [%lu].\n", (unsigned long) id);
#endif #endif
#endif #endif
if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
...@@ -313,9 +309,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) ...@@ -313,9 +309,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
RESTYPE rtype = res->type; RESTYPE rtype = res->type;
*prev = res->next; *prev = res->next;
elements = --*eltptr; elements = --*eltptr;
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
nxagentResChangedFlag = 1; nxagentResChangedFlag = 1;
#endif #endif
if (rtype != skipDeleteFuncType) if (rtype != skipDeleteFuncType)
(*DeleteFuncs[rtype & TypeMask])(res->value, res->id); (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
free(res); free(res);
...@@ -349,9 +345,9 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree) ...@@ -349,9 +345,9 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
if (res->id == id && res->type == type) if (res->id == id && res->type == type)
{ {
*prev = res->next; *prev = res->next;
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
nxagentResChangedFlag = 1; nxagentResChangedFlag = 1;
#endif #endif
if (!skipFree) if (!skipFree)
(*DeleteFuncs[type & TypeMask])(res->value, res->id); (*DeleteFuncs[type & TypeMask])(res->value, res->id);
free(res); free(res);
...@@ -381,28 +377,21 @@ FindClientResourcesByType( ...@@ -381,28 +377,21 @@ FindClientResourcesByType(
int i, elements; int i, elements;
register int *eltptr; register int *eltptr;
#ifdef NXAGENT_SERVER
register ResourcePtr **resptr;
#endif
if (!client) if (!client)
client = serverClient; client = serverClient;
#ifdef NXAGENT_SERVER
/* /*
* If func triggers a resource table * If func triggers a resource table
* rebuild then restart the loop. * rebuild then restart the loop.
*/ */
register ResourcePtr **resptr;
#ifdef NXAGENT_SERVER
RestartLoop: RestartLoop:
resptr = &clientTable[client->index].resources;
#endif #endif
resources = clientTable[client->index].resources; resources = clientTable[client->index].resources;
#ifdef NXAGENT_SERVER
resptr = &clientTable[client->index].resources;
#endif
eltptr = &clientTable[client->index].elements; eltptr = &clientTable[client->index].elements;
for (i = 0; i < clientTable[client->index].buckets; i++) for (i = 0; i < clientTable[client->index].buckets; i++)
{ {
...@@ -412,17 +401,16 @@ RestartLoop: ...@@ -412,17 +401,16 @@ RestartLoop:
if (!type || this->type == type) { if (!type || this->type == type) {
elements = *eltptr; elements = *eltptr;
#ifdef NXAGENT_SERVER
/* /*
* FIXME: * FIXME:
* It is not safe to let a function change the resource * It is not safe to let a function change the resource
* table we are reading! * table we are reading!
*/ */
#ifdef NXAGENT_SERVER
nxagentResChangedFlag = 0; nxagentResChangedFlag = 0;
#endif #endif
(*func)(this->value, this->id, cdata); (*func)(this->value, this->id, cdata);
#ifdef NXAGENT_SERVER
/* /*
* Avoid that a call to RebuildTable() could invalidate the * Avoid that a call to RebuildTable() could invalidate the
* pointer. This is safe enough, because in RebuildTable() * pointer. This is safe enough, because in RebuildTable()
...@@ -430,10 +418,8 @@ RestartLoop: ...@@ -430,10 +418,8 @@ RestartLoop:
* freed, so it can't point to the same address. * freed, so it can't point to the same address.
*/ */
#ifdef NXAGENT_SERVER
if (*resptr != resources) if (*resptr != resources)
goto RestartLoop; goto RestartLoop;
#endif
/* /*
* It's not enough to check if the number of elements has * It's not enough to check if the number of elements has
...@@ -444,11 +430,10 @@ RestartLoop: ...@@ -444,11 +430,10 @@ RestartLoop:
* added or freed. * added or freed.
*/ */
#ifdef NXAGENT_SERVER
if (*eltptr != elements || nxagentResChangedFlag) if (*eltptr != elements || nxagentResChangedFlag)
#else #else
if (*eltptr != elements) if (*eltptr != elements)
#endif #endif
next = resources[i]; /* start over */ next = resources[i]; /* start over */
} }
} }
...@@ -466,28 +451,21 @@ FindAllClientResources( ...@@ -466,28 +451,21 @@ FindAllClientResources(
int i, elements; int i, elements;
register int *eltptr; register int *eltptr;
#ifdef NXAGENT_SERVER
register ResourcePtr **resptr;
#endif
if (!client) if (!client)
client = serverClient; client = serverClient;
#ifdef NXAGENT_SERVER
/* /*
* If func triggers a resource table * If func triggers a resource table
* rebuild then restart the loop. * rebuild then restart the loop.
*/ */
register ResourcePtr **resptr;
#ifdef NXAGENT_SERVER
RestartLoop: RestartLoop:
resptr = &clientTable[client->index].resources;
#endif #endif
resources = clientTable[client->index].resources; resources = clientTable[client->index].resources;
#ifdef NXAGENT_SERVER
resptr = &clientTable[client->index].resources;
#endif
eltptr = &clientTable[client->index].elements; eltptr = &clientTable[client->index].elements;
for (i = 0; i < clientTable[client->index].buckets; i++) for (i = 0; i < clientTable[client->index].buckets; i++)
{ {
...@@ -496,17 +474,18 @@ RestartLoop: ...@@ -496,17 +474,18 @@ RestartLoop:
next = this->next; next = this->next;
elements = *eltptr; elements = *eltptr;
#ifdef NXAGENT_SERVER
/* /*
* FIXME: * FIXME:
* It is not safe to let a function change the resource * It is not safe to let a function change the resource
* table we are reading! * table we are reading!
*/ */
#ifdef NXAGENT_SERVER
nxagentResChangedFlag = 0; nxagentResChangedFlag = 0;
#endif #endif
(*func)(this->value, this->id, this->type, cdata); (*func)(this->value, this->id, this->type, cdata);
#ifdef NXAGENT_SERVER
/* /*
* Avoid that a call to RebuildTable() could invalidate the * Avoid that a call to RebuildTable() could invalidate the
* pointer. This is safe enough, because in RebuildTable() * pointer. This is safe enough, because in RebuildTable()
...@@ -514,10 +493,8 @@ RestartLoop: ...@@ -514,10 +493,8 @@ RestartLoop:
* freed, so it can't point to the same address. * freed, so it can't point to the same address.
*/ */
#ifdef NXAGENT_SERVER
if (*resptr != resources) if (*resptr != resources)
goto RestartLoop; goto RestartLoop;
#endif
/* /*
* It's not enough to check if the number of elements has * It's not enough to check if the number of elements has
...@@ -528,11 +505,10 @@ RestartLoop: ...@@ -528,11 +505,10 @@ RestartLoop:
* added or freed. * added or freed.
*/ */
#ifdef NXAGENT_SERVER
if (*eltptr != elements || nxagentResChangedFlag) if (*eltptr != elements || nxagentResChangedFlag)
#else #else
if (*eltptr != elements) if (*eltptr != elements)
#endif #endif
next = resources[i]; /* start over */ next = resources[i]; /* start over */
} }
} }
...@@ -550,44 +526,36 @@ LookupClientResourceComplex( ...@@ -550,44 +526,36 @@ LookupClientResourceComplex(
ResourcePtr this; ResourcePtr this;
int i; int i;
#ifdef NXAGENT_SERVER
ResourcePtr **resptr;
Bool res;
#endif
if (!client) if (!client)
client = serverClient; client = serverClient;
#ifdef NXAGENT_SERVER
/* /*
* If func triggers a resource table * If func triggers a resource table
* rebuild then restart the loop. * rebuild then restart the loop.
*/ */
ResourcePtr **resptr;
#ifdef NXAGENT_SERVER
RestartLoop: RestartLoop:
resptr = &clientTable[client->index].resources;
#endif #endif
resources = clientTable[client->index].resources; resources = clientTable[client->index].resources;
#ifdef NXAGENT_SERVER
resptr = &clientTable[client->index].resources;
#endif
for (i = 0; i < clientTable[client->index].buckets; i++) { for (i = 0; i < clientTable[client->index].buckets; i++) {
for (this = resources[i]; this; this = this->next) { for (this = resources[i]; this; this = this->next) {
if (!type || this->type == type) { if (!type || this->type == type) {
#ifdef NXAGENT_SERVER #ifdef NXAGENT_SERVER
res = (*func)(this->value, this->id, cdata); Bool res = (*func)(this->value, this->id, cdata);
if (*resptr != resources) if (*resptr != resources)
goto RestartLoop; goto RestartLoop;
if (res) if (res)
return this->value; return this->value;
#else #else
if((*func)(this->value, this->id, cdata)) if((*func)(this->value, this->id, cdata))
return this->value; return this->value;
#endif #endif
} }
} }
} }
......
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