#include <sys/ipc.h>
#include <sys/shm.h>
+#define MAX_SEMOP_RETRIES 500
int mutex_new(void)
{
return ret < 0? -E_SEM_GET : ret;
}
-int mutex_remove(int id)
+int mutex_destroy(int id)
{
int ret = semctl(id, 0, IPC_RMID);
return ret < 0? -E_SEM_REMOVE : 1;
static void para_semop(int id, struct sembuf *sops, int num)
{
- if (semop(id, sops, num) >= 0)
- return;
- PARA_WARNING_LOG("semop failed (%s), retrying\n", strerror(errno));
- while (semop(id, sops, num) < 0)
- ; /* nothing */
+ int i;
+
+ for (i = 0; i < MAX_SEMOP_RETRIES; i++)
+ if (semop(id, sops, num) >= 0)
+ return;
+ PARA_EMERG_LOG("semop failed %d times, aborting\n", MAX_SEMOP_RETRIES);
+ exit(EXIT_FAILURE);
}
/**
*
* \sa semop(2)
*/
-void *shm_attach(int id, enum shm_attach_mode mode)
+int shm_attach(int id, enum shm_attach_mode mode, void **result)
{
- if (mode == ATTACH_RW)
- return shmat(id, NULL, 0);
- return shmat(id, NULL, SHM_RDONLY);
+ if (mode == ATTACH_RW) {
+ *result = shmat(id, NULL, 0);
+ return *result? 1 : -E_SHM_ATTACH;
+ }
+ *result = shmat(id, NULL, SHM_RDONLY);
+ return *result? 1 : -E_SHM_ATTACH;
}
+
int shm_detach(void *addr)
{
int ret = shmdt(addr);