/[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.2 by sysadm, Tue Oct 21 11:11:28 2025 UTC Revision 1.4 by sysadm, Tue Oct 21 12:35:03 2025 UTC
# Line 274  int user_list_pool_reload(void) Line 274  int user_list_pool_reload(void)
274  {  {
275      MYSQL *db = NULL;      MYSQL *db = NULL;
276      USER_LIST *p_tmp;      USER_LIST *p_tmp;
     int ret = 0;  
277    
278      if (p_user_list_pool == NULL)      if (p_user_list_pool == NULL)
279      {      {
# Line 289  int user_list_pool_reload(void) Line 288  int user_list_pool_reload(void)
288          return -1;          return -1;
289      }      }
290    
291      if (user_list_rw_lock() < 0)      if (user_list_load(db, p_user_list_pool->p_new) < 0)
292      {      {
293          log_error("user_list_rw_lock() error\n");          log_error("user_list_rw_lock() error\n");
294          return -2;          return -2;
295      }      }
296    
297      if (user_list_load(db, p_user_list_pool->p_new) < 0)      mysql_close(db);
298    
299        if (user_list_rw_lock() < 0)
300      {      {
301          log_error("user_list_rw_lock() error\n");          log_error("user_list_rw_lock() error\n");
302          ret = -3;          return -3;
         goto cleanup;  
303      }      }
304    
305      // Swap p_current and p_new      // Swap p_current and p_new
# Line 307  int user_list_pool_reload(void) Line 307  int user_list_pool_reload(void)
307      p_user_list_pool->p_current = p_user_list_pool->p_new;      p_user_list_pool->p_current = p_user_list_pool->p_new;
308      p_user_list_pool->p_new = p_tmp;      p_user_list_pool->p_new = p_tmp;
309    
 cleanup:  
310      if (user_list_rw_unlock() < 0)      if (user_list_rw_unlock() < 0)
311      {      {
312          log_error("user_list_rw_unlock() error\n");          log_error("user_list_rw_unlock() error\n");
313          ret = -2;          return -3;
314      }      }
315    
316      mysql_close(db);      return 0;
   
     return ret;  
317  }  }
318    
319  int user_list_try_rd_lock(int wait_sec)  int user_list_try_rd_lock(int wait_sec)
# Line 517  cleanup: Line 514  cleanup:
514      // release lock of user list      // release lock of user list
515      if (user_list_rd_unlock() < 0)      if (user_list_rd_unlock() < 0)
516      {      {
517            log_error("user_list_rd_unlock() error\n");
518            ret = -1;
519        }
520    
521        return ret;
522    }
523    
524    int query_user_info(int32_t uid, USER_INFO *p_user)
525    {
526        int left;
527        int right;
528        int mid;
529        int ret = 0;
530    
531        if (p_user == NULL)
532        {
533            log_error("NULL pointer error\n");
534            return -1;
535        }
536    
537        // acquire lock of user list
538        if (user_list_rd_lock() < 0)
539        {
540            log_error("user_list_rd_lock() error\n");
541            return -2;
542        }
543    
544        left = 0;
545        right = p_user_list_pool->p_current->user_count - 1;
546    
547        while (left < right)
548        {
549            mid = (left + right) / 2;
550            if (uid < p_user_list_pool->p_current->users[mid].uid)
551            {
552                right = mid;
553            }
554            else if (uid > p_user_list_pool->p_current->users[mid].uid)
555            {
556                left = mid + 1;
557            }
558            else // if (uid == p_user_list_pool->p_current->users[mid].uid)
559            {
560                left = mid;
561                break;
562            }
563        }
564    
565        if (uid == p_user_list_pool->p_current->users[left].uid) // Found
566        {
567            *p_user = p_user_list_pool->p_current->users[left];
568            ret = 1;
569        }
570    
571        // release lock of user list
572        if (user_list_rd_unlock() < 0)
573        {
574          log_error("user_list_rd_unlock() error\n");          log_error("user_list_rd_unlock() error\n");
575          ret = -1;          ret = -1;
576      }      }


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

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