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

Diff of /lbbs/src/section_list.c

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

Revision 1.22 by sysadm, Sun May 25 23:47:36 2025 UTC Revision 1.24 by sysadm, Mon May 26 04:47:45 2025 UTC
# Line 41  union semun Line 41  union semun
41  };  };
42  #endif // #ifdef _SEM_SEMUN_UNDEFINED  #endif // #ifdef _SEM_SEMUN_UNDEFINED
43    
44    #define SECTION_TRY_LOCK_WAIT_TIME 1 // second
45    #define SECTION_TRY_LOCK_TIMES 10
46    
47  #define ARTICLE_BLOCK_PER_SHM 400                 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate  #define ARTICLE_BLOCK_PER_SHM 400                 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
48  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id)  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id)
49  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)
# Line 574  void section_list_cleanup(void) Line 577  void section_list_cleanup(void)
577  SECTION_LIST *section_list_find_by_name(const char *sname)  SECTION_LIST *section_list_find_by_name(const char *sname)
578  {  {
579          int64_t index;          int64_t index;
580            int ret;
581    
582          if (p_section_list_pool == NULL)          if (p_section_list_pool == NULL)
583          {          {
# Line 581  SECTION_LIST *section_list_find_by_name( Line 585  SECTION_LIST *section_list_find_by_name(
585                  return NULL;                  return NULL;
586          }          }
587    
588          if (trie_dict_get(p_section_list_pool->p_trie_dict_section_by_name, sname, &index) != 1)          ret = trie_dict_get(p_section_list_pool->p_trie_dict_section_by_name, sname, &index);
589            if (ret < 0)
590          {          {
591                  log_error("trie_dict_get(section, %s) error\n", sname);                  log_error("trie_dict_get(section, %s) error\n", sname);
592                  return NULL;                  return NULL;
593          }          }
594            else if (ret == 0)
595            {
596                    return NULL;
597            }
598    
599          return (p_section_list_pool->sections + index);          return (p_section_list_pool->sections + index);
600  }  }
# Line 593  SECTION_LIST *section_list_find_by_name( Line 602  SECTION_LIST *section_list_find_by_name(
602  SECTION_LIST *section_list_find_by_sid(int32_t sid)  SECTION_LIST *section_list_find_by_sid(int32_t sid)
603  {  {
604          int64_t index;          int64_t index;
605            int ret;
606          char sid_str[SID_STR_LEN];          char sid_str[SID_STR_LEN];
607    
608          if (p_section_list_pool == NULL)          if (p_section_list_pool == NULL)
# Line 603  SECTION_LIST *section_list_find_by_sid(i Line 613  SECTION_LIST *section_list_find_by_sid(i
613    
614          sid_to_str(sid, sid_str);          sid_to_str(sid, sid_str);
615    
616          if (trie_dict_get(p_section_list_pool->p_trie_dict_section_by_sid, sid_str, &index) != 1)          ret = trie_dict_get(p_section_list_pool->p_trie_dict_section_by_sid, sid_str, &index);
617            if (ret < 0)
618          {          {
619                  log_error("trie_dict_get(section, %d) error\n", sid);                  log_error("trie_dict_get(section, %d) error\n", sid);
620                  return NULL;                  return NULL;
621          }          }
622            else if (ret == 0)
623            {
624                    return NULL;
625            }
626    
627          return (p_section_list_pool->sections + index);          return (p_section_list_pool->sections + index);
628  }  }
# Line 1406  int section_list_rw_unlock(SECTION_LIST Line 1421  int section_list_rw_unlock(SECTION_LIST
1421          }          }
1422    
1423          return ret;          return ret;
1424    }
1425    
1426    int section_list_rd_lock(SECTION_LIST *p_section)
1427    {
1428            int timer = 0;
1429            int sid = (p_section == NULL ? 0 : p_section->sid);
1430            int ret = -1;
1431    
1432            while (!SYS_server_exit)
1433            {
1434                    ret = section_list_try_rd_lock(p_section, SECTION_TRY_LOCK_WAIT_TIME);
1435                    if (ret == 0) // success
1436                    {
1437                            break;
1438                    }
1439                    else if (errno == EAGAIN || errno == EINTR) // retry
1440                    {
1441                            timer++;
1442                            if (timer % SECTION_TRY_LOCK_TIMES == 0)
1443                            {
1444                                    log_error("section_list_rd_lock() tried %d times on section %d\n", sid, timer);
1445                            }
1446                    }
1447                    else // failed
1448                    {
1449                            log_error("section_list_rd_lock() failed on section %d\n", sid);
1450                            break;
1451                    }
1452            }
1453    
1454            return ret;
1455    }
1456    
1457    int section_list_rw_lock(SECTION_LIST *p_section)
1458    {
1459            int timer = 0;
1460            int sid = (p_section == NULL ? 0 : p_section->sid);
1461            int ret = -1;
1462    
1463            while (!SYS_server_exit)
1464            {
1465                    ret = section_list_try_rw_lock(p_section, SECTION_TRY_LOCK_WAIT_TIME);
1466                    if (ret == 0) // success
1467                    {
1468                            break;
1469                    }
1470                    else if (errno == EAGAIN || errno == EINTR) // retry
1471                    {
1472                            timer++;
1473                            if (timer % SECTION_TRY_LOCK_TIMES == 0)
1474                            {
1475                                    log_error("acquire_section_rw_lock() tried %d times on section %d\n", sid, timer);
1476                            }
1477                    }
1478                    else // failed
1479                    {
1480                            log_error("acquire_section_rw_lock() failed on section %d\n", sid);
1481                            break;
1482                    }
1483            }
1484    
1485            return ret;
1486  }  }


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

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