/[LeafOK_CVS]/lbbs/src/user_list.c
ViewVC logotype

Diff of /lbbs/src/user_list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.43 by sysadm, Thu Nov 20 10:20:51 2025 UTC Revision 1.44 by sysadm, Thu Nov 20 11:31:56 2025 UTC
# Line 47  enum _user_list_constant_t Line 47  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
# Line 104  static int user_list_rd_unlock(void); Line 105  static int user_list_rd_unlock(void);
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);
# Line 909  int user_list_rd_lock(void) Line 913  int user_list_rd_lock(void)
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          {          {
# Line 929  int user_list_rd_lock(void) Line 934  int user_list_rd_lock(void)
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                  }                  }
# Line 946  int user_list_rw_lock(void) Line 961  int user_list_rw_lock(void)
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          {          {
# Line 966  int user_list_rw_lock(void) Line 982  int user_list_rw_lock(void)
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                  }                  }
# Line 979  int user_list_rw_lock(void) Line 1005  int user_list_rw_lock(void)
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;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1