/[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.4 by sysadm, Tue Oct 21 12:35:03 2025 UTC Revision 1.5 by sysadm, Tue Oct 21 13:00:55 2025 UTC
# Line 54  typedef struct user_list_pool_t USER_LIS Line 54  typedef struct user_list_pool_t USER_LIS
54    
55  static USER_LIST_POOL *p_user_list_pool = NULL;  static USER_LIST_POOL *p_user_list_pool = NULL;
56    
57    static int user_list_try_rd_lock(int semid, int wait_sec);
58    static int user_list_try_rw_lock(int semid, int wait_sec);
59    static int user_list_rd_unlock(int semid);
60    static int user_list_rw_unlock(int semid);
61    static int user_list_rd_lock(int semid);
62    static int user_list_rw_lock(int semid);
63    
64  int user_list_load(MYSQL *db, USER_LIST *p_list)  int user_list_load(MYSQL *db, USER_LIST *p_list)
65  {  {
66      MYSQL_RES *rs = NULL;      MYSQL_RES *rs = NULL;
# Line 296  int user_list_pool_reload(void) Line 303  int user_list_pool_reload(void)
303    
304      mysql_close(db);      mysql_close(db);
305    
306      if (user_list_rw_lock() < 0)      if (user_list_rw_lock(p_user_list_pool->semid) < 0)
307      {      {
308          log_error("user_list_rw_lock() error\n");          log_error("user_list_rw_lock() error\n");
309          return -3;          return -3;
# Line 307  int user_list_pool_reload(void) Line 314  int user_list_pool_reload(void)
314      p_user_list_pool->p_current = p_user_list_pool->p_new;      p_user_list_pool->p_current = p_user_list_pool->p_new;
315      p_user_list_pool->p_new = p_tmp;      p_user_list_pool->p_new = p_tmp;
316    
317      if (user_list_rw_unlock() < 0)      if (user_list_rw_unlock(p_user_list_pool->semid) < 0)
318      {      {
319          log_error("user_list_rw_unlock() error\n");          log_error("user_list_rw_unlock() error\n");
320          return -3;          return -3;
# Line 316  int user_list_pool_reload(void) Line 323  int user_list_pool_reload(void)
323      return 0;      return 0;
324  }  }
325    
326  int user_list_try_rd_lock(int wait_sec)  int user_list_try_rd_lock(int semid, int wait_sec)
327  {  {
328      struct sembuf sops[2];      struct sembuf sops[2];
329      struct timespec timeout;      struct timespec timeout;
# Line 333  int user_list_try_rd_lock(int wait_sec) Line 340  int user_list_try_rd_lock(int wait_sec)
340      timeout.tv_sec = wait_sec;      timeout.tv_sec = wait_sec;
341      timeout.tv_nsec = 0;      timeout.tv_nsec = 0;
342    
343      ret = semtimedop(p_user_list_pool->semid, sops, 2, &timeout);      ret = semtimedop(semid, sops, 2, &timeout);
344      if (ret == -1 && errno != EAGAIN && errno != EINTR)      if (ret == -1 && errno != EAGAIN && errno != EINTR)
345      {      {
346          log_error("semtimedop(lock read) error %d\n", errno);          log_error("semtimedop(lock read) error %d\n", errno);
# Line 342  int user_list_try_rd_lock(int wait_sec) Line 349  int user_list_try_rd_lock(int wait_sec)
349      return ret;      return ret;
350  }  }
351    
352  int user_list_try_rw_lock(int wait_sec)  int user_list_try_rw_lock(int semid, int wait_sec)
353  {  {
354      struct sembuf sops[3];      struct sembuf sops[3];
355      struct timespec timeout;      struct timespec timeout;
# Line 363  int user_list_try_rw_lock(int wait_sec) Line 370  int user_list_try_rw_lock(int wait_sec)
370      timeout.tv_sec = wait_sec;      timeout.tv_sec = wait_sec;
371      timeout.tv_nsec = 0;      timeout.tv_nsec = 0;
372    
373      ret = semtimedop(p_user_list_pool->semid, sops, 3, &timeout);      ret = semtimedop(semid, sops, 3, &timeout);
374      if (ret == -1 && errno != EAGAIN && errno != EINTR)      if (ret == -1 && errno != EAGAIN && errno != EINTR)
375      {      {
376          log_error("semtimedop(lock write) error %d\n", errno);          log_error("semtimedop(lock write) error %d\n", errno);
# Line 372  int user_list_try_rw_lock(int wait_sec) Line 379  int user_list_try_rw_lock(int wait_sec)
379      return ret;      return ret;
380  }  }
381    
382  int user_list_rd_unlock(void)  int user_list_rd_unlock(int semid)
383  {  {
384      struct sembuf sops[2];      struct sembuf sops[2];
385      int ret;      int ret;
# Line 381  int user_list_rd_unlock(void) Line 388  int user_list_rd_unlock(void)
388      sops[0].sem_op = -1;                     // unlock      sops[0].sem_op = -1;                     // unlock
389      sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait      sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait
390    
391      ret = semop(p_user_list_pool->semid, sops, 1);      ret = semop(semid, sops, 1);
392      if (ret == -1 && errno != EAGAIN && errno != EINTR)      if (ret == -1 && errno != EAGAIN && errno != EINTR)
393      {      {
394          log_error("semop(unlock read) error %d\n", errno);          log_error("semop(unlock read) error %d\n", errno);
# Line 390  int user_list_rd_unlock(void) Line 397  int user_list_rd_unlock(void)
397      return ret;      return ret;
398  }  }
399    
400  int user_list_rw_unlock(void)  int user_list_rw_unlock(int semid)
401  {  {
402      struct sembuf sops[1];      struct sembuf sops[1];
403      int ret;      int ret;
# Line 399  int user_list_rw_unlock(void) Line 406  int user_list_rw_unlock(void)
406      sops[0].sem_op = -1;                     // unlock      sops[0].sem_op = -1;                     // unlock
407      sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait      sops[0].sem_flg = IPC_NOWAIT | SEM_UNDO; // no wait
408    
409      ret = semop(p_user_list_pool->semid, sops, 1);      ret = semop(semid, sops, 1);
410      if (ret == -1 && errno != EAGAIN && errno != EINTR)      if (ret == -1 && errno != EAGAIN && errno != EINTR)
411      {      {
412          log_error("semop(unlock write) error %d\n", errno);          log_error("semop(unlock write) error %d\n", errno);
# Line 408  int user_list_rw_unlock(void) Line 415  int user_list_rw_unlock(void)
415      return ret;      return ret;
416  }  }
417    
418  int user_list_rd_lock(void)  int user_list_rd_lock(int semid)
419  {  {
420      int timer = 0;      int timer = 0;
421      int ret = -1;      int ret = -1;
422    
423      while (!SYS_server_exit)      while (!SYS_server_exit)
424      {      {
425          ret = user_list_try_rd_lock(USER_LIST_TRY_LOCK_WAIT_TIME);          ret = user_list_try_rd_lock(semid, USER_LIST_TRY_LOCK_WAIT_TIME);
426          if (ret == 0) // success          if (ret == 0) // success
427          {          {
428              break;              break;
# Line 438  int user_list_rd_lock(void) Line 445  int user_list_rd_lock(void)
445      return ret;      return ret;
446  }  }
447    
448  int user_list_rw_lock(void)  int user_list_rw_lock(int semid)
449  {  {
450      int timer = 0;      int timer = 0;
451      int ret = -1;      int ret = -1;
452    
453      while (!SYS_server_exit)      while (!SYS_server_exit)
454      {      {
455          ret = user_list_try_rw_lock(USER_LIST_TRY_LOCK_WAIT_TIME);          ret = user_list_try_rw_lock(semid, USER_LIST_TRY_LOCK_WAIT_TIME);
456          if (ret == 0) // success          if (ret == 0) // success
457          {          {
458              break;              break;
# Line 479  int query_user_list(int page_id, USER_IN Line 486  int query_user_list(int page_id, USER_IN
486      }      }
487    
488      // acquire lock of user list      // acquire lock of user list
489      if (user_list_rd_lock() < 0)      if (user_list_rd_lock(p_user_list_pool->semid) < 0)
490      {      {
491          log_error("user_list_rd_lock() error\n");          log_error("user_list_rd_lock() error\n");
492          return -2;          return -2;
# Line 512  int query_user_list(int page_id, USER_IN Line 519  int query_user_list(int page_id, USER_IN
519    
520  cleanup:  cleanup:
521      // release lock of user list      // release lock of user list
522      if (user_list_rd_unlock() < 0)      if (user_list_rd_unlock(p_user_list_pool->semid) < 0)
523      {      {
524          log_error("user_list_rd_unlock() error\n");          log_error("user_list_rd_unlock() error\n");
525          ret = -1;          ret = -1;
# Line 535  int query_user_info(int32_t uid, USER_IN Line 542  int query_user_info(int32_t uid, USER_IN
542      }      }
543    
544      // acquire lock of user list      // acquire lock of user list
545      if (user_list_rd_lock() < 0)      if (user_list_rd_lock(p_user_list_pool->semid) < 0)
546      {      {
547          log_error("user_list_rd_lock() error\n");          log_error("user_list_rd_lock() error\n");
548          return -2;          return -2;
# Line 569  int query_user_info(int32_t uid, USER_IN Line 576  int query_user_info(int32_t uid, USER_IN
576      }      }
577    
578      // release lock of user list      // release lock of user list
579      if (user_list_rd_unlock() < 0)      if (user_list_rd_unlock(p_user_list_pool->semid) < 0)
580      {      {
581          log_error("user_list_rd_unlock() error\n");          log_error("user_list_rd_unlock() error\n");
582          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