| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
file_section_list.c - description |
/* |
| 3 |
------------------- |
* test_section_list |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - tester for data models and basic operations of section and article |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
|
#include "section_list.h" |
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "log.h" |
#include "log.h" |
| 15 |
|
#include "section_list.h" |
| 16 |
|
#include "trie_dict.h" |
| 17 |
|
#include "user_list.h" |
| 18 |
|
#include <errno.h> |
| 19 |
#include <stdio.h> |
#include <stdio.h> |
| 20 |
#include <unistd.h> |
#include <unistd.h> |
|
#include <errno.h> |
|
| 21 |
|
|
| 22 |
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
static const char ARTICLE_BLOCK_SHM_FILE[] = "~article_block_shm.dat"; |
| 23 |
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
static const char SECTION_LIST_SHM_FILE[] = "~section_list_shm.dat"; |
| 24 |
|
static const char TRIE_DICT_SHM_FILE[] = "~trie_dict_shm.dat"; |
| 25 |
|
static const char USER_LIST_SHM_FILE[] = "~user_list_shm.dat"; |
| 26 |
|
|
| 27 |
const char *sname[] = { |
const char *sname[] = { |
| 28 |
"Test", |
"Test", |
| 31 |
|
|
| 32 |
const char *stitle[] = { |
const char *stitle[] = { |
| 33 |
" Test Section ", |
" Test Section ", |
| 34 |
"ĸABC", |
"字母组合ABC", |
| 35 |
"__123"}; |
"_数字_123"}; |
| 36 |
|
|
| 37 |
const char *master_name[] = { |
const char *master_name[] = { |
| 38 |
"sysadm", |
"sysadm", |
| 68 |
return -1; |
return -1; |
| 69 |
} |
} |
| 70 |
|
|
| 71 |
log_std_redirect(STDOUT_FILENO); |
log_common_redir(STDOUT_FILENO); |
| 72 |
log_err_redirect(STDERR_FILENO); |
log_error_redir(STDERR_FILENO); |
| 73 |
|
|
| 74 |
// - 1 to make blocks allocated is less than required, to trigger error handling |
// - 1 to make blocks allocated is less than required, to trigger error handling |
| 75 |
block_count = BBS_article_limit_per_section * BBS_max_section / ARTICLE_PER_BLOCK; |
block_count = BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block; |
| 76 |
|
|
| 77 |
if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL) |
if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL) |
| 78 |
{ |
{ |
| 79 |
log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE); |
log_error("fopen(%s) error", ARTICLE_BLOCK_SHM_FILE); |
| 80 |
return -1; |
return -1; |
| 81 |
} |
} |
| 82 |
fclose(fp); |
fclose(fp); |
| 83 |
|
|
| 84 |
if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL) |
if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL) |
| 85 |
{ |
{ |
| 86 |
log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE); |
log_error("fopen(%s) error", SECTION_LIST_SHM_FILE); |
| 87 |
|
return -1; |
| 88 |
|
} |
| 89 |
|
fclose(fp); |
| 90 |
|
|
| 91 |
|
if ((fp = fopen(TRIE_DICT_SHM_FILE, "w")) == NULL) |
| 92 |
|
{ |
| 93 |
|
log_error("fopen(%s) error", TRIE_DICT_SHM_FILE); |
| 94 |
return -1; |
return -1; |
| 95 |
} |
} |
| 96 |
fclose(fp); |
fclose(fp); |
| 97 |
|
|
| 98 |
|
if ((fp = fopen(USER_LIST_SHM_FILE, "w")) == NULL) |
| 99 |
|
{ |
| 100 |
|
log_error("fopen(%s) error", USER_LIST_SHM_FILE); |
| 101 |
|
return -1; |
| 102 |
|
} |
| 103 |
|
fclose(fp); |
| 104 |
|
|
| 105 |
|
if (trie_dict_init(TRIE_DICT_SHM_FILE, TRIE_NODE_PER_POOL) < 0) |
| 106 |
|
{ |
| 107 |
|
printf("trie_dict_init failed\n"); |
| 108 |
|
return -1; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0) |
if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0) |
| 112 |
{ |
{ |
| 113 |
log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count); |
log_error("article_block_init(%s, %d) error", ARTICLE_BLOCK_SHM_FILE, block_count); |
| 114 |
return -2; |
return -2; |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0) |
if (section_list_init(SECTION_LIST_SHM_FILE) < 0) |
| 118 |
{ |
{ |
| 119 |
log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE); |
log_error("section_list_pool_init(%s) error", SECTION_LIST_SHM_FILE); |
| 120 |
|
return -2; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
// Load user_list and online_user_list |
| 124 |
|
if (user_list_pool_init(USER_LIST_SHM_FILE) < 0) |
| 125 |
|
{ |
| 126 |
|
log_error("user_list_pool_init() error"); |
| 127 |
return -2; |
return -2; |
| 128 |
} |
} |
| 129 |
|
|
| 131 |
|
|
| 132 |
last_aid = 0; |
last_aid = 0; |
| 133 |
|
|
| 134 |
if (section_list_try_rw_lock(NULL, 1) < 0) |
if (section_list_rw_lock(NULL) < 0) |
| 135 |
{ |
{ |
| 136 |
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
printf("section_list_rw_lock(sid = %d) error\n", 0); |
| 137 |
} |
} |
| 138 |
|
|
| 139 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 191 |
article.tid = 0; |
article.tid = 0; |
| 192 |
article.sid = i * 3 + 1; |
article.sid = i * 3 + 1; |
| 193 |
article.cid = article.aid; |
article.cid = article.aid; |
| 194 |
article.uid = 1; // TODO: randomize |
article.uid = 1; |
| 195 |
article.visible = 1; |
article.visible = 1; |
| 196 |
article.excerption = 0; |
article.excerption = 0; |
| 197 |
article.ontop = 0; |
article.ontop = 0; |
| 198 |
article.lock = 0; |
article.lock = 0; |
| 199 |
|
article.transship = 0; |
| 200 |
|
|
| 201 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 202 |
{ |
{ |
| 203 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 204 |
break; |
break; |
| 205 |
} |
} |
| 206 |
|
|
| 223 |
// printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i); |
// printf("Loaded %d articles into section %d\n", p_section[i]->article_count, i); |
| 224 |
} |
} |
| 225 |
|
|
| 226 |
|
if (last_aid != article_block_last_aid()) |
| 227 |
|
{ |
| 228 |
|
printf("last_aid != %d\n", article_block_last_aid()); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
if (article_block_article_count() != section_count * BBS_article_limit_per_section) |
| 232 |
|
{ |
| 233 |
|
printf("article_block_article_count() error %d != %d * %d\n", |
| 234 |
|
article_block_article_count(), section_count, BBS_article_limit_per_section); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
last_aid = 0; |
last_aid = 0; |
| 238 |
|
|
| 239 |
for (j = 0; j < BBS_article_limit_per_section; j++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 248 |
printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid); |
printf("article_block_find_by_aid() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid); |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 252 |
{ |
{ |
| 253 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 254 |
break; |
break; |
| 255 |
} |
} |
| 256 |
|
|
| 271 |
|
|
| 272 |
printf("Testing #2 ...\n"); |
printf("Testing #2 ...\n"); |
| 273 |
|
|
| 274 |
if (section_list_try_rw_lock(NULL, 1) < 0) |
if (section_list_rw_lock(NULL) < 0) |
| 275 |
{ |
{ |
| 276 |
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
printf("section_list_rw_lock(sid = %d) error\n", 0); |
| 277 |
} |
} |
| 278 |
|
|
| 279 |
if (article_block_reset() != 0) |
if (article_block_reset() != 0) |
| 280 |
{ |
{ |
| 281 |
log_error("article_block_reset() error\n"); |
log_error("article_block_reset() error"); |
| 282 |
return -4; |
return -4; |
| 283 |
} |
} |
| 284 |
|
|
| 298 |
{ |
{ |
| 299 |
section_first_aid = last_aid + 1; |
section_first_aid = last_aid + 1; |
| 300 |
|
|
| 301 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 302 |
{ |
{ |
| 303 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 304 |
break; |
break; |
| 305 |
} |
} |
| 306 |
|
|
| 314 |
article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count)); |
article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count)); |
| 315 |
article.sid = i * 3 + 1; |
article.sid = i * 3 + 1; |
| 316 |
article.cid = article.aid; |
article.cid = article.aid; |
| 317 |
article.uid = 1; // TODO: randomize |
article.uid = 1; |
| 318 |
article.visible = 1; |
article.visible = 1; |
| 319 |
article.excerption = 0; |
article.excerption = 0; |
| 320 |
article.ontop = 0; |
article.ontop = 0; |
| 321 |
article.lock = 0; |
article.lock = 0; |
| 322 |
|
article.transship = 0; |
| 323 |
|
|
| 324 |
if (section_list_append_article(p_section[i], &article) < 0) |
if (section_list_append_article(p_section[i], &article) < 0) |
| 325 |
{ |
{ |
| 347 |
article_count = 0; |
article_count = 0; |
| 348 |
last_aid = 0; |
last_aid = 0; |
| 349 |
|
|
| 350 |
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
if (section_list_rd_lock(p_section[i]) < 0) |
| 351 |
{ |
{ |
| 352 |
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 353 |
break; |
break; |
| 354 |
} |
} |
| 355 |
|
|
| 391 |
continue; |
continue; |
| 392 |
} |
} |
| 393 |
|
|
| 394 |
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
if (section_list_rd_lock(p_section[i]) < 0) |
| 395 |
{ |
{ |
| 396 |
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 397 |
break; |
break; |
| 398 |
} |
} |
| 399 |
|
|
| 473 |
{ |
{ |
| 474 |
last_aid = 0; |
last_aid = 0; |
| 475 |
|
|
| 476 |
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
if (section_list_rd_lock(p_section[i]) < 0) |
| 477 |
{ |
{ |
| 478 |
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 479 |
break; |
break; |
| 480 |
} |
} |
| 481 |
|
|
| 515 |
|
|
| 516 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 517 |
{ |
{ |
| 518 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 519 |
{ |
{ |
| 520 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 521 |
break; |
break; |
| 522 |
} |
} |
| 523 |
|
|
| 558 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 559 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 560 |
{ |
{ |
| 561 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#1 Inconsistent page count in section %d offset %d, %d != %d, " |
| 562 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 563 |
i, j, |
i, j, |
| 564 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 641 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 642 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 643 |
{ |
{ |
| 644 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#2 Inconsistent page count in section %d offset %d, %d != %d, " |
| 645 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 646 |
i, j, |
i, j, |
| 647 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 660 |
|
|
| 661 |
for (i = 0; i < BBS_max_section; i++) |
for (i = 0; i < BBS_max_section; i++) |
| 662 |
{ |
{ |
| 663 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 664 |
{ |
{ |
| 665 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 666 |
break; |
break; |
| 667 |
} |
} |
| 668 |
|
|
| 710 |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
(p_section[i]->visible_article_count % BBS_article_limit_per_page ? 1 : 0) != |
| 711 |
p_section[i]->page_count) |
p_section[i]->page_count) |
| 712 |
{ |
{ |
| 713 |
printf("Inconsistent page count in section %d offset %d, %d != %d, " |
printf("#3 Inconsistent page count in section %d offset %d, %d != %d, " |
| 714 |
"visible_article_count = %d, last_page_visible_count = %d\n", |
"visible_article_count = %d, last_page_visible_count = %d\n", |
| 715 |
i, j, |
i, j, |
| 716 |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
p_section[i]->visible_article_count / BBS_article_limit_per_page + |
| 729 |
|
|
| 730 |
printf("Testing #5 ...\n"); |
printf("Testing #5 ...\n"); |
| 731 |
|
|
| 732 |
if (section_list_try_rw_lock(NULL, 1) < 0) |
if (section_list_rw_lock(NULL) < 0) |
| 733 |
{ |
{ |
| 734 |
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
printf("section_list_rw_lock(sid = %d) error\n", 0); |
| 735 |
} |
} |
| 736 |
|
|
| 737 |
if (article_block_reset() != 0) |
if (article_block_reset() != 0) |
| 738 |
{ |
{ |
| 739 |
log_error("article_block_reset() error\n"); |
log_error("article_block_reset() error"); |
| 740 |
return -4; |
return -4; |
| 741 |
} |
} |
| 742 |
|
|
| 754 |
|
|
| 755 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 756 |
{ |
{ |
| 757 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 758 |
{ |
{ |
| 759 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 760 |
break; |
break; |
| 761 |
} |
} |
| 762 |
|
|
| 772 |
article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count)); |
article.tid = ((article.aid < section_first_aid + group_count) ? 0 : (section_first_aid + j % group_count)); |
| 773 |
article.sid = i * 3 + 1; |
article.sid = i * 3 + 1; |
| 774 |
article.cid = article.aid; |
article.cid = article.aid; |
| 775 |
article.uid = 1; // TODO: randomize |
article.uid = 1; |
| 776 |
article.visible = 1; |
article.visible = 1; |
| 777 |
article.excerption = 0; |
article.excerption = 0; |
| 778 |
article.ontop = 0; |
article.ontop = 0; |
| 779 |
article.lock = 0; |
article.lock = 0; |
| 780 |
|
article.transship = 0; |
| 781 |
|
|
| 782 |
if (section_list_append_article(p_section[i], &article) < 0) |
if (section_list_append_article(p_section[i], &article) < 0) |
| 783 |
{ |
{ |
| 797 |
|
|
| 798 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 799 |
{ |
{ |
| 800 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 801 |
{ |
{ |
| 802 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 803 |
break; |
break; |
| 804 |
} |
} |
| 805 |
|
|
| 830 |
|
|
| 831 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 832 |
{ |
{ |
| 833 |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
if (section_list_rw_lock(p_section[i]) < 0) |
| 834 |
{ |
{ |
| 835 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 836 |
break; |
break; |
| 837 |
} |
} |
| 838 |
|
|
| 839 |
if (section_list_try_rw_lock(p_section[section_count / 2 + i], 1) < 0) |
if (section_list_rw_lock(p_section[section_count / 2 + i]) < 0) |
| 840 |
{ |
{ |
| 841 |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid); |
printf("section_list_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid); |
| 842 |
|
|
| 843 |
if (section_list_rw_unlock(p_section[i]) < 0) |
if (section_list_rw_unlock(p_section[i]) < 0) |
| 844 |
{ |
{ |
| 888 |
|
|
| 889 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 890 |
{ |
{ |
| 891 |
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
if (section_list_rd_lock(p_section[i]) < 0) |
| 892 |
{ |
{ |
| 893 |
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 894 |
break; |
break; |
| 895 |
} |
} |
| 896 |
|
|
| 936 |
} |
} |
| 937 |
} |
} |
| 938 |
|
|
| 939 |
|
printf("Testing #6 ...\n"); |
| 940 |
|
|
| 941 |
|
for (i = 0; i < section_count; i++) |
| 942 |
|
{ |
| 943 |
|
if (section_list_rd_lock(p_section[i]) < 0) |
| 944 |
|
{ |
| 945 |
|
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 946 |
|
break; |
| 947 |
|
} |
| 948 |
|
} |
| 949 |
|
|
| 950 |
|
printf("Try rw_lock for 5 sec...\n"); |
| 951 |
|
if (section_list_try_rw_lock(NULL, 5) == 0) |
| 952 |
|
{ |
| 953 |
|
printf("section_list_try_rw_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid); |
| 954 |
|
} |
| 955 |
|
|
| 956 |
|
for (i = 0; i < section_count; i++) |
| 957 |
|
{ |
| 958 |
|
if (section_list_rd_unlock(p_section[i]) < 0) |
| 959 |
|
{ |
| 960 |
|
printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid); |
| 961 |
|
break; |
| 962 |
|
} |
| 963 |
|
} |
| 964 |
|
|
| 965 |
|
if (section_list_try_rw_lock(NULL, 5) < 0) |
| 966 |
|
{ |
| 967 |
|
printf("section_list_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 968 |
|
} |
| 969 |
|
|
| 970 |
|
for (i = 0; i < section_count; i++) |
| 971 |
|
{ |
| 972 |
|
if (section_list_try_rd_lock(p_section[i], 0) == 0) |
| 973 |
|
{ |
| 974 |
|
printf("section_list_try_rd_lock(sid = %d) error, expectation is timeout\n", p_section[i]->sid); |
| 975 |
|
break; |
| 976 |
|
} |
| 977 |
|
} |
| 978 |
|
|
| 979 |
|
if (section_list_rw_unlock(NULL) < 0) |
| 980 |
|
{ |
| 981 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 982 |
|
} |
| 983 |
|
|
| 984 |
printf("Press ENTER to exit..."); |
printf("Press ENTER to exit..."); |
| 985 |
getchar(); |
getchar(); |
| 986 |
|
|
| 987 |
|
user_list_pool_cleanup(); |
| 988 |
|
section_list_cleanup(); |
| 989 |
article_block_cleanup(); |
article_block_cleanup(); |
| 990 |
section_list_pool_cleanup(); |
trie_dict_cleanup(); |
| 991 |
|
|
| 992 |
|
if (unlink(USER_LIST_SHM_FILE) < 0) |
| 993 |
|
{ |
| 994 |
|
log_error("unlink(%s) error", USER_LIST_SHM_FILE); |
| 995 |
|
return -1; |
| 996 |
|
} |
| 997 |
|
|
| 998 |
|
if (unlink(TRIE_DICT_SHM_FILE) < 0) |
| 999 |
|
{ |
| 1000 |
|
log_error("unlink(%s) error", TRIE_DICT_SHM_FILE); |
| 1001 |
|
return -1; |
| 1002 |
|
} |
| 1003 |
|
|
| 1004 |
if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0) |
if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0) |
| 1005 |
{ |
{ |
| 1006 |
log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE); |
log_error("unlink(%s) error", ARTICLE_BLOCK_SHM_FILE); |
| 1007 |
return -1; |
return -1; |
| 1008 |
} |
} |
| 1009 |
|
|
| 1010 |
if (unlink(SECTION_LIST_SHM_FILE) < 0) |
if (unlink(SECTION_LIST_SHM_FILE) < 0) |
| 1011 |
{ |
{ |
| 1012 |
log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE); |
log_error("unlink(%s) error", SECTION_LIST_SHM_FILE); |
| 1013 |
return -1; |
return -1; |
| 1014 |
} |
} |
| 1015 |
|
|