| 26 |
#include <sys/sem.h> |
#include <sys/sem.h> |
| 27 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 28 |
|
|
| 29 |
#ifdef _SEM_SEMUN_UNDEFINED |
#if defined(_SEM_SEMUN_UNDEFINED) || defined(__MSYS__) || defined(__MINGW32__) |
| 30 |
union semun |
union semun |
| 31 |
{ |
{ |
| 32 |
int val; /* Value for SETVAL */ |
int val; /* Value for SETVAL */ |
| 35 |
struct seminfo *__buf; /* Buffer for IPC_INFO |
struct seminfo *__buf; /* Buffer for IPC_INFO |
| 36 |
(Linux-specific) */ |
(Linux-specific) */ |
| 37 |
}; |
}; |
| 38 |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
#endif // #if defined(_SEM_SEMUN_UNDEFINED) |
| 39 |
|
|
| 40 |
enum _user_list_constant_t |
enum _user_list_constant_t |
| 41 |
{ |
{ |
| 643 |
int user_list_try_rd_lock(int semid, int wait_sec) |
int user_list_try_rd_lock(int semid, int wait_sec) |
| 644 |
{ |
{ |
| 645 |
struct sembuf sops[2]; |
struct sembuf sops[2]; |
| 646 |
|
#if !defined(__MSYS__) && !defined(__MINGW32__) |
| 647 |
struct timespec timeout; |
struct timespec timeout; |
| 648 |
|
#endif |
| 649 |
int ret; |
int ret; |
| 650 |
|
|
| 651 |
sops[0].sem_num = 1; // w_sem |
sops[0].sem_num = 1; // w_sem |
| 656 |
sops[1].sem_op = 1; // lock |
sops[1].sem_op = 1; // lock |
| 657 |
sops[1].sem_flg = SEM_UNDO; // undo on terminate |
sops[1].sem_flg = SEM_UNDO; // undo on terminate |
| 658 |
|
|
| 659 |
|
#if defined(__MSYS__) || defined(__MINGW32__) |
| 660 |
|
ret = semop(semid, sops, 2); |
| 661 |
|
#else |
| 662 |
timeout.tv_sec = wait_sec; |
timeout.tv_sec = wait_sec; |
| 663 |
timeout.tv_nsec = 0; |
timeout.tv_nsec = 0; |
| 664 |
|
|
| 665 |
ret = semtimedop(semid, sops, 2, &timeout); |
ret = semtimedop(semid, sops, 2, &timeout); |
| 666 |
|
#endif |
| 667 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 668 |
{ |
{ |
| 669 |
log_error("semtimedop(lock read) error %d\n", errno); |
log_error("semop(lock read) error %d\n", errno); |
| 670 |
} |
} |
| 671 |
|
|
| 672 |
return ret; |
return ret; |
| 675 |
int user_list_try_rw_lock(int semid, int wait_sec) |
int user_list_try_rw_lock(int semid, int wait_sec) |
| 676 |
{ |
{ |
| 677 |
struct sembuf sops[3]; |
struct sembuf sops[3]; |
| 678 |
|
#if !defined(__MSYS__) && !defined(__MINGW32__) |
| 679 |
struct timespec timeout; |
struct timespec timeout; |
| 680 |
|
#endif |
| 681 |
int ret; |
int ret; |
| 682 |
|
|
| 683 |
sops[0].sem_num = 1; // w_sem |
sops[0].sem_num = 1; // w_sem |
| 692 |
sops[2].sem_op = 0; // wait until unlocked |
sops[2].sem_op = 0; // wait until unlocked |
| 693 |
sops[2].sem_flg = 0; |
sops[2].sem_flg = 0; |
| 694 |
|
|
| 695 |
|
#if defined(__MSYS__) || defined(__MINGW32__) |
| 696 |
|
ret = semop(semid, sops, 3); |
| 697 |
|
#else |
| 698 |
timeout.tv_sec = wait_sec; |
timeout.tv_sec = wait_sec; |
| 699 |
timeout.tv_nsec = 0; |
timeout.tv_nsec = 0; |
| 700 |
|
|
| 701 |
ret = semtimedop(semid, sops, 3, &timeout); |
ret = semtimedop(semid, sops, 3, &timeout); |
| 702 |
|
#endif |
| 703 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 704 |
{ |
{ |
| 705 |
log_error("semtimedop(lock write) error %d\n", errno); |
log_error("semop(lock write) error %d\n", errno); |
| 706 |
} |
} |
| 707 |
|
|
| 708 |
return ret; |
return ret; |