/[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.53 by sysadm, Tue Nov 4 14:58:56 2025 UTC Revision 1.55 by sysadm, Wed Nov 5 04:19:21 2025 UTC
# Line 32  union semun Line 32  union semun
32  };  };
33  #endif // #ifdef _SEM_SEMUN_UNDEFINED  #endif // #ifdef _SEM_SEMUN_UNDEFINED
34    
35  #define SECTION_TRY_LOCK_WAIT_TIME 1 // second  enum _section_list_constant_t
36  #define SECTION_TRY_LOCK_TIMES 10  {
37            SECTION_TRY_LOCK_WAIT_TIME = 1, // second
38            SECTION_TRY_LOCK_TIMES = 10,
39    
40  #define ARTICLE_BLOCK_PER_SHM 1000               // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate          ARTICLE_BLOCK_PER_SHM = 1000,           // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
41  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 80 // limited by length (8-bit) of proj_id in ftok(path, proj_id)          ARTICLE_BLOCK_SHM_COUNT_LIMIT = 80, // limited by length (8-bit) of proj_id in ftok(path, proj_id)
42  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)          ARTICLE_BLOCK_PER_POOL = (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT),
43    
44  #define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of moving topic between sections          CALCULATE_PAGE_THRESHOLD = 100, // Adjust to tune performance of moving topic between sections
45    
46  #define SID_STR_LEN 5 // 32-bit + NULL          SID_STR_LEN = 5, // 32-bit + NULL
47    };
48    
49  struct article_block_t  struct article_block_t
50  {  {
51          ARTICLE articles[ARTICLE_PER_BLOCK];          ARTICLE articles[BBS_article_count_per_block];
52          int article_count;          int article_count;
53          struct article_block_t *p_next_block;          struct article_block_t *p_next_block;
54  };  };
# Line 391  ARTICLE *article_block_find_by_index(int Line 394  ARTICLE *article_block_find_by_index(int
394                  return NULL;                  return NULL;
395          }          }
396    
397          if (index < 0 || index / ARTICLE_PER_BLOCK >= p_article_block_pool->block_count)          if (index < 0 || index / BBS_article_count_per_block >= p_article_block_pool->block_count)
398          {          {
399                  log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)\n", index, p_article_block_pool->block_count);                  log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)\n", index, p_article_block_pool->block_count);
400                  return NULL;                  return NULL;
401          }          }
402    
403          p_block = p_article_block_pool->p_block[index / ARTICLE_PER_BLOCK];          p_block = p_article_block_pool->p_block[index / BBS_article_count_per_block];
404    
405          if (index % ARTICLE_PER_BLOCK >= p_block->article_count)          if (index % BBS_article_count_per_block >= p_block->article_count)
406          {          {
407                  log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)\n", index, p_block->article_count);                  log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)\n", index, p_block->article_count);
408                  return NULL;                  return NULL;
409          }          }
410    
411          return (p_block->articles + (index % ARTICLE_PER_BLOCK));          return (p_block->articles + (index % BBS_article_count_per_block));
412  }  }
413    
414  extern int section_list_init(const char *filename)  extern int section_list_init(const char *filename)
# Line 767  int section_list_append_article(SECTION_ Line 770  int section_list_append_article(SECTION_
770          }          }
771    
772          if (p_article_block_pool->block_count == 0 ||          if (p_article_block_pool->block_count == 0 ||
773                  p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= ARTICLE_PER_BLOCK)                  p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= BBS_article_count_per_block)
774          {          {
775                  if ((p_block = pop_free_article_block()) == NULL)                  if ((p_block = pop_free_article_block()) == NULL)
776                  {                  {
# Line 777  int section_list_append_article(SECTION_ Line 780  int section_list_append_article(SECTION_
780    
781                  if (p_article_block_pool->block_count > 0)                  if (p_article_block_pool->block_count > 0)
782                  {                  {
783                          last_aid = p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->articles[ARTICLE_PER_BLOCK - 1].aid;                          last_aid = p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->articles[BBS_article_count_per_block - 1].aid;
784                  }                  }
785    
786                  p_article_block_pool->p_block[p_article_block_pool->block_count] = p_block;                  p_article_block_pool->p_block[p_article_block_pool->block_count] = p_block;
# Line 1300  int article_block_article_count(void) Line 1303  int article_block_article_count(void)
1303                  return -1;                  return -1;
1304          }          }
1305    
1306          ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK +          ret = (p_article_block_pool->block_count - 1) * BBS_article_count_per_block +
1307                    p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count;                    p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count;
1308    
1309          return ret;          return ret;


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

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