| 47 |
{ |
{ |
| 48 |
USER_LIST_TRY_LOCK_WAIT_TIME = 1, // second |
USER_LIST_TRY_LOCK_WAIT_TIME = 1, // second |
| 49 |
USER_LIST_TRY_LOCK_TIMES = 10, |
USER_LIST_TRY_LOCK_TIMES = 10, |
| 50 |
|
USER_LIST_DEAD_LOCK_TIMEOUT = 15, // second |
| 51 |
}; |
}; |
| 52 |
|
|
| 53 |
struct user_list_pool_t |
struct user_list_pool_t |
| 105 |
static int user_list_rw_unlock(void); |
static int user_list_rw_unlock(void); |
| 106 |
static int user_list_rd_lock(void); |
static int user_list_rd_lock(void); |
| 107 |
static int user_list_rw_lock(void); |
static int user_list_rw_lock(void); |
| 108 |
|
#ifndef HAVE_SYSTEM_V |
| 109 |
|
static int user_list_reset_lock(void); |
| 110 |
|
#endif |
| 111 |
|
|
| 112 |
static int user_list_load(MYSQL *db, USER_LIST *p_list); |
static int user_list_load(MYSQL *db, USER_LIST *p_list); |
| 113 |
static int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list); |
static int user_online_list_load(MYSQL *db, USER_ONLINE_LIST *p_online_list); |
| 913 |
{ |
{ |
| 914 |
int timer = 0; |
int timer = 0; |
| 915 |
int ret = -1; |
int ret = -1; |
| 916 |
|
time_t tm_first_failure = 0; |
| 917 |
|
|
| 918 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 919 |
{ |
{ |
| 934 |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
| 935 |
{ |
{ |
| 936 |
log_error("user_list_try_rd_lock() tried %d times\n", timer); |
log_error("user_list_try_rd_lock() tried %d times\n", timer); |
| 937 |
|
|
| 938 |
|
if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) |
| 939 |
|
{ |
| 940 |
|
log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); |
| 941 |
|
#ifndef HAVE_SYSTEM_V |
| 942 |
|
user_list_reset_lock(); |
| 943 |
|
log_error("Reset POSIX semaphore to resolve dead lock\n"); |
| 944 |
|
#endif |
| 945 |
|
break; |
| 946 |
|
} |
| 947 |
} |
} |
| 948 |
usleep(100 * 1000); // 0.1 second |
usleep(100 * 1000); // 0.1 second |
| 949 |
} |
} |
| 961 |
{ |
{ |
| 962 |
int timer = 0; |
int timer = 0; |
| 963 |
int ret = -1; |
int ret = -1; |
| 964 |
|
time_t tm_first_failure = 0; |
| 965 |
|
|
| 966 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 967 |
{ |
{ |
| 982 |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
| 983 |
{ |
{ |
| 984 |
log_error("user_list_try_rw_lock() tried %d times\n", timer); |
log_error("user_list_try_rw_lock() tried %d times\n", timer); |
| 985 |
|
|
| 986 |
|
if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) |
| 987 |
|
{ |
| 988 |
|
log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); |
| 989 |
|
#ifndef HAVE_SYSTEM_V |
| 990 |
|
user_list_reset_lock(); |
| 991 |
|
log_error("Reset POSIX semaphore to resolve dead lock\n"); |
| 992 |
|
#endif |
| 993 |
|
break; |
| 994 |
|
} |
| 995 |
} |
} |
| 996 |
usleep(100 * 1000); // 0.1 second |
usleep(100 * 1000); // 0.1 second |
| 997 |
} |
} |
| 1005 |
return ret; |
return ret; |
| 1006 |
} |
} |
| 1007 |
|
|
| 1008 |
|
#ifndef HAVE_SYSTEM_V |
| 1009 |
|
int user_list_reset_lock(void) |
| 1010 |
|
{ |
| 1011 |
|
if (p_user_list_pool == NULL) |
| 1012 |
|
{ |
| 1013 |
|
log_error("p_user_list_pool not initialized\n"); |
| 1014 |
|
return -1; |
| 1015 |
|
} |
| 1016 |
|
|
| 1017 |
|
if (sem_destroy(&(p_user_list_pool->sem)) == -1) |
| 1018 |
|
{ |
| 1019 |
|
log_error("sem_destroy() error (%d)\n", errno); |
| 1020 |
|
} |
| 1021 |
|
|
| 1022 |
|
p_user_list_pool->read_lock_count = 0; |
| 1023 |
|
p_user_list_pool->write_lock_count = 0; |
| 1024 |
|
|
| 1025 |
|
if (sem_init(&(p_user_list_pool->sem), 1, 1) == -1) |
| 1026 |
|
{ |
| 1027 |
|
log_error("sem_init() error (%d)\n", errno); |
| 1028 |
|
} |
| 1029 |
|
|
| 1030 |
|
return 0; |
| 1031 |
|
} |
| 1032 |
|
#endif |
| 1033 |
|
|
| 1034 |
int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_page_count) |
int query_user_list(int page_id, USER_INFO *p_users, int *p_user_count, int *p_page_count) |
| 1035 |
{ |
{ |
| 1036 |
int ret = 0; |
int ret = 0; |