diff options
author | Antoine Villeret <avilleret@users.sourceforge.net> | 2014-10-03 12:47:43 +0000 |
---|---|---|
committer | Antoine Villeret <avilleret@users.sourceforge.net> | 2014-10-03 12:47:43 +0000 |
commit | 61a138457bc43e3696d230be58aace4f4f4dcb20 (patch) | |
tree | 4aa30778d5802c8df69f8bd15b0f7920cc6af5c2 | |
parent | 935ecc0752914edf117aaa0dbf143871d87a7d62 (diff) |
avoid deleting share memory segment if someone is still attached
svn path=/trunk/externals/share_mem/; revision=17353
-rw-r--r-- | shmem.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -8,7 +8,7 @@ #include <tchar.h> #else #include <sys/shm.h> - #include <sys/stat.h>
+ #include <sys/stat.h> #endif // _WIN32 typedef struct shmem @@ -317,8 +317,22 @@ void shmem_free(t_shmem *x) if ( x->share_memory ) UnmapViewOfFile( x->share_memory );
if ( x->m_MapFile ) CloseHandle( x->m_MapFile );
#else - shmdt (x->share_memory); - shmctl (x->segment_id, IPC_RMID, 0);
+ if ( x->share_memory ){ + if ( shmdt (x->share_memory) == -1) error("shmdt failed at %x", x->share_memory); + } + x->share_memory=NULL; + + int shm_id = x->segment_id; + struct shmid_ds shm_desc; + if(shm_id>0){ + if (shmctl(shm_id,IPC_STAT, &shm_desc) != -1){ + if(shm_desc.shm_nattch<=0){ + if (shmctl(shm_id,IPC_RMID, &shm_desc) == -1) error("shmctl remove failed for %d", shm_id); + } + } + } + shm_id=0; + //~shmctl (x->segment_id, IPC_RMID, 0);
#endif // _WIN32 } |