36 lines
1,000 B
C
36 lines
1,000 B
C
|
#include "libnazgul.h"
|
|||
|
|
|||
|
int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr,int poolIndex){
|
|||
|
msgBufferInfoTabId bufferInfoTabId;
|
|||
|
int bufferInfoTabFd;
|
|||
|
msgBufferInfo * bufferInfoTabAddr;
|
|||
|
int bufferInfoNb;
|
|||
|
int bufferFreeIndex;
|
|||
|
|
|||
|
//r<>cuperer l'ID du BufferInfoTab;
|
|||
|
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
|
|||
|
|
|||
|
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);
|
|||
|
if (bufferInfoTabFd<0){
|
|||
|
perror("shm_open");
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
/** on regarde dans le tableau d'infos de buffer **/
|
|||
|
bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb;
|
|||
|
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
|
|||
|
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
|
|||
|
|
|||
|
int i=0;
|
|||
|
while ((i<bufferInfoNb)
|
|||
|
&& (bufferInfoTabAddr[i].ownerPid != (pid_t)-1)){ i++; }
|
|||
|
if (i == bufferInfoNb){ return -1; }
|
|||
|
bufferFreeIndex=i;
|
|||
|
|
|||
|
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
|
|||
|
{ perror("munmap"); return -1; }
|
|||
|
|
|||
|
return bufferFreeIndex;
|
|||
|
}
|
|||
|
|