| 3 |
* section_list |
* section_list |
| 4 |
* - data models and basic operations of section and article |
* - data models and basic operations of section and article |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 by Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "log.h" |
#include "log.h" |
| 14 |
#include "section_list.h" |
#include "section_list.h" |
| 15 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 36 |
}; |
}; |
| 37 |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
| 38 |
|
|
| 39 |
#define SECTION_TRY_LOCK_WAIT_TIME 1 // second |
enum _section_list_constant_t |
| 40 |
#define SECTION_TRY_LOCK_TIMES 10 |
{ |
| 41 |
|
SECTION_TRY_LOCK_WAIT_TIME = 1, // second |
| 42 |
|
SECTION_TRY_LOCK_TIMES = 10, |
| 43 |
|
|
| 44 |
#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 |
| 45 |
#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) |
| 46 |
#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), |
| 47 |
|
|
| 48 |
#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 |
| 49 |
|
|
| 50 |
#define SID_STR_LEN 5 // 32-bit + NULL |
SID_STR_LEN = 5, // 32-bit + NULL |
| 51 |
|
}; |
| 52 |
|
|
| 53 |
struct article_block_t |
struct article_block_t |
| 54 |
{ |
{ |
| 55 |
ARTICLE articles[ARTICLE_PER_BLOCK]; |
ARTICLE articles[BBS_article_count_per_block]; |
| 56 |
int article_count; |
int article_count; |
| 57 |
struct article_block_t *p_next_block; |
struct article_block_t *p_next_block; |
| 58 |
}; |
}; |
| 398 |
return NULL; |
return NULL; |
| 399 |
} |
} |
| 400 |
|
|
| 401 |
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) |
| 402 |
{ |
{ |
| 403 |
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); |
| 404 |
return NULL; |
return NULL; |
| 405 |
} |
} |
| 406 |
|
|
| 407 |
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]; |
| 408 |
|
|
| 409 |
if (index % ARTICLE_PER_BLOCK >= p_block->article_count) |
if (index % BBS_article_count_per_block >= p_block->article_count) |
| 410 |
{ |
{ |
| 411 |
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); |
| 412 |
return NULL; |
return NULL; |
| 413 |
} |
} |
| 414 |
|
|
| 415 |
return (p_block->articles + (index % ARTICLE_PER_BLOCK)); |
return (p_block->articles + (index % BBS_article_count_per_block)); |
| 416 |
} |
} |
| 417 |
|
|
| 418 |
extern int section_list_init(const char *filename) |
extern int section_list_init(const char *filename) |
| 774 |
} |
} |
| 775 |
|
|
| 776 |
if (p_article_block_pool->block_count == 0 || |
if (p_article_block_pool->block_count == 0 || |
| 777 |
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) |
| 778 |
{ |
{ |
| 779 |
if ((p_block = pop_free_article_block()) == NULL) |
if ((p_block = pop_free_article_block()) == NULL) |
| 780 |
{ |
{ |
| 784 |
|
|
| 785 |
if (p_article_block_pool->block_count > 0) |
if (p_article_block_pool->block_count > 0) |
| 786 |
{ |
{ |
| 787 |
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; |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
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; |
| 1307 |
return -1; |
return -1; |
| 1308 |
} |
} |
| 1309 |
|
|
| 1310 |
ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK + |
ret = (p_article_block_pool->block_count - 1) * BBS_article_count_per_block + |
| 1311 |
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; |
| 1312 |
|
|
| 1313 |
return ret; |
return ret; |