/[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.37 by sysadm, Tue Nov 18 14:43:35 2025 UTC Revision 1.39 by sysadm, Thu Nov 20 01:54:18 2025 UTC
# Line 17  Line 17 
17  #include "user_list.h"  #include "user_list.h"
18  #include "user_stat.h"  #include "user_stat.h"
19  #include <errno.h>  #include <errno.h>
20    #include <fcntl.h>
21  #include <stdlib.h>  #include <stdlib.h>
22  #include <string.h>  #include <string.h>
23  #include <time.h>  #include <time.h>
 #include <sys/ipc.h>  
24  #include <sys/mman.h>  #include <sys/mman.h>
25  #include <sys/param.h>  #include <sys/param.h>
26  #include <sys/sem.h>  #include <sys/sem.h>
27  #include <sys/shm.h>  #include <sys/stat.h>
28    
29  #if defined(_SEM_SEMUN_UNDEFINED) || defined(__CYGWIN__)  #if defined(_SEM_SEMUN_UNDEFINED) || defined(__CYGWIN__)
30  union semun  union semun
# Line 45  enum _user_list_constant_t Line 45  enum _user_list_constant_t
45    
46  struct user_list_pool_t  struct user_list_pool_t
47  {  {
48          int shmid;          size_t shm_size;
49          int semid;          int semid;
50          USER_LIST user_list[2];          USER_LIST user_list[2];
51          int user_list_index_current;          int user_list_index_current;
# Line 58  struct user_list_pool_t Line 58  struct user_list_pool_t
58  };  };
59  typedef struct user_list_pool_t USER_LIST_POOL;  typedef struct user_list_pool_t USER_LIST_POOL;
60    
61    static char user_list_shm_name[FILE_PATH_LEN];
62  static USER_LIST_POOL *p_user_list_pool = NULL;  static USER_LIST_POOL *p_user_list_pool = NULL;
63  static TRIE_NODE *p_trie_action_dict = NULL;  static TRIE_NODE *p_trie_action_dict = NULL;
64    
# Line 85  const USER_ACTION_MAP user_action_map[] Line 86  const USER_ACTION_MAP user_action_map[]
86    
87  const int user_action_map_size = sizeof(user_action_map) / sizeof(USER_ACTION_MAP);  const int user_action_map_size = sizeof(user_action_map) / sizeof(USER_ACTION_MAP);
88    
89  static int user_list_try_rd_lock(int semid, int wait_sec);  static int user_list_try_rd_lock(int wait_sec);
90  static int user_list_try_rw_lock(int semid, int wait_sec);  static int user_list_try_rw_lock(int wait_sec);
91  static int user_list_rd_unlock(int semid);  static int user_list_rd_unlock(void);
92  static int user_list_rw_unlock(int semid);  static int user_list_rw_unlock(void);
93  static int user_list_rd_lock(int semid);  static int user_list_rd_lock(void);
94  static int user_list_rw_lock(int semid);  static int user_list_rw_lock(void);
95    
96  static int user_list_load(MYSQL *db, USER_LIST *p_list);  static int user_list_load(MYSQL *db, USER_LIST *p_list);
97  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 388  int user_login_count_load(MYSQL *db) Line 389  int user_login_count_load(MYSQL *db)
389    
390  int user_list_pool_init(const char *filename)  int user_list_pool_init(const char *filename)
391  {  {
392          int shmid;          char filepath[FILE_PATH_LEN];
393          int semid;          int fd;
         int proj_id;  
         key_t key;  
394          size_t size;          size_t size;
395          void *p_shm;          void *p_shm;
396            int proj_id;
397            key_t key;
398            int semid;
399          union semun arg;          union semun arg;
400          int i;          int i;
401    
# Line 419  int user_list_pool_init(const char *file Line 421  int user_list_pool_init(const char *file
421          }          }
422    
423          // Allocate shared memory          // Allocate shared memory
424          proj_id = (int)(time(NULL) % getpid());          size = sizeof(USER_LIST_POOL);
425          key = ftok(filename, proj_id);  
426          if (key == -1)          strncpy(filepath, filename, sizeof(filepath) - 1);
427            filepath[sizeof(filepath) - 1] = '\0';
428            snprintf(user_list_shm_name, sizeof(user_list_shm_name), "/USER_LIST_SHM_%s", basename(filepath));
429    
430            if (shm_unlink(user_list_shm_name) == -1 && errno != ENOENT)
431          {          {
432                  log_error("ftok(%s %d) error (%d)\n", filename, proj_id, errno);                  log_error("shm_unlink(%s) error (%d)\n", user_list_shm_name, errno);
433                  return -2;                  return -2;
434          }          }
435    
436          size = sizeof(USER_LIST_POOL);          if ((fd = shm_open(user_list_shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)
         shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);  
         if (shmid == -1)  
437          {          {
438                  log_error("shmget(size = %d) error (%d)\n", size, errno);                  log_error("shm_open(%s) error (%d)\n", user_list_shm_name, errno);
439                  return -3;                  return -2;
440          }          }
441          p_shm = shmat(shmid, NULL, 0);          if (ftruncate(fd, (off_t)size) == -1)
         if (p_shm == (void *)-1)  
442          {          {
443                  log_error("shmat(shmid=%d) error (%d)\n", shmid, errno);                  log_error("ftruncate(size=%d) error (%d)\n", size, errno);
444                  return -3;                  close(fd);
445                    return -2;
446            }
447    
448            p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L);
449            if (p_shm == MAP_FAILED)
450            {
451                    log_error("mmap() error (%d)\n", errno);
452                    close(fd);
453                    return -2;
454            }
455    
456            if (close(fd) < 0)
457            {
458                    log_error("close(fd) error (%d)\n", errno);
459                    return -1;
460          }          }
461    
462          p_user_list_pool = p_shm;          p_user_list_pool = p_shm;
463          p_user_list_pool->shmid = shmid;          p_user_list_pool->shm_size = size;
464    
465          // Allocate semaphore as user list pool lock          // Allocate semaphore as user list pool lock
466            proj_id = (int)(time(NULL) % getpid());
467            key = ftok(filename, proj_id);
468            if (key == -1)
469            {
470                    log_error("ftok(%s %d) error (%d)\n", filename, proj_id, errno);
471                    return -2;
472            }
473    
474          size = 2; // r_sem and w_sem          size = 2; // r_sem and w_sem
475          semid = semget(key, (int)size, IPC_CREAT | IPC_EXCL | 0600);          semid = semget(key, (int)size, IPC_CREAT | IPC_EXCL | 0600);
476          if (semid == -1)          if (semid == -1)
# Line 481  int user_list_pool_init(const char *file Line 507  int user_list_pool_init(const char *file
507          return 0;          return 0;
508  }  }
509    
510  void user_list_pool_cleanup(void)  int user_list_pool_cleanup(void)
511  {  {
         int shmid;  
   
512          if (p_user_list_pool == NULL)          if (p_user_list_pool == NULL)
513          {          {
514                  return;                  return -1;
         }  
   
         shmid = p_user_list_pool->shmid;  
   
         if (semctl(p_user_list_pool->semid, 0, IPC_RMID) == -1)  
         {  
                 log_error("semctl(semid = %d, IPC_RMID) error (%d)\n", p_user_list_pool->semid, errno);  
515          }          }
516    
517          if (shmdt(p_user_list_pool) == -1)          detach_user_list_pool_shm();
         {  
                 log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);  
         }  
518    
519          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)          if (shm_unlink(user_list_shm_name) == -1 && errno != ENOENT)
520          {          {
521                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shm_unlink(%s) error (%d)\n", user_list_shm_name, errno);
522                    return -2;
523          }          }
524    
525          p_user_list_pool = NULL;          user_list_shm_name[0] = '\0';
526    
527          if (p_trie_action_dict != NULL)          if (p_trie_action_dict != NULL)
528          {          {
# Line 515  void user_list_pool_cleanup(void) Line 530  void user_list_pool_cleanup(void)
530    
531                  p_trie_action_dict = NULL;                  p_trie_action_dict = NULL;
532          }          }
533    
534            return 0;
535  }  }
536    
537  int set_user_list_pool_shm_readonly(void)  int set_user_list_pool_shm_readonly(void)
538  {  {
539          int shmid;          if (p_user_list_pool != NULL && mprotect(p_user_list_pool, p_user_list_pool->shm_size, PROT_READ) < 0)
         void *p_shm;  
   
         if (p_user_list_pool == NULL)  
540          {          {
541                  log_error("p_user_list_pool not initialized\n");                  log_error("mprotect() error (%d)\n", errno);
542                  return -1;                  return -1;
543          }          }
544    
         shmid = p_user_list_pool->shmid;  
   
         // Remap shared memory in read-only mode  
 #if defined(__CYGWIN__)  
         if (shmdt(p_user_list_pool) == -1)  
         {  
                 log_error("shmdt(user_list_pool) error (%d)\n", errno);  
                 return -1;  
         }  
         p_shm = shmat(shmid, p_user_list_pool, SHM_RDONLY);  
 #else  
         p_shm = shmat(shmid, p_user_list_pool, SHM_RDONLY | SHM_REMAP);  
 #endif  
         if (p_shm == (void *)-1)  
         {  
                 log_error("shmat(user_list_pool shmid = %d) error (%d)\n", shmid, errno);  
                 return -3;  
         }  
   
         p_user_list_pool = p_shm;  
   
545          return 0;          return 0;
546  }  }
547    
548  int detach_user_list_pool_shm(void)  int detach_user_list_pool_shm(void)
549  {  {
550          if (p_user_list_pool != NULL && shmdt(p_user_list_pool) == -1)          if (p_user_list_pool != NULL && munmap(p_user_list_pool, p_user_list_pool->shm_size) < 0)
551          {          {
552                  log_error("shmdt(user_list_pool) error (%d)\n", errno);                  log_error("munmap() error (%d)\n", errno);
553                  return -1;                  return -1;
554          }          }
555    
# Line 613  int user_list_pool_reload(int online_use Line 606  int user_list_pool_reload(int online_use
606          mysql_close(db);          mysql_close(db);
607          db = NULL;          db = NULL;
608    
609          if (user_list_rw_lock(p_user_list_pool->semid) < 0)          if (user_list_rw_lock() < 0)
610          {          {
611                  log_error("user_list_rw_lock() error\n");                  log_error("user_list_rw_lock() error\n");
612                  ret = -3;                  ret = -3;
# Line 635  int user_list_pool_reload(int online_use Line 628  int user_list_pool_reload(int online_use
628                  p_user_list_pool->user_list_index_new = tmp;                  p_user_list_pool->user_list_index_new = tmp;
629          }          }
630    
631          if (user_list_rw_unlock(p_user_list_pool->semid) < 0)          if (user_list_rw_unlock() < 0)
632          {          {
633                  log_error("user_list_rw_unlock() error\n");                  log_error("user_list_rw_unlock() error\n");
634                  ret = -3;                  ret = -3;
# Line 648  cleanup: Line 641  cleanup:
641          return ret;          return ret;
642  }  }
643    
644  int user_list_try_rd_lock(int semid, int wait_sec)  int user_list_try_rd_lock(int wait_sec)
645  {  {
646          struct sembuf sops[2];          struct sembuf sops[2];
647  #if !defined(__CYGWIN__)  #ifndef __CYGWIN__
648          struct timespec timeout;          struct timespec timeout;
649  #endif  #endif
650          int ret;          int ret;
651    
652            if (p_user_list_pool == NULL)
653            {
654                    log_error("p_user_list_pool not initialized\n");
655                    return -1;
656            }
657    
658          sops[0].sem_num = 1; // w_sem          sops[0].sem_num = 1; // w_sem
659          sops[0].sem_op = 0;      // wait until unlocked          sops[0].sem_op = 0;      // wait until unlocked
660          sops[0].sem_flg = 0;          sops[0].sem_flg = 0;
# Line 664  int user_list_try_rd_lock(int semid, int Line 663  int user_list_try_rd_lock(int semid, int
663          sops[1].sem_op = 1;                     // lock          sops[1].sem_op = 1;                     // lock
664          sops[1].sem_flg = SEM_UNDO; // undo on terminate          sops[1].sem_flg = SEM_UNDO; // undo on terminate
665    
666  #if defined(__CYGWIN__)  #ifdef __CYGWIN__
667          ret = semop(semid, sops, 2);          ret = semop(p_user_list_pool->semid, sops, 2);
668  #else  #else
669          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;
670          timeout.tv_nsec = 0;          timeout.tv_nsec = 0;
671    
672          ret = semtimedop(semid, sops, 2, &timeout);          ret = semtimedop(p_user_list_pool->semid, sops, 2, &timeout);
673  #endif  #endif
674          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
675          {          {
# Line 680  int user_list_try_rd_lock(int semid, int Line 679  int user_list_try_rd_lock(int semid, int
679          return ret;          return ret;
680  }  }
681    
682  int user_list_try_rw_lock(int semid, int wait_sec)  int user_list_try_rw_lock(int wait_sec)
683  {  {
684          struct sembuf sops[3];          struct sembuf sops[3];
685  #if !defined(__CYGWIN__)  #ifndef __CYGWIN__
686          struct timespec timeout;          struct timespec timeout;
687  #endif  #endif
688          int ret;          int ret;
689    
690            if (p_user_list_pool == NULL)
691            {
692                    log_error("p_user_list_pool not initialized\n");
693                    return -1;
694            }
695    
696          sops[0].sem_num = 1; // w_sem          sops[0].sem_num = 1; // w_sem
697          sops[0].sem_op = 0;      // wait until unlocked          sops[0].sem_op = 0;      // wait until unlocked
698          sops[0].sem_flg = 0;          sops[0].sem_flg = 0;
# Line 700  int user_list_try_rw_lock(int semid, int Line 705  int user_list_try_rw_lock(int semid, int
705          sops[2].sem_op = 0;      // wait until unlocked          sops[2].sem_op = 0;      // wait until unlocked
706          sops[2].sem_flg = 0;          sops[2].sem_flg = 0;
707    
708  #if defined(__CYGWIN__)  #ifdef __CYGWIN__
709          ret = semop(semid, sops, 3);          ret = semop(p_user_list_pool->semid, sops, 3);
710  #else  #else
711          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;
712          timeout.tv_nsec = 0;          timeout.tv_nsec = 0;
713    
714          ret = semtimedop(semid, sops, 3, &timeout);          ret = semtimedop(p_user_list_pool->semid, sops, 3, &timeout);
715  #endif  #endif
716          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
717          {          {
# Line 716  int user_list_try_rw_lock(int semid, int Line 721  int user_list_try_rw_lock(int semid, int
721          return ret;          return ret;
722  }  }
723    
724  int user_list_rd_unlock(int semid)  int user_list_rd_unlock(void)
725  {  {
726          struct sembuf sops[2];          struct sembuf sops[2];
727          int ret;          int ret;
728    
729            if (p_user_list_pool == NULL)
730            {
731                    log_error("p_user_list_pool not initialized\n");
732                    return -1;
733            }
734    
735          sops[0].sem_num = 0;                                     // r_sem          sops[0].sem_num = 0;                                     // r_sem
736          sops[0].sem_op = -1;                                     // unlock          sops[0].sem_op = -1;                                     // unlock
737          sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait          sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait
738    
739          ret = semop(semid, sops, 1);          ret = semop(p_user_list_pool->semid, sops, 1);
740          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
741          {          {
742                  log_error("semop(unlock read) error %d\n", errno);                  log_error("semop(unlock read) error %d\n", errno);
# Line 734  int user_list_rd_unlock(int semid) Line 745  int user_list_rd_unlock(int semid)
745          return ret;          return ret;
746  }  }
747    
748  int user_list_rw_unlock(int semid)  int user_list_rw_unlock(void)
749  {  {
750          struct sembuf sops[1];          struct sembuf sops[1];
751          int ret;          int ret;
752    
753            if (p_user_list_pool == NULL)
754            {
755                    log_error("p_user_list_pool not initialized\n");
756                    return -1;
757            }
758    
759          sops[0].sem_num = 1;                                     // w_sem          sops[0].sem_num = 1;                                     // w_sem
760          sops[0].sem_op = -1;                                     // unlock          sops[0].sem_op = -1;                                     // unlock
761          sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait          sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait
762    
763          ret = semop(semid, sops, 1);          ret = semop(p_user_list_pool->semid, sops, 1);
764          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
765          {          {
766                  log_error("semop(unlock write) error %d\n", errno);                  log_error("semop(unlock write) error %d\n", errno);
# Line 752  int user_list_rw_unlock(int semid) Line 769  int user_list_rw_unlock(int semid)
769          return ret;          return ret;
770  }  }
771    
772  int user_list_rd_lock(int semid)  int user_list_rd_lock(void)
773  {  {
774          int timer = 0;          int timer = 0;
775          int ret = -1;          int ret = -1;
776    
777            if (p_user_list_pool == NULL)
778            {
779                    log_error("p_user_list_pool not initialized\n");
780                    return -1;
781            }
782    
783          while (!SYS_server_exit)          while (!SYS_server_exit)
784          {          {
785                  ret = user_list_try_rd_lock(semid, USER_LIST_TRY_LOCK_WAIT_TIME);                  ret = user_list_try_rd_lock(USER_LIST_TRY_LOCK_WAIT_TIME);
786                  if (ret == 0) // success                  if (ret == 0) // success
787                  {                  {
788                          break;                          break;
# Line 782  int user_list_rd_lock(int semid) Line 805  int user_list_rd_lock(int semid)
805          return ret;          return ret;
806  }  }
807    
808  int user_list_rw_lock(int semid)  int user_list_rw_lock(void)
809  {  {
810          int timer = 0;          int timer = 0;
811          int ret = -1;          int ret = -1;
812    
813            if (p_user_list_pool == NULL)
814            {
815                    log_error("p_user_list_pool not initialized\n");
816                    return -1;
817            }
818    
819          while (!SYS_server_exit)          while (!SYS_server_exit)
820          {          {
821                  ret = user_list_try_rw_lock(semid, USER_LIST_TRY_LOCK_WAIT_TIME);                  ret = user_list_try_rw_lock(USER_LIST_TRY_LOCK_WAIT_TIME);
822                  if (ret == 0) // success                  if (ret == 0) // success
823                  {                  {
824                          break;                          break;
# Line 826  int query_user_list(int page_id, USER_IN Line 855  int query_user_list(int page_id, USER_IN
855          *p_page_count = 0;          *p_page_count = 0;
856    
857          // acquire lock of user list          // acquire lock of user list
858          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
859          {          {
860                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
861                  return -2;                  return -2;
# Line 859  int query_user_list(int page_id, USER_IN Line 888  int query_user_list(int page_id, USER_IN
888    
889  cleanup:  cleanup:
890          // release lock of user list          // release lock of user list
891          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
892          {          {
893                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
894                  ret = -1;                  ret = -1;
# Line 882  int query_user_online_list(int page_id, Line 911  int query_user_online_list(int page_id,
911          *p_page_count = 0;          *p_page_count = 0;
912    
913          // acquire lock of user list          // acquire lock of user list
914          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
915          {          {
916                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
917                  return -2;                  return -2;
# Line 914  int query_user_online_list(int page_id, Line 943  int query_user_online_list(int page_id,
943    
944  cleanup:  cleanup:
945          // release lock of user list          // release lock of user list
946          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
947          {          {
948                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
949                  ret = -1;                  ret = -1;
# Line 932  int get_user_list_count(int *p_user_cnt) Line 961  int get_user_list_count(int *p_user_cnt)
961          }          }
962    
963          // acquire lock of user list          // acquire lock of user list
964          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
965          {          {
966                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
967                  return -2;                  return -2;
# Line 941  int get_user_list_count(int *p_user_cnt) Line 970  int get_user_list_count(int *p_user_cnt)
970          *p_user_cnt = p_user_list_pool->user_list[p_user_list_pool->user_list_index_current].user_count;          *p_user_cnt = p_user_list_pool->user_list[p_user_list_pool->user_list_index_current].user_count;
971    
972          // release lock of user list          // release lock of user list
973          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
974          {          {
975                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
976                  return -2;                  return -2;
# Line 959  int get_user_online_list_count(int *p_us Line 988  int get_user_online_list_count(int *p_us
988          }          }
989    
990          // acquire lock of user list          // acquire lock of user list
991          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
992          {          {
993                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
994                  return -2;                  return -2;
# Line 969  int get_user_online_list_count(int *p_us Line 998  int get_user_online_list_count(int *p_us
998          *p_guest_cnt = p_user_list_pool->user_online_list[p_user_list_pool->user_online_list_index_current].guest_count;          *p_guest_cnt = p_user_list_pool->user_online_list[p_user_list_pool->user_online_list_index_current].guest_count;
999    
1000          // release lock of user list          // release lock of user list
1001          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1002          {          {
1003                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1004                  return -2;                  return -2;
# Line 1002  int query_user_info(int32_t id, USER_INF Line 1031  int query_user_info(int32_t id, USER_INF
1031          }          }
1032    
1033          // acquire lock of user list          // acquire lock of user list
1034          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1035          {          {
1036                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1037                  return -2;                  return -2;
# Line 1015  int query_user_info(int32_t id, USER_INF Line 1044  int query_user_info(int32_t id, USER_INF
1044          }          }
1045    
1046          // release lock of user list          // release lock of user list
1047          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1048          {          {
1049                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1050                  ret = -1;                  ret = -1;
# Line 1039  int query_user_info_by_uid(int32_t uid, Line 1068  int query_user_info_by_uid(int32_t uid,
1068          }          }
1069    
1070          // acquire lock of user list          // acquire lock of user list
1071          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1072          {          {
1073                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1074                  return -2;                  return -2;
# Line 1081  int query_user_info_by_uid(int32_t uid, Line 1110  int query_user_info_by_uid(int32_t uid,
1110          }          }
1111    
1112          // release lock of user list          // release lock of user list
1113          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1114          {          {
1115                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1116                  ret = -1;                  ret = -1;
# Line 1111  int query_user_info_by_username(const ch Line 1140  int query_user_info_by_username(const ch
1140          prefix_len = strlen(username_prefix);          prefix_len = strlen(username_prefix);
1141    
1142          // acquire lock of user list          // acquire lock of user list
1143          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1144          {          {
1145                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1146                  return -2;                  return -2;
# Line 1215  int query_user_info_by_username(const ch Line 1244  int query_user_info_by_username(const ch
1244    
1245  cleanup:  cleanup:
1246          // release lock of user list          // release lock of user list
1247          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1248          {          {
1249                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1250                  ret = -1;                  ret = -1;
# Line 1235  int query_user_online_info(int32_t id, U Line 1264  int query_user_online_info(int32_t id, U
1264          }          }
1265    
1266          // acquire lock of user list          // acquire lock of user list
1267          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1268          {          {
1269                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1270                  return -2;                  return -2;
# Line 1248  int query_user_online_info(int32_t id, U Line 1277  int query_user_online_info(int32_t id, U
1277          }          }
1278    
1279          // release lock of user list          // release lock of user list
1280          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1281          {          {
1282                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1283                  ret = -1;                  ret = -1;
# Line 1277  int query_user_online_info_by_uid(int32_ Line 1306  int query_user_online_info_by_uid(int32_
1306          *p_user_cnt = 0;          *p_user_cnt = 0;
1307    
1308          // acquire lock of user list          // acquire lock of user list
1309          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1310          {          {
1311                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1312                  return -2;                  return -2;
# Line 1339  int query_user_online_info_by_uid(int32_ Line 1368  int query_user_online_info_by_uid(int32_
1368          }          }
1369    
1370          // release lock of user list          // release lock of user list
1371          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1372          {          {
1373                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1374                  ret = -1;                  ret = -1;
# Line 1363  int get_user_id_list(int32_t *p_uid_list Line 1392  int get_user_id_list(int32_t *p_uid_list
1392          }          }
1393    
1394          // acquire lock of user list          // acquire lock of user list
1395          if (user_list_rd_lock(p_user_list_pool->semid) < 0)          if (user_list_rd_lock() < 0)
1396          {          {
1397                  log_error("user_list_rd_lock() error\n");                  log_error("user_list_rd_lock() error\n");
1398                  return -2;                  return -2;
# Line 1397  int get_user_id_list(int32_t *p_uid_list Line 1426  int get_user_id_list(int32_t *p_uid_list
1426          *p_user_cnt = i;          *p_user_cnt = i;
1427    
1428          // release lock of user list          // release lock of user list
1429          if (user_list_rd_unlock(p_user_list_pool->semid) < 0)          if (user_list_rd_unlock() < 0)
1430          {          {
1431                  log_error("user_list_rd_unlock() error\n");                  log_error("user_list_rd_unlock() error\n");
1432                  ret = -1;                  ret = -1;


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

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