| 60 |
|
|
| 61 |
static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL; |
static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL; |
| 62 |
|
|
| 63 |
|
static int section_list_pool_shmid; |
| 64 |
static SECTION_LIST *p_section_list_pool = NULL; |
static SECTION_LIST *p_section_list_pool = NULL; |
| 65 |
static int section_list_count = 0; |
static int section_list_count = 0; |
| 66 |
static TRIE_NODE *p_trie_dict_section_list = NULL; |
static TRIE_NODE *p_trie_dict_section_list = NULL; |
| 312 |
return (p_block->articles + (index % ARTICLE_PER_BLOCK)); |
return (p_block->articles + (index % ARTICLE_PER_BLOCK)); |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_name) |
extern int section_list_pool_init(const char *filename) |
| 316 |
{ |
{ |
| 317 |
SECTION_LIST *p_section; |
int shmid; |
| 318 |
|
int proj_id; |
| 319 |
|
key_t key; |
| 320 |
|
size_t size; |
| 321 |
|
void *p_shm; |
| 322 |
|
|
| 323 |
|
if (p_section_list_pool == NULL || p_trie_dict_section_list == NULL) |
| 324 |
|
{ |
| 325 |
|
section_list_pool_cleanup(); |
| 326 |
|
} |
| 327 |
|
|
| 328 |
|
p_section_list_pool = calloc(BBS_max_section, sizeof(SECTION_LIST)); |
| 329 |
if (p_section_list_pool == NULL) |
if (p_section_list_pool == NULL) |
| 330 |
{ |
{ |
| 331 |
p_section_list_pool = calloc(BBS_max_section, sizeof(SECTION_LIST)); |
log_error("calloc(%d SECTION_LIST) OOM\n", BBS_max_section); |
| 332 |
if (p_section_list_pool == NULL) |
return -1; |
| 333 |
{ |
} |
|
log_error("calloc(%d SECTION_LIST) OOM\n", BBS_max_section); |
|
|
return NULL; |
|
|
} |
|
| 334 |
|
|
| 335 |
section_list_count = 0; |
proj_id = (int)(time(NULL) % getpid()); |
| 336 |
|
key = ftok(filename, proj_id); |
| 337 |
|
if (key == -1) |
| 338 |
|
{ |
| 339 |
|
log_error("ftok(%s, %d) error (%d)\n", filename, proj_id, errno); |
| 340 |
|
return -3; |
| 341 |
} |
} |
| 342 |
|
|
| 343 |
|
size = sizeof(shmid) + sizeof(SECTION_LIST) * BBS_max_section; |
| 344 |
|
shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600); |
| 345 |
|
if (shmid == -1) |
| 346 |
|
{ |
| 347 |
|
log_error("shmget(section_list_pool, size = %d) error (%d)\n", size, errno); |
| 348 |
|
return -3; |
| 349 |
|
} |
| 350 |
|
p_shm = shmat(shmid, NULL, 0); |
| 351 |
|
if (p_shm == (void *)-1) |
| 352 |
|
{ |
| 353 |
|
log_error("shmat(shmid = %d) error (%d)\n", shmid, errno); |
| 354 |
|
return -3; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
section_list_pool_shmid = shmid; |
| 358 |
|
p_section_list_pool = p_shm; |
| 359 |
|
section_list_count = 0; |
| 360 |
|
|
| 361 |
|
p_trie_dict_section_list = trie_dict_create(); |
| 362 |
if (p_trie_dict_section_list == NULL) |
if (p_trie_dict_section_list == NULL) |
| 363 |
{ |
{ |
| 364 |
p_trie_dict_section_list = trie_dict_create(); |
log_error("trie_dict_create() OOM\n", BBS_max_section); |
| 365 |
if (p_trie_dict_section_list == NULL) |
return -2; |
| 366 |
{ |
} |
| 367 |
log_error("trie_dict_create() OOM\n", BBS_max_section); |
|
| 368 |
return NULL; |
return 0; |
| 369 |
} |
} |
| 370 |
|
|
| 371 |
|
SECTION_LIST *section_list_create(int32_t sid, const char *sname, const char *stitle, const char *master_name) |
| 372 |
|
{ |
| 373 |
|
SECTION_LIST *p_section; |
| 374 |
|
|
| 375 |
|
if (p_section_list_pool == NULL || p_trie_dict_section_list == NULL) |
| 376 |
|
{ |
| 377 |
|
log_error("session_list_pool not initialized\n"); |
| 378 |
|
return NULL; |
| 379 |
} |
} |
| 380 |
|
|
| 381 |
if (section_list_count >= BBS_max_section) |
if (section_list_count >= BBS_max_section) |
| 382 |
{ |
{ |
| 383 |
log_error("section_list_count exceed limit %d\n", BBS_max_section); |
log_error("section_list_count exceed limit %d >= %d\n", section_list_count, BBS_max_section); |
| 384 |
return NULL; |
return NULL; |
| 385 |
} |
} |
| 386 |
|
|
| 423 |
p_section->last_page_visible_article_count = 0; |
p_section->last_page_visible_article_count = 0; |
| 424 |
} |
} |
| 425 |
|
|
| 426 |
void section_list_cleanup(void) |
void section_list_pool_cleanup(void) |
| 427 |
{ |
{ |
| 428 |
if (p_trie_dict_section_list != NULL) |
if (p_trie_dict_section_list != NULL) |
| 429 |
{ |
{ |
| 433 |
|
|
| 434 |
if (p_section_list_pool != NULL) |
if (p_section_list_pool != NULL) |
| 435 |
{ |
{ |
| 436 |
free(p_section_list_pool); |
if (shmdt(p_section_list_pool) == -1) |
| 437 |
|
{ |
| 438 |
|
log_error("shmdt(shmid = %d) error (%d)\n", section_list_pool_shmid, errno); |
| 439 |
|
} |
| 440 |
p_section_list_pool = NULL; |
p_section_list_pool = NULL; |
| 441 |
|
|
| 442 |
|
if (shmctl(section_list_pool_shmid, IPC_RMID, NULL) == -1) |
| 443 |
|
{ |
| 444 |
|
log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", section_list_pool_shmid, errno); |
| 445 |
|
} |
| 446 |
} |
} |
| 447 |
|
|
| 448 |
section_list_count = 0; |
section_list_count = 0; |