2004-02-22 17:39:08 +00:00
|
|
|
#include "libnazgul.h"
|
|
|
|
|
2019-09-17 12:47:35 +00:00
|
|
|
int msgFree(msgSpace * space, void * addr){
|
2004-02-23 17:15:20 +00:00
|
|
|
printf("[ FREE 0x%08x ]\n",(int)addr);
|
2004-02-23 15:54:29 +00:00
|
|
|
|
|
|
|
int poolIndex;
|
|
|
|
int bufferIndex;
|
|
|
|
msgPoolData * poolDataTabAddr;
|
|
|
|
sem_t * poolDataTabSemFd;
|
|
|
|
msgPoolDataTabSemId ressourceSemId;
|
|
|
|
sem_t * ressourceSemFd;
|
|
|
|
/* on acquiert le droit de modifier les infos sur la ressource */
|
|
|
|
/* on protege le tableau des associations */
|
|
|
|
poolDataTabSemFd=sem_open(space->poolDataTabSemId,
|
|
|
|
O_CREAT,SEM_DEFAULT_MODE,1);
|
|
|
|
if (poolDataTabSemFd == SEM_FAILED){
|
|
|
|
NZG_ERROR("sem_open : ouverture de la ressource",
|
|
|
|
space->poolDataTabSemId);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sem_wait(poolDataTabSemFd);
|
|
|
|
|
|
|
|
/* verifier le premier arg du shm_open */
|
|
|
|
|
2004-02-23 23:19:04 +00:00
|
|
|
poolDataTabAddr = msgPoolDataTabOpen(space);
|
2004-02-23 15:54:29 +00:00
|
|
|
|
|
|
|
// TODO: verouiller semaphore DataInfo
|
|
|
|
int err;
|
|
|
|
|
2004-02-23 16:32:20 +00:00
|
|
|
poolIndex=-1; bufferIndex=-1;
|
2004-02-23 15:54:29 +00:00
|
|
|
err=msgBufferGetProcAttach(
|
|
|
|
poolDataTabAddr,
|
|
|
|
space->poolNb,
|
|
|
|
&poolIndex,
|
|
|
|
&bufferIndex,
|
|
|
|
addr
|
|
|
|
);
|
|
|
|
|
2004-02-23 16:32:20 +00:00
|
|
|
printf("Found : %d\n",err);
|
|
|
|
printf("Freing pool: %d, buffer: %d\n",poolIndex,bufferIndex);
|
2004-02-23 17:15:20 +00:00
|
|
|
msgBufferDetachProc(poolDataTabAddr,poolIndex,bufferIndex,addr);
|
2004-02-23 15:54:29 +00:00
|
|
|
|
2004-02-23 22:16:44 +00:00
|
|
|
/* unmapper le buffer */
|
|
|
|
void * realAddr=addr;
|
|
|
|
int bufferSize=poolDataTabAddr[poolIndex].bufferSize;
|
|
|
|
int bufferNb=poolDataTabAddr[poolIndex].bufferNb;
|
|
|
|
realAddr=realAddr-poolIndex*bufferSize;
|
|
|
|
munmap(realAddr,bufferSize*bufferNb);
|
2004-02-23 23:19:04 +00:00
|
|
|
|
|
|
|
msgPoolDataTabClose(space,poolDataTabAddr);
|
2004-02-23 15:54:29 +00:00
|
|
|
|
|
|
|
// deverouiller semaphore DataInfo
|
2004-02-24 09:54:05 +00:00
|
|
|
msgPoolDataTabUnlock(space);
|
|
|
|
// sem_post(poolDataTabSemFd);
|
|
|
|
// sem_close(poolDataTabSemFd);
|
2004-02-23 15:54:29 +00:00
|
|
|
|
|
|
|
// deverouiller semaphore ressource.
|
|
|
|
msgPoolSemIdIntern(ressourceSemId,space->id,poolIndex);
|
|
|
|
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
|
|
|
if (ressourceSemFd == SEM_FAILED){
|
|
|
|
NZG_ERROR("sem_open",ressourceSemId);
|
2004-02-23 22:16:44 +00:00
|
|
|
goto ERROR;
|
2004-02-23 15:54:29 +00:00
|
|
|
}
|
|
|
|
sem_post(ressourceSemFd);
|
|
|
|
sem_close(ressourceSemFd);
|
2004-02-23 16:22:44 +00:00
|
|
|
return 0;
|
2004-02-23 22:16:44 +00:00
|
|
|
ERROR:
|
|
|
|
return -1;
|
2019-09-17 12:47:35 +00:00
|
|
|
}
|
2004-02-22 17:39:08 +00:00
|
|
|
|