From eff2be3efa8e451f49c5de06170fb5c28570a702 Mon Sep 17 00:00:00 2001 From: glenux Date: Thu, 26 Feb 2004 10:47:46 +0000 Subject: [PATCH] * ajout du debug mode (affichage de certains messages seulement lors du debug) --- src/poolDataTabLock.c | 6 ++++-- src/poolDataTabUnlock.c | 11 ++++++----- src/queueProtLock.c | 5 +++-- src/queueProtUnlock.c | 16 +++++++++------- src/queueReadLock.c | 13 ++++++------- src/queueReadTryLock.c | 9 ++++----- src/queueReadUnlock.c | 6 ++++-- test/msgSpaceState.c | 4 ++-- 8 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/poolDataTabLock.c b/src/poolDataTabLock.c index 0baaf98..a8790cd 100644 --- a/src/poolDataTabLock.c +++ b/src/poolDataTabLock.c @@ -1,9 +1,11 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 + int msgPoolDataTabLock(msgSpace * space){ sem_t * poolDataTabSemFd; -printf("Locking %s\n",space->poolDataTabSemId); +if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);} poolDataTabSemFd=sem_open( space->poolDataTabSemId @@ -21,7 +23,7 @@ printf("Locking %s\n",space->poolDataTabSemId); } int semval=0; sem_getvalue(poolDataTabSemFd,&semval); - printf("(AfternValue:%d)\n",semval); + if (DEBUG) { printf("(AfternValue:%d)\n",semval);} sem_close(poolDataTabSemFd); diff --git a/src/poolDataTabUnlock.c b/src/poolDataTabUnlock.c index b6eb8c9..4c9afdc 100644 --- a/src/poolDataTabUnlock.c +++ b/src/poolDataTabUnlock.c @@ -1,11 +1,12 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 int msgPoolDataTabUnlock(msgSpace * space){ sem_t * poolDataTabSemFd; -printf("Unlocking %s\n",space->poolDataTabSemId); - poolDataTabSemFd=sem_open( + if (DEBUG) { printf("Unlocking %s\n",space->poolDataTabSemId); } + poolDataTabSemFd=sem_open( space->poolDataTabSemId ,O_CREAT, SEM_DEFAULT_MODE, @@ -19,9 +20,9 @@ printf("Unlocking %s\n",space->poolDataTabSemId); NZG_ERROR("sem_post",space->poolDataTabSemId); goto ERROR; } - int semval=0; - sem_getvalue(poolDataTabSemFd,&semval); - printf("(AfternValue:%d)\n",semval); + int semval=0; + sem_getvalue(poolDataTabSemFd,&semval); + if (DEBUG) { printf("(AfternValue:%d)\n",semval); } sem_close(poolDataTabSemFd); diff --git a/src/queueProtLock.c b/src/queueProtLock.c index 43125b9..476f5ab 100644 --- a/src/queueProtLock.c +++ b/src/queueProtLock.c @@ -1,12 +1,13 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 int msgQueueProtLock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); - printf("Locking %s\n",queueSemId); + if (DEBUG) { printf("Locking %s\n",queueSemId);} queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); @@ -19,7 +20,7 @@ int msgQueueProtLock(msgSpaceId externId,int queueIdx){ } int semval=0; sem_getvalue(queueSemFd,&semval); - printf("(AfterValue:%d)\n",semval); + if (DEBUG) { printf("(AfterValue:%d)\n",semval); } sem_close(queueSemFd); diff --git a/src/queueProtUnlock.c b/src/queueProtUnlock.c index 7bd5671..1e6d8d9 100644 --- a/src/queueProtUnlock.c +++ b/src/queueProtUnlock.c @@ -1,14 +1,16 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 + int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){ - sem_t * queueSemFd; + sem_t * queueSemFd; msgQueueSemId queueSemId; msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); - printf("Unlocking %s\n",queueSemId); - - queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); + if (DEBUG) { printf("Unlocking %s\n",queueSemId); } + + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -18,9 +20,9 @@ int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_post",queueSemId); goto ERROR; } - int semval=0; - sem_getvalue(queueSemFd,&semval); - printf("(AfterValue:%d)\n",semval); + int semval=0; + sem_getvalue(queueSemFd,&semval); + if (DEBUG) { printf("(AfterValue:%d)\n",semval); } sem_close(queueSemFd); diff --git a/src/queueReadLock.c b/src/queueReadLock.c index 2d9c79e..b694749 100644 --- a/src/queueReadLock.c +++ b/src/queueReadLock.c @@ -1,13 +1,15 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 + int msgQueueReadLock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); - printf("Locking %s\n",queueSemId); - queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); + if (DEBUG) { printf("Locking %s\n",queueSemId); } + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -18,11 +20,8 @@ int msgQueueReadLock(msgSpaceId externId,int queueIdx){ goto ERROR; } int semval=0; - sem_getvalue(queueSemFd,&semval); - printf("(AfterValue:%d)\n",semval); - - sem_close(queueSemFd); - + sem_getvalue(queueSemFd,&semval); + if (DEBUG) { printf("(AfterValue:%d)\n",semval); } sem_close(queueSemFd); diff --git a/src/queueReadTryLock.c b/src/queueReadTryLock.c index 4c3e597..3c33646 100644 --- a/src/queueReadTryLock.c +++ b/src/queueReadTryLock.c @@ -1,6 +1,8 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 + int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; @@ -16,13 +18,10 @@ int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_wait",queueSemId); goto ERROR; } - printf("Locking %s\n",queueSemId); + if (DEBUG) { printf("Locking %s\n",queueSemId); } int semval=0; sem_getvalue(queueSemFd,&semval); - printf("(AfterValue:%d)\n",semval); - - sem_close(queueSemFd); - + if (DEBUG) { printf("(AfterValue:%d)\n",semval); } sem_close(queueSemFd); diff --git a/src/queueReadUnlock.c b/src/queueReadUnlock.c index 717cefa..d6afbb6 100644 --- a/src/queueReadUnlock.c +++ b/src/queueReadUnlock.c @@ -1,12 +1,14 @@ #include "libnazgul.h" #include "ids.h" +#define DEBUG 0 + int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); - printf("Unlocking %s\n",queueSemId); + if (DEBUG) { printf("Unlocking %s\n",queueSemId); } queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); @@ -19,7 +21,7 @@ int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){ } int semval=0; sem_getvalue(queueSemFd,&semval); - printf("(AfterValue:%d)\n",semval); + if (DEBUG) { printf("(AfterValue:%d)\n",semval); } sem_close(queueSemFd); diff --git a/test/msgSpaceState.c b/test/msgSpaceState.c index e00d730..85ba668 100644 --- a/test/msgSpaceState.c +++ b/test/msgSpaceState.c @@ -38,8 +38,7 @@ int about(char * spaceId){ NZG_ERROR("sem_getvalue",ressourceSemId); goto ERROR; } - //msgPoolDataTabLock(space); - //msgPoolDataTabUnlock(space); + msgPoolDataTabLock(space); poolDataTab= msgPoolDataTabOpen(space); // donner le nombre de buffer disponibles printf("- %d/%d free buffers in pool #%d\n", @@ -47,6 +46,7 @@ int about(char * spaceId){ poolDataTab[i].bufferNb, i); msgPoolDataTabClose(space,poolDataTab); + msgPoolDataTabUnlock(space); if(sem_close(ressourceSemFd) <0){ NZG_ERROR("sem_getvalue",ressourceSemId); goto ERROR;