| 21 |
#include <unistd.h> |
#include <unistd.h> |
| 22 |
#include <errno.h> |
#include <errno.h> |
| 23 |
|
|
| 24 |
|
#define ARTICLE_BLOCK_SHM_FILE "~article_block_shm.dat" |
| 25 |
|
#define SECTION_LIST_SHM_FILE "~section_list_shm.dat" |
| 26 |
|
|
| 27 |
const char *sname[] = { |
const char *sname[] = { |
| 28 |
"Test", |
"Test", |
| 29 |
"ABCDEFG", |
"ABCDEFG", |
| 50 |
ARTICLE article; |
ARTICLE article; |
| 51 |
int block_count; |
int block_count; |
| 52 |
int i, j; |
int i, j; |
| 53 |
|
int sid; |
| 54 |
int last_aid; |
int last_aid; |
| 55 |
int current_tid; |
int current_tid; |
| 56 |
int section_first_aid; |
int section_first_aid; |
| 60 |
int32_t page; |
int32_t page; |
| 61 |
int32_t offset; |
int32_t offset; |
| 62 |
int affected_count; |
int affected_count; |
| 63 |
|
FILE *fp; |
| 64 |
|
|
| 65 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0) |
| 66 |
{ |
{ |
| 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 / ARTICLE_PER_BLOCK; |
| 76 |
|
|
| 77 |
if (article_block_init("../conf/menu.conf", block_count) < 0) |
if ((fp = fopen(ARTICLE_BLOCK_SHM_FILE, "w")) == NULL) |
| 78 |
|
{ |
| 79 |
|
log_error("fopen(%s) error\n", ARTICLE_BLOCK_SHM_FILE); |
| 80 |
|
return -1; |
| 81 |
|
} |
| 82 |
|
fclose(fp); |
| 83 |
|
|
| 84 |
|
if ((fp = fopen(SECTION_LIST_SHM_FILE, "w")) == NULL) |
| 85 |
|
{ |
| 86 |
|
log_error("fopen(%s) error\n", SECTION_LIST_SHM_FILE); |
| 87 |
|
return -1; |
| 88 |
|
} |
| 89 |
|
fclose(fp); |
| 90 |
|
|
| 91 |
|
if (article_block_init(ARTICLE_BLOCK_SHM_FILE, block_count) < 0) |
| 92 |
|
{ |
| 93 |
|
log_error("article_block_init(%s, %d) error\n", ARTICLE_BLOCK_SHM_FILE, block_count); |
| 94 |
|
return -2; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
if (section_list_pool_init(SECTION_LIST_SHM_FILE) < 0) |
| 98 |
{ |
{ |
| 99 |
log_error("section_data_pool_init() error\n"); |
log_error("section_list_pool_init(%s) error\n", SECTION_LIST_SHM_FILE); |
| 100 |
return -2; |
return -2; |
| 101 |
} |
} |
| 102 |
|
|
| 104 |
|
|
| 105 |
last_aid = 0; |
last_aid = 0; |
| 106 |
|
|
| 107 |
|
if (section_list_try_rw_lock(NULL, 1) < 0) |
| 108 |
|
{ |
| 109 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 113 |
{ |
{ |
| 114 |
p_section[i] = section_list_create(i + 1, |
sid = i * 3 + 1; |
| 115 |
|
p_section[i] = section_list_create(sid, |
| 116 |
sname[i % section_conf_count], |
sname[i % section_conf_count], |
| 117 |
stitle[i % section_conf_count], |
stitle[i % section_conf_count], |
| 118 |
master_name[i % section_conf_count]); |
master_name[i % section_conf_count]); |
| 119 |
if (p_section[i] == NULL) |
if (p_section[i] == NULL) |
| 120 |
{ |
{ |
| 121 |
log_error("section_data_create(i=%d) error\n", i); |
printf("section_list_create(i = %d) error\n", i); |
| 122 |
|
return -3; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
if (get_section_index(p_section[i]) != i) |
| 126 |
|
{ |
| 127 |
|
printf("get_section_index(i = %d) error\n", i); |
| 128 |
return -3; |
return -3; |
| 129 |
} |
} |
| 130 |
} |
} |
| 133 |
{ |
{ |
| 134 |
if (section_list_find_by_name(sname[i]) == NULL) |
if (section_list_find_by_name(sname[i]) == NULL) |
| 135 |
{ |
{ |
| 136 |
printf("section_data_find_section_by_name(%s) error\n", sname[i]); |
printf("section_list_find_by_name(%s) error\n", sname[i]); |
| 137 |
return -3; |
return -3; |
| 138 |
} |
} |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
|
for (i = 0; i < section_count; i++) |
| 142 |
|
{ |
| 143 |
|
sid = i * 3 + 1; |
| 144 |
|
if (section_list_find_by_sid(sid) == NULL || section_list_find_by_sid(sid)->sid != sid) |
| 145 |
|
{ |
| 146 |
|
printf("section_list_find_by_sid(%d) error\n", sid); |
| 147 |
|
return -3; |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
if (section_list_rw_unlock(NULL) < 0) |
| 152 |
|
{ |
| 153 |
|
printf("section_list_rw_unlock(sid = %d) error\n", 0); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
for (j = 0; j < BBS_article_limit_per_section; j++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 157 |
{ |
{ |
| 158 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 161 |
|
|
| 162 |
// Set article data |
// Set article data |
| 163 |
article.aid = last_aid; |
article.aid = last_aid; |
|
article.cid = article.aid; |
|
| 164 |
article.tid = 0; |
article.tid = 0; |
| 165 |
|
article.sid = i * 3 + 1; |
| 166 |
|
article.cid = article.aid; |
| 167 |
article.uid = 1; // TODO: randomize |
article.uid = 1; // TODO: randomize |
| 168 |
article.visible = 1; |
article.visible = 1; |
| 169 |
article.excerption = 0; |
article.excerption = 0; |
| 170 |
article.ontop = 0; |
article.ontop = 0; |
| 171 |
article.lock = 0; |
article.lock = 0; |
| 172 |
|
|
| 173 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 174 |
|
{ |
| 175 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 176 |
|
break; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
if (section_list_append_article(p_section[i], &article) < 0) |
if (section_list_append_article(p_section[i], &article) < 0) |
| 180 |
{ |
{ |
| 181 |
printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j); |
printf("append article (aid = %d) error at section %d index %d\n", article.aid, i, j); |
| 182 |
break; |
break; |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 186 |
|
{ |
| 187 |
|
printf("section_list_rw_unlock(sid = %d) error %d\n", p_section[i]->sid, errno); |
| 188 |
|
break; |
| 189 |
|
} |
| 190 |
} |
} |
| 191 |
} |
} |
| 192 |
|
|
| 197 |
|
|
| 198 |
last_aid = 0; |
last_aid = 0; |
| 199 |
|
|
| 200 |
for (i = 0; i < section_count; i++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 201 |
{ |
{ |
| 202 |
if (p_section[i]->article_count == 0) |
for (i = 0; i < section_count; i++) |
|
{ |
|
|
continue; |
|
|
} |
|
|
|
|
|
for (j = 0; j < p_section[i]->article_count; j++) |
|
| 203 |
{ |
{ |
| 204 |
last_aid++; |
last_aid++; |
| 205 |
|
|
| 209 |
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); |
| 210 |
} |
} |
| 211 |
|
|
| 212 |
p_article = article_block_find_by_index(last_aid - 1); |
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
|
if (p_article == NULL || p_article->aid != last_aid) |
|
| 213 |
{ |
{ |
| 214 |
printf("article_block_find_by_index() at section %d index %d, %d != %d\n", i, j, p_article->aid, last_aid); |
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 215 |
|
break; |
| 216 |
} |
} |
| 217 |
|
|
| 218 |
if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1) |
if (section_list_set_article_visible(p_section[i], p_article->aid, 0) != 1) |
| 219 |
{ |
{ |
| 220 |
printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid); |
printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid); |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 224 |
|
{ |
| 225 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 226 |
|
break; |
| 227 |
|
} |
| 228 |
} |
} |
| 229 |
|
|
| 230 |
// printf("Verified %d articles in section %d\n", p_section[i]->article_count, i); |
// printf("Verified %d articles in section %d\n", p_section[i]->article_count, i); |
| 232 |
|
|
| 233 |
printf("Testing #2 ...\n"); |
printf("Testing #2 ...\n"); |
| 234 |
|
|
| 235 |
|
if (section_list_try_rw_lock(NULL, 1) < 0) |
| 236 |
|
{ |
| 237 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
if (article_block_reset() != 0) |
if (article_block_reset() != 0) |
| 241 |
{ |
{ |
| 242 |
log_error("section_data_free_block(i=%d) error\n", i); |
log_error("article_block_reset() error\n"); |
| 243 |
return -4; |
return -4; |
| 244 |
} |
} |
| 245 |
|
|
| 248 |
section_list_reset_articles(p_section[i]); |
section_list_reset_articles(p_section[i]); |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
|
if (section_list_rw_unlock(NULL) < 0) |
| 252 |
|
{ |
| 253 |
|
printf("section_list_rw_unlock(sid = %d) error\n", 0); |
| 254 |
|
} |
| 255 |
|
|
| 256 |
last_aid = 0; |
last_aid = 0; |
| 257 |
|
|
| 258 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 259 |
{ |
{ |
| 260 |
section_first_aid = last_aid + 1; |
section_first_aid = last_aid + 1; |
| 261 |
|
|
| 262 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 263 |
|
{ |
| 264 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 265 |
|
break; |
| 266 |
|
} |
| 267 |
|
|
| 268 |
for (j = 0; j < BBS_article_limit_per_section; j++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 269 |
{ |
{ |
| 270 |
last_aid++; |
last_aid++; |
| 271 |
|
|
| 272 |
// Set article data |
// Set article data |
| 273 |
article.aid = last_aid; |
article.aid = last_aid; |
|
article.cid = article.aid; |
|
| 274 |
// Group articles into group_count topics |
// Group articles into group_count topics |
| 275 |
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)); |
| 276 |
|
article.sid = i * 3 + 1; |
| 277 |
|
article.cid = article.aid; |
| 278 |
article.uid = 1; // TODO: randomize |
article.uid = 1; // TODO: randomize |
| 279 |
article.visible = 1; |
article.visible = 1; |
| 280 |
article.excerption = 0; |
article.excerption = 0; |
| 288 |
} |
} |
| 289 |
} |
} |
| 290 |
|
|
| 291 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 292 |
|
{ |
| 293 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 294 |
|
break; |
| 295 |
|
} |
| 296 |
|
|
| 297 |
// 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); |
| 298 |
} |
} |
| 299 |
|
|
| 307 |
article_count = 0; |
article_count = 0; |
| 308 |
last_aid = 0; |
last_aid = 0; |
| 309 |
|
|
| 310 |
|
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
| 311 |
|
{ |
| 312 |
|
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 313 |
|
break; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
p_article = p_section[i]->p_article_head; |
p_article = p_section[i]->p_article_head; |
| 317 |
|
|
| 318 |
do |
do |
| 335 |
break; |
break; |
| 336 |
} |
} |
| 337 |
|
|
| 338 |
|
if (section_list_rd_unlock(p_section[i]) < 0) |
| 339 |
|
{ |
| 340 |
|
printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid); |
| 341 |
|
break; |
| 342 |
|
} |
| 343 |
|
|
| 344 |
// printf("Verified %d articles in section %d\n", group_count, i); |
// printf("Verified %d articles in section %d\n", group_count, i); |
| 345 |
} |
} |
| 346 |
|
|
| 351 |
continue; |
continue; |
| 352 |
} |
} |
| 353 |
|
|
| 354 |
|
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
| 355 |
|
{ |
| 356 |
|
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 357 |
|
break; |
| 358 |
|
} |
| 359 |
|
|
| 360 |
if (p_section[i]->topic_count != group_count) |
if (p_section[i]->topic_count != group_count) |
| 361 |
{ |
{ |
| 362 |
printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count); |
printf("Inconsistent topic count in section %d, %d != %d\n", i, p_section[i]->topic_count, group_count); |
| 418 |
} |
} |
| 419 |
} |
} |
| 420 |
|
|
| 421 |
|
if (section_list_rd_unlock(p_section[i]) < 0) |
| 422 |
|
{ |
| 423 |
|
printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid); |
| 424 |
|
break; |
| 425 |
|
} |
| 426 |
|
|
| 427 |
// printf("Verified %d topics in section %d\n", group_count, i); |
// printf("Verified %d topics in section %d\n", group_count, i); |
| 428 |
} |
} |
| 429 |
|
|
| 433 |
{ |
{ |
| 434 |
last_aid = 0; |
last_aid = 0; |
| 435 |
|
|
| 436 |
|
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
| 437 |
|
{ |
| 438 |
|
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 439 |
|
break; |
| 440 |
|
} |
| 441 |
|
|
| 442 |
for (j = 0; j < p_section[i]->page_count; j++) |
for (j = 0; j < p_section[i]->page_count; j++) |
| 443 |
{ |
{ |
| 444 |
if (p_section[i]->p_page_first_article[j]->aid <= last_aid) |
if (p_section[i]->p_page_first_article[j]->aid <= last_aid) |
| 463 |
} |
} |
| 464 |
} |
} |
| 465 |
} |
} |
| 466 |
|
|
| 467 |
|
if (section_list_rd_unlock(p_section[i]) < 0) |
| 468 |
|
{ |
| 469 |
|
printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid); |
| 470 |
|
break; |
| 471 |
|
} |
| 472 |
} |
} |
| 473 |
|
|
| 474 |
printf("Testing #4 ...\n"); |
printf("Testing #4 ...\n"); |
| 475 |
|
|
| 476 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 477 |
{ |
{ |
| 478 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 479 |
|
{ |
| 480 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 481 |
|
break; |
| 482 |
|
} |
| 483 |
|
|
| 484 |
step = i % 10 + 1; |
step = i % 10 + 1; |
| 485 |
for (j = group_count; j < BBS_article_limit_per_section; j += step) |
for (j = group_count; j < BBS_article_limit_per_section; j += step) |
| 486 |
{ |
{ |
| 610 |
p_section[i]->last_page_visible_article_count); |
p_section[i]->last_page_visible_article_count); |
| 611 |
break; |
break; |
| 612 |
} |
} |
| 613 |
|
|
| 614 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 615 |
|
{ |
| 616 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 617 |
|
break; |
| 618 |
|
} |
| 619 |
} |
} |
| 620 |
|
|
| 621 |
for (i = 0; i < BBS_max_section; i++) |
for (i = 0; i < BBS_max_section; i++) |
| 622 |
{ |
{ |
| 623 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 624 |
|
{ |
| 625 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 626 |
|
break; |
| 627 |
|
} |
| 628 |
|
|
| 629 |
affected_count = 0; |
affected_count = 0; |
| 630 |
|
|
| 631 |
for (j = 0; j < BBS_article_limit_per_section; j += 1) |
for (j = 0; j < BBS_article_limit_per_section; j += 1) |
| 679 |
p_section[i]->last_page_visible_article_count); |
p_section[i]->last_page_visible_article_count); |
| 680 |
break; |
break; |
| 681 |
} |
} |
| 682 |
|
|
| 683 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 684 |
|
{ |
| 685 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 686 |
|
break; |
| 687 |
|
} |
| 688 |
} |
} |
| 689 |
|
|
| 690 |
printf("Testing #5 ...\n"); |
printf("Testing #5 ...\n"); |
| 691 |
|
|
| 692 |
|
if (section_list_try_rw_lock(NULL, 1) < 0) |
| 693 |
|
{ |
| 694 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", 0); |
| 695 |
|
} |
| 696 |
|
|
| 697 |
if (article_block_reset() != 0) |
if (article_block_reset() != 0) |
| 698 |
{ |
{ |
| 699 |
log_error("section_data_free_block(i=%d) error\n", i); |
log_error("article_block_reset() error\n"); |
| 700 |
return -4; |
return -4; |
| 701 |
} |
} |
| 702 |
|
|
| 705 |
section_list_reset_articles(p_section[i]); |
section_list_reset_articles(p_section[i]); |
| 706 |
} |
} |
| 707 |
|
|
| 708 |
|
if (section_list_rw_unlock(NULL) < 0) |
| 709 |
|
{ |
| 710 |
|
printf("section_list_rw_unlock(sid = %d) error\n", 0); |
| 711 |
|
} |
| 712 |
|
|
| 713 |
last_aid = 0; |
last_aid = 0; |
| 714 |
|
|
| 715 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 716 |
{ |
{ |
| 717 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 718 |
|
{ |
| 719 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 720 |
|
break; |
| 721 |
|
} |
| 722 |
|
|
| 723 |
section_first_aid = last_aid + 1; |
section_first_aid = last_aid + 1; |
| 724 |
|
|
| 725 |
for (j = 0; j < BBS_article_limit_per_section; j++) |
for (j = 0; j < BBS_article_limit_per_section; j++) |
| 728 |
|
|
| 729 |
// Set article data |
// Set article data |
| 730 |
article.aid = last_aid; |
article.aid = last_aid; |
|
article.cid = article.aid; |
|
| 731 |
// Group articles into group_count topics |
// Group articles into group_count topics |
| 732 |
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)); |
| 733 |
|
article.sid = i * 3 + 1; |
| 734 |
|
article.cid = article.aid; |
| 735 |
article.uid = 1; // TODO: randomize |
article.uid = 1; // TODO: randomize |
| 736 |
article.visible = 1; |
article.visible = 1; |
| 737 |
article.excerption = 0; |
article.excerption = 0; |
| 745 |
} |
} |
| 746 |
} |
} |
| 747 |
|
|
| 748 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 749 |
|
{ |
| 750 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 751 |
|
break; |
| 752 |
|
} |
| 753 |
|
|
| 754 |
// 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); |
| 755 |
} |
} |
| 756 |
|
|
| 757 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 758 |
{ |
{ |
| 759 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 760 |
|
{ |
| 761 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 762 |
|
break; |
| 763 |
|
} |
| 764 |
|
|
| 765 |
section_first_aid = p_section[i]->p_article_head->aid; |
section_first_aid = p_section[i]->p_article_head->aid; |
| 766 |
|
|
| 767 |
for (j = 0; j < group_count; j += 2) |
for (j = 0; j < group_count; j += 2) |
| 779 |
printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid); |
printf("section_list_set_article_visible(aid = %d) error\n", p_article->aid); |
| 780 |
} |
} |
| 781 |
} |
} |
| 782 |
|
|
| 783 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 784 |
|
{ |
| 785 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 786 |
|
break; |
| 787 |
|
} |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
for (i = 0; i < section_count / 2; i++) |
for (i = 0; i < section_count / 2; i++) |
| 791 |
{ |
{ |
| 792 |
|
if (section_list_try_rw_lock(p_section[i], 1) < 0) |
| 793 |
|
{ |
| 794 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[i]->sid); |
| 795 |
|
break; |
| 796 |
|
} |
| 797 |
|
|
| 798 |
|
if (section_list_try_rw_lock(p_section[section_count / 2 + i], 1) < 0) |
| 799 |
|
{ |
| 800 |
|
printf("section_list_try_rw_lock(sid = %d) error\n", p_section[section_count / 2 + i]->sid); |
| 801 |
|
|
| 802 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 803 |
|
{ |
| 804 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 805 |
|
} |
| 806 |
|
break; |
| 807 |
|
} |
| 808 |
|
|
| 809 |
section_first_aid = p_section[i]->p_article_head->aid; |
section_first_aid = p_section[i]->p_article_head->aid; |
| 810 |
|
|
| 811 |
for (j = 0; j < group_count; j++) |
for (j = 0; j < group_count; j++) |
| 826 |
// break; |
// break; |
| 827 |
} |
} |
| 828 |
} |
} |
| 829 |
|
|
| 830 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 831 |
|
{ |
| 832 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 833 |
|
break; |
| 834 |
|
} |
| 835 |
|
|
| 836 |
|
if (section_list_rw_unlock(p_section[section_count / 2 + i]) < 0) |
| 837 |
|
{ |
| 838 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[section_count / 2 + i]->sid); |
| 839 |
|
|
| 840 |
|
if (section_list_rw_unlock(p_section[i]) < 0) |
| 841 |
|
{ |
| 842 |
|
printf("section_list_rw_unlock(sid = %d) error\n", p_section[i]->sid); |
| 843 |
|
} |
| 844 |
|
break; |
| 845 |
|
} |
| 846 |
} |
} |
| 847 |
|
|
| 848 |
for (i = 0; i < section_count; i++) |
for (i = 0; i < section_count; i++) |
| 849 |
{ |
{ |
| 850 |
|
if (section_list_try_rd_lock(p_section[i], 1) < 0) |
| 851 |
|
{ |
| 852 |
|
printf("section_list_try_rd_lock(sid = %d) error\n", p_section[i]->sid); |
| 853 |
|
break; |
| 854 |
|
} |
| 855 |
|
|
| 856 |
if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count)) |
if (p_section[i]->topic_count != (i < section_count / 2 ? 0 : group_count)) |
| 857 |
{ |
{ |
| 858 |
printf("Topic count error in section %d, %d != %d\n", i, |
printf("Topic count error in section %d, %d != %d\n", i, |
| 887 |
p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page)); |
p_section[i]->page_count, (i < section_count / 2 ? 0 : BBS_article_limit_per_section / 2 / BBS_article_limit_per_page)); |
| 888 |
break; |
break; |
| 889 |
} |
} |
| 890 |
|
|
| 891 |
|
if (section_list_rd_unlock(p_section[i]) < 0) |
| 892 |
|
{ |
| 893 |
|
printf("section_list_rd_unlock(sid = %d) error\n", p_section[i]->sid); |
| 894 |
|
break; |
| 895 |
|
} |
| 896 |
} |
} |
| 897 |
|
|
| 898 |
printf("Press ENTER to exit..."); |
printf("Press ENTER to exit..."); |
| 899 |
getchar(); |
getchar(); |
| 900 |
|
|
| 901 |
article_block_cleanup(); |
article_block_cleanup(); |
| 902 |
|
section_list_pool_cleanup(); |
| 903 |
|
|
| 904 |
|
if (unlink(ARTICLE_BLOCK_SHM_FILE) < 0) |
| 905 |
|
{ |
| 906 |
|
log_error("unlink(%s) error\n", ARTICLE_BLOCK_SHM_FILE); |
| 907 |
|
return -1; |
| 908 |
|
} |
| 909 |
|
|
| 910 |
|
if (unlink(SECTION_LIST_SHM_FILE) < 0) |
| 911 |
|
{ |
| 912 |
|
log_error("unlink(%s) error\n", SECTION_LIST_SHM_FILE); |
| 913 |
|
return -1; |
| 914 |
|
} |
| 915 |
|
|
| 916 |
log_end(); |
log_end(); |
| 917 |
|
|