| 23 |
#include <time.h> |
#include <time.h> |
| 24 |
#include <sys/mman.h> |
#include <sys/mman.h> |
| 25 |
#include <sys/param.h> |
#include <sys/param.h> |
|
#include <sys/sem.h> |
|
| 26 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 27 |
|
|
| 28 |
#if defined(_SEM_SEMUN_UNDEFINED) || defined(__CYGWIN__) |
#ifdef HAVE_SYSTEM_V |
| 29 |
|
#include <sys/sem.h> |
| 30 |
|
|
| 31 |
|
#ifdef _SEM_SEMUN_UNDEFINED |
| 32 |
union semun |
union semun |
| 33 |
{ |
{ |
| 34 |
int val; /* Value for SETVAL */ |
int val; /* Value for SETVAL */ |
| 35 |
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ |
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ |
| 36 |
unsigned short *array; /* Array for GETALL, SETALL */ |
unsigned short *array; /* Array for GETALL, SETALL */ |
| 37 |
struct seminfo *__buf; /* Buffer for IPC_INFO |
struct seminfo *__buf; /* Buffer for IPC_INFO |
| 38 |
(Linux-specific) */ |
(Linux-specific) */ |
| 39 |
}; |
}; |
| 40 |
#endif // #if defined(_SEM_SEMUN_UNDEFINED) |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
| 41 |
|
|
| 42 |
|
#else |
| 43 |
|
#include <semaphore.h> |
| 44 |
|
#endif |
| 45 |
|
|
| 46 |
enum _user_list_constant_t |
enum _user_list_constant_t |
| 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 |
| 54 |
{ |
{ |
| 55 |
size_t shm_size; |
size_t shm_size; |
| 56 |
|
#ifndef HAVE_SYSTEM_V |
| 57 |
|
sem_t sem; |
| 58 |
|
uint16_t read_lock_count; |
| 59 |
|
uint16_t write_lock_count; |
| 60 |
|
#else |
| 61 |
int semid; |
int semid; |
| 62 |
|
#endif |
| 63 |
USER_LIST user_list[2]; |
USER_LIST user_list[2]; |
| 64 |
int user_list_index_current; |
int user_list_index_current; |
| 65 |
int user_list_index_new; |
int user_list_index_new; |
| 91 |
{"MENU", "菜单选择"}, |
{"MENU", "菜单选择"}, |
| 92 |
{"POST_ARTICLE", "撰写文章"}, |
{"POST_ARTICLE", "撰写文章"}, |
| 93 |
{"REPLY_ARTICLE", "回复文章"}, |
{"REPLY_ARTICLE", "回复文章"}, |
| 94 |
|
{"TOP10_MENU", "十大热门"}, |
| 95 |
{"USER_LIST", "查花名册"}, |
{"USER_LIST", "查花名册"}, |
| 96 |
{"USER_ONLINE", "环顾四周"}, |
{"USER_ONLINE", "环顾四周"}, |
| 97 |
{"VIEW_ARTICLE", "阅读文章"}, |
{"VIEW_ARTICLE", "阅读文章"}, |
| 106 |
static int user_list_rw_unlock(void); |
static int user_list_rw_unlock(void); |
| 107 |
static int user_list_rd_lock(void); |
static int user_list_rd_lock(void); |
| 108 |
static int user_list_rw_lock(void); |
static int user_list_rw_lock(void); |
| 109 |
|
#ifndef HAVE_SYSTEM_V |
| 110 |
|
static int user_list_reset_lock(void); |
| 111 |
|
#endif |
| 112 |
|
|
| 113 |
static int user_list_load(MYSQL *db, USER_LIST *p_list); |
static int user_list_load(MYSQL *db, USER_LIST *p_list); |
| 114 |
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); |
| 240 |
|
|
| 241 |
qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
qsort(p_list->index_uid, (size_t)i, sizeof(USER_INFO_INDEX_UID), user_info_index_uid_comp); |
| 242 |
|
|
| 243 |
#ifdef _DEBUG |
log_debug("Rebuild index of %d users, last_uid=%d\n", i, p_list->users[i - 1].uid); |
|
log_error("Rebuild index of %d users, last_uid=%d\n", i, p_list->users[i - 1].uid); |
|
|
#endif |
|
| 244 |
} |
} |
| 245 |
|
|
| 246 |
p_list->user_count = i; |
p_list->user_count = i; |
| 247 |
|
|
| 248 |
#ifdef _DEBUG |
log_debug("Loaded %d users\n", p_list->user_count); |
|
log_error("Loaded %d users\n", p_list->user_count); |
|
|
#endif |
|
| 249 |
|
|
| 250 |
cleanup: |
cleanup: |
| 251 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 406 |
int fd; |
int fd; |
| 407 |
size_t size; |
size_t size; |
| 408 |
void *p_shm; |
void *p_shm; |
| 409 |
|
#ifdef HAVE_SYSTEM_V |
| 410 |
int proj_id; |
int proj_id; |
| 411 |
key_t key; |
key_t key; |
| 412 |
int semid; |
int semid; |
| 413 |
union semun arg; |
union semun arg; |
| 414 |
|
#endif |
| 415 |
int i; |
int i; |
| 416 |
|
|
| 417 |
if (p_user_list_pool != NULL || p_trie_action_dict != NULL) |
if (p_user_list_pool != NULL || p_trie_action_dict != NULL) |
| 478 |
p_user_list_pool->shm_size = size; |
p_user_list_pool->shm_size = size; |
| 479 |
|
|
| 480 |
// Allocate semaphore as user list pool lock |
// Allocate semaphore as user list pool lock |
| 481 |
|
#ifndef HAVE_SYSTEM_V |
| 482 |
|
if (sem_init(&(p_user_list_pool->sem), 1, 1) == -1) |
| 483 |
|
{ |
| 484 |
|
log_error("sem_init() error (%d)\n", errno); |
| 485 |
|
return -3; |
| 486 |
|
} |
| 487 |
|
|
| 488 |
|
p_user_list_pool->read_lock_count = 0; |
| 489 |
|
p_user_list_pool->write_lock_count = 0; |
| 490 |
|
#else |
| 491 |
proj_id = (int)(time(NULL) % getpid()); |
proj_id = (int)(time(NULL) % getpid()); |
| 492 |
key = ftok(filename, proj_id); |
key = ftok(filename, proj_id); |
| 493 |
if (key == -1) |
if (key == -1) |
| 516 |
} |
} |
| 517 |
|
|
| 518 |
p_user_list_pool->semid = semid; |
p_user_list_pool->semid = semid; |
| 519 |
|
#endif |
| 520 |
|
|
| 521 |
// Set user counts to 0 |
// Set user counts to 0 |
| 522 |
p_user_list_pool->user_list[0].user_count = 0; |
p_user_list_pool->user_list[0].user_count = 0; |
| 540 |
return; |
return; |
| 541 |
} |
} |
| 542 |
|
|
| 543 |
|
#ifdef HAVE_SYSTEM_V |
| 544 |
if (semctl(p_user_list_pool->semid, 0, IPC_RMID) == -1) |
if (semctl(p_user_list_pool->semid, 0, IPC_RMID) == -1) |
| 545 |
{ |
{ |
| 546 |
log_error("semctl(semid = %d, IPC_RMID) error (%d)\n", p_user_list_pool->semid, errno); |
log_error("semctl(semid = %d, IPC_RMID) error (%d)\n", p_user_list_pool->semid, errno); |
| 547 |
} |
} |
| 548 |
|
#else |
| 549 |
|
if (sem_destroy(&(p_user_list_pool->sem)) == -1) |
| 550 |
|
{ |
| 551 |
|
log_error("sem_destroy() error (%d)\n", errno); |
| 552 |
|
} |
| 553 |
|
#endif |
| 554 |
|
|
| 555 |
detach_user_list_pool_shm(); |
detach_user_list_pool_shm(); |
| 556 |
|
|
| 678 |
|
|
| 679 |
int user_list_try_rd_lock(int wait_sec) |
int user_list_try_rd_lock(int wait_sec) |
| 680 |
{ |
{ |
| 681 |
|
#ifdef HAVE_SYSTEM_V |
| 682 |
struct sembuf sops[2]; |
struct sembuf sops[2]; |
|
#ifndef __CYGWIN__ |
|
|
struct timespec timeout; |
|
| 683 |
#endif |
#endif |
| 684 |
int ret; |
struct timespec timeout; |
| 685 |
|
int ret = 0; |
| 686 |
|
|
| 687 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 688 |
{ |
{ |
| 690 |
return -1; |
return -1; |
| 691 |
} |
} |
| 692 |
|
|
| 693 |
|
timeout.tv_sec = wait_sec; |
| 694 |
|
timeout.tv_nsec = 0; |
| 695 |
|
|
| 696 |
|
#ifdef HAVE_SYSTEM_V |
| 697 |
sops[0].sem_num = 1; // w_sem |
sops[0].sem_num = 1; // w_sem |
| 698 |
sops[0].sem_op = 0; // wait until unlocked |
sops[0].sem_op = 0; // wait until unlocked |
| 699 |
sops[0].sem_flg = 0; |
sops[0].sem_flg = 0; |
| 702 |
sops[1].sem_op = 1; // lock |
sops[1].sem_op = 1; // lock |
| 703 |
sops[1].sem_flg = SEM_UNDO; // undo on terminate |
sops[1].sem_flg = SEM_UNDO; // undo on terminate |
| 704 |
|
|
|
#ifdef __CYGWIN__ |
|
|
ret = semop(p_user_list_pool->semid, sops, 2); |
|
|
#else |
|
|
timeout.tv_sec = wait_sec; |
|
|
timeout.tv_nsec = 0; |
|
|
|
|
| 705 |
ret = semtimedop(p_user_list_pool->semid, sops, 2, &timeout); |
ret = semtimedop(p_user_list_pool->semid, sops, 2, &timeout); |
|
#endif |
|
| 706 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 707 |
{ |
{ |
| 708 |
log_error("semop(lock read) error %d\n", errno); |
log_error("semop(lock read) error %d\n", errno); |
| 709 |
} |
} |
| 710 |
|
#else |
| 711 |
|
if (sem_timedwait(&(p_user_list_pool->sem), &timeout) == -1) |
| 712 |
|
{ |
| 713 |
|
if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) |
| 714 |
|
{ |
| 715 |
|
log_error("sem_timedwait() error %d\n", errno); |
| 716 |
|
} |
| 717 |
|
return -1; |
| 718 |
|
} |
| 719 |
|
|
| 720 |
|
if (p_user_list_pool->write_lock_count == 0) |
| 721 |
|
{ |
| 722 |
|
p_user_list_pool->read_lock_count++; |
| 723 |
|
} |
| 724 |
|
else |
| 725 |
|
{ |
| 726 |
|
errno = EAGAIN; |
| 727 |
|
ret = -1; |
| 728 |
|
} |
| 729 |
|
|
| 730 |
|
if (sem_post(&(p_user_list_pool->sem)) == -1) |
| 731 |
|
{ |
| 732 |
|
log_error("sem_post() error %d\n", errno); |
| 733 |
|
return -1; |
| 734 |
|
} |
| 735 |
|
#endif |
| 736 |
|
|
| 737 |
return ret; |
return ret; |
| 738 |
} |
} |
| 739 |
|
|
| 740 |
int user_list_try_rw_lock(int wait_sec) |
int user_list_try_rw_lock(int wait_sec) |
| 741 |
{ |
{ |
| 742 |
|
#ifdef HAVE_SYSTEM_V |
| 743 |
struct sembuf sops[3]; |
struct sembuf sops[3]; |
|
#ifndef __CYGWIN__ |
|
|
struct timespec timeout; |
|
| 744 |
#endif |
#endif |
| 745 |
int ret; |
struct timespec timeout; |
| 746 |
|
int ret = 0; |
| 747 |
|
|
| 748 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 749 |
{ |
{ |
| 751 |
return -1; |
return -1; |
| 752 |
} |
} |
| 753 |
|
|
| 754 |
|
timeout.tv_sec = wait_sec; |
| 755 |
|
timeout.tv_nsec = 0; |
| 756 |
|
|
| 757 |
|
#ifdef HAVE_SYSTEM_V |
| 758 |
sops[0].sem_num = 1; // w_sem |
sops[0].sem_num = 1; // w_sem |
| 759 |
sops[0].sem_op = 0; // wait until unlocked |
sops[0].sem_op = 0; // wait until unlocked |
| 760 |
sops[0].sem_flg = 0; |
sops[0].sem_flg = 0; |
| 767 |
sops[2].sem_op = 0; // wait until unlocked |
sops[2].sem_op = 0; // wait until unlocked |
| 768 |
sops[2].sem_flg = 0; |
sops[2].sem_flg = 0; |
| 769 |
|
|
|
#ifdef __CYGWIN__ |
|
|
ret = semop(p_user_list_pool->semid, sops, 3); |
|
|
#else |
|
|
timeout.tv_sec = wait_sec; |
|
|
timeout.tv_nsec = 0; |
|
|
|
|
| 770 |
ret = semtimedop(p_user_list_pool->semid, sops, 3, &timeout); |
ret = semtimedop(p_user_list_pool->semid, sops, 3, &timeout); |
|
#endif |
|
| 771 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 772 |
{ |
{ |
| 773 |
log_error("semop(lock write) error %d\n", errno); |
log_error("semop(lock write) error %d\n", errno); |
| 774 |
} |
} |
| 775 |
|
#else |
| 776 |
|
if (sem_timedwait(&(p_user_list_pool->sem), &timeout) == -1) |
| 777 |
|
{ |
| 778 |
|
if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) |
| 779 |
|
{ |
| 780 |
|
log_error("sem_timedwait() error %d\n", errno); |
| 781 |
|
} |
| 782 |
|
return -1; |
| 783 |
|
} |
| 784 |
|
|
| 785 |
|
if (p_user_list_pool->read_lock_count == 0 && p_user_list_pool->write_lock_count == 0) |
| 786 |
|
{ |
| 787 |
|
p_user_list_pool->write_lock_count++; |
| 788 |
|
} |
| 789 |
|
else |
| 790 |
|
{ |
| 791 |
|
errno = EAGAIN; |
| 792 |
|
ret = -1; |
| 793 |
|
} |
| 794 |
|
|
| 795 |
|
if (sem_post(&(p_user_list_pool->sem)) == -1) |
| 796 |
|
{ |
| 797 |
|
log_error("sem_post() error %d\n", errno); |
| 798 |
|
return -1; |
| 799 |
|
} |
| 800 |
|
#endif |
| 801 |
|
|
| 802 |
return ret; |
return ret; |
| 803 |
} |
} |
| 804 |
|
|
| 805 |
int user_list_rd_unlock(void) |
int user_list_rd_unlock(void) |
| 806 |
{ |
{ |
| 807 |
|
#ifdef HAVE_SYSTEM_V |
| 808 |
struct sembuf sops[2]; |
struct sembuf sops[2]; |
| 809 |
int ret; |
#endif |
| 810 |
|
int ret = 0; |
| 811 |
|
|
| 812 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 813 |
{ |
{ |
| 815 |
return -1; |
return -1; |
| 816 |
} |
} |
| 817 |
|
|
| 818 |
|
#ifdef HAVE_SYSTEM_V |
| 819 |
sops[0].sem_num = 0; // r_sem |
sops[0].sem_num = 0; // r_sem |
| 820 |
sops[0].sem_op = -1; // unlock |
sops[0].sem_op = -1; // unlock |
| 821 |
sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait |
sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait |
| 825 |
{ |
{ |
| 826 |
log_error("semop(unlock read) error %d\n", errno); |
log_error("semop(unlock read) error %d\n", errno); |
| 827 |
} |
} |
| 828 |
|
#else |
| 829 |
|
if (sem_wait(&(p_user_list_pool->sem)) == -1) |
| 830 |
|
{ |
| 831 |
|
if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) |
| 832 |
|
{ |
| 833 |
|
log_error("sem_wait() error %d\n", errno); |
| 834 |
|
} |
| 835 |
|
return -1; |
| 836 |
|
} |
| 837 |
|
|
| 838 |
|
if (p_user_list_pool->read_lock_count > 0) |
| 839 |
|
{ |
| 840 |
|
p_user_list_pool->read_lock_count--; |
| 841 |
|
} |
| 842 |
|
else |
| 843 |
|
{ |
| 844 |
|
log_error("read_lock_count already 0\n"); |
| 845 |
|
} |
| 846 |
|
|
| 847 |
|
if (sem_post(&(p_user_list_pool->sem)) == -1) |
| 848 |
|
{ |
| 849 |
|
log_error("sem_post() error %d\n", errno); |
| 850 |
|
return -1; |
| 851 |
|
} |
| 852 |
|
#endif |
| 853 |
|
|
| 854 |
return ret; |
return ret; |
| 855 |
} |
} |
| 856 |
|
|
| 857 |
int user_list_rw_unlock(void) |
int user_list_rw_unlock(void) |
| 858 |
{ |
{ |
| 859 |
|
#ifdef HAVE_SYSTEM_V |
| 860 |
struct sembuf sops[1]; |
struct sembuf sops[1]; |
| 861 |
int ret; |
#endif |
| 862 |
|
int ret = 0; |
| 863 |
|
|
| 864 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 865 |
{ |
{ |
| 867 |
return -1; |
return -1; |
| 868 |
} |
} |
| 869 |
|
|
| 870 |
|
#ifdef HAVE_SYSTEM_V |
| 871 |
sops[0].sem_num = 1; // w_sem |
sops[0].sem_num = 1; // w_sem |
| 872 |
sops[0].sem_op = -1; // unlock |
sops[0].sem_op = -1; // unlock |
| 873 |
sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait |
sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait |
| 877 |
{ |
{ |
| 878 |
log_error("semop(unlock write) error %d\n", errno); |
log_error("semop(unlock write) error %d\n", errno); |
| 879 |
} |
} |
| 880 |
|
#else |
| 881 |
|
if (sem_wait(&(p_user_list_pool->sem)) == -1) |
| 882 |
|
{ |
| 883 |
|
if (errno != ETIMEDOUT && errno != EAGAIN && errno != EINTR) |
| 884 |
|
{ |
| 885 |
|
log_error("sem_wait() error %d\n", errno); |
| 886 |
|
} |
| 887 |
|
return -1; |
| 888 |
|
} |
| 889 |
|
|
| 890 |
|
if (p_user_list_pool->write_lock_count > 0) |
| 891 |
|
{ |
| 892 |
|
p_user_list_pool->write_lock_count--; |
| 893 |
|
} |
| 894 |
|
else |
| 895 |
|
{ |
| 896 |
|
log_error("write_lock_count already 0\n"); |
| 897 |
|
} |
| 898 |
|
|
| 899 |
|
if (sem_post(&(p_user_list_pool->sem)) == -1) |
| 900 |
|
{ |
| 901 |
|
log_error("sem_post() error %d\n", errno); |
| 902 |
|
return -1; |
| 903 |
|
} |
| 904 |
|
#endif |
| 905 |
|
|
| 906 |
return ret; |
return ret; |
| 907 |
} |
} |
| 910 |
{ |
{ |
| 911 |
int timer = 0; |
int timer = 0; |
| 912 |
int ret = -1; |
int ret = -1; |
| 913 |
|
time_t tm_first_failure = 0; |
| 914 |
|
|
| 915 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 916 |
{ |
{ |
| 931 |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
| 932 |
{ |
{ |
| 933 |
log_error("user_list_try_rd_lock() tried %d times\n", timer); |
log_error("user_list_try_rd_lock() tried %d times\n", timer); |
| 934 |
|
|
| 935 |
|
if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) |
| 936 |
|
{ |
| 937 |
|
log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); |
| 938 |
|
#ifndef HAVE_SYSTEM_V |
| 939 |
|
user_list_reset_lock(); |
| 940 |
|
log_error("Reset POSIX semaphore to resolve dead lock\n"); |
| 941 |
|
#endif |
| 942 |
|
break; |
| 943 |
|
} |
| 944 |
} |
} |
| 945 |
|
usleep(100 * 1000); // 0.1 second |
| 946 |
} |
} |
| 947 |
else // failed |
else // failed |
| 948 |
{ |
{ |
| 958 |
{ |
{ |
| 959 |
int timer = 0; |
int timer = 0; |
| 960 |
int ret = -1; |
int ret = -1; |
| 961 |
|
time_t tm_first_failure = 0; |
| 962 |
|
|
| 963 |
if (p_user_list_pool == NULL) |
if (p_user_list_pool == NULL) |
| 964 |
{ |
{ |
| 979 |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
if (timer % USER_LIST_TRY_LOCK_TIMES == 0) |
| 980 |
{ |
{ |
| 981 |
log_error("user_list_try_rw_lock() tried %d times\n", timer); |
log_error("user_list_try_rw_lock() tried %d times\n", timer); |
| 982 |
|
|
| 983 |
|
if (time(NULL) - tm_first_failure >= USER_LIST_DEAD_LOCK_TIMEOUT) |
| 984 |
|
{ |
| 985 |
|
log_error("Unable to acquire rw_lock for %d seconds\n", time(NULL) - tm_first_failure); |
| 986 |
|
#ifndef HAVE_SYSTEM_V |
| 987 |
|
user_list_reset_lock(); |
| 988 |
|
log_error("Reset POSIX semaphore to resolve dead lock\n"); |
| 989 |
|
#endif |
| 990 |
|
break; |
| 991 |
|
} |
| 992 |
} |
} |
| 993 |
|
usleep(100 * 1000); // 0.1 second |
| 994 |
} |
} |
| 995 |
else // failed |
else // failed |
| 996 |
{ |
{ |
| 1002 |
return ret; |
return ret; |
| 1003 |
} |
} |
| 1004 |
|
|
| 1005 |
|
#ifndef HAVE_SYSTEM_V |
| 1006 |
|
int user_list_reset_lock(void) |
| 1007 |
|
{ |
| 1008 |
|
if (p_user_list_pool == NULL) |
| 1009 |
|
{ |
| 1010 |
|
log_error("p_user_list_pool not initialized\n"); |
| 1011 |
|
return -1; |
| 1012 |
|
} |
| 1013 |
|
|
| 1014 |
|
if (sem_destroy(&(p_user_list_pool->sem)) == -1) |
| 1015 |
|
{ |
| 1016 |
|
log_error("sem_destroy() error (%d)\n", errno); |
| 1017 |
|
} |
| 1018 |
|
|
| 1019 |
|
p_user_list_pool->read_lock_count = 0; |
| 1020 |
|
p_user_list_pool->write_lock_count = 0; |
| 1021 |
|
|
| 1022 |
|
if (sem_init(&(p_user_list_pool->sem), 1, 1) == -1) |
| 1023 |
|
{ |
| 1024 |
|
log_error("sem_init() error (%d)\n", errno); |
| 1025 |
|
} |
| 1026 |
|
|
| 1027 |
|
return 0; |
| 1028 |
|
} |
| 1029 |
|
#endif |
| 1030 |
|
|
| 1031 |
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) |
| 1032 |
{ |
{ |
| 1033 |
int ret = 0; |
int ret = 0; |
| 1357 |
|
|
| 1358 |
if (strncasecmp(username_prefix, p_user_list_pool->user_list[p_user_list_pool->user_list_index_current].users[left].username, prefix_len) == 0) // Found |
if (strncasecmp(username_prefix, p_user_list_pool->user_list[p_user_list_pool->user_list_index_current].users[left].username, prefix_len) == 0) // Found |
| 1359 |
{ |
{ |
| 1360 |
#ifdef _DEBUG |
log_debug("Debug: match found, pos=%d\n", left); |
|
log_error("Debug: match found, pos=%d\n", left); |
|
|
#endif |
|
| 1361 |
|
|
| 1362 |
left_save = left; |
left_save = left; |
| 1363 |
right = left; |
right = left; |
| 1383 |
} |
} |
| 1384 |
} |
} |
| 1385 |
|
|
| 1386 |
#ifdef _DEBUG |
log_debug("Debug: first match found, pos=%d\n", right); |
|
log_error("Debug: first match found, pos=%d\n", right); |
|
|
#endif |
|
| 1387 |
|
|
| 1388 |
left = left_save; |
left = left_save; |
| 1389 |
left_save = right; |
left_save = right; |
| 1409 |
} |
} |
| 1410 |
} |
} |
| 1411 |
|
|
| 1412 |
#ifdef _DEBUG |
log_debug("Debug: last match found, pos=%d\n", left); |
|
log_error("Debug: last match found, pos=%d\n", left); |
|
|
#endif |
|
| 1413 |
|
|
| 1414 |
right = left; |
right = left; |
| 1415 |
left = left_save; |
left = left_save; |