| 343 |
} |
} |
| 344 |
|
|
| 345 |
left = 0; |
left = 0; |
| 346 |
right = p_article_block_pool->block_count; |
right = p_article_block_pool->block_count - 1; |
| 347 |
|
|
| 348 |
// aid in the range [ head aid of blocks[left], tail aid of blocks[right - 1] ] |
// aid in the range [ head aid of blocks[left], tail aid of blocks[right] ] |
| 349 |
while (left < right - 1) |
while (left < right) |
| 350 |
{ |
{ |
| 351 |
// get block offset no less than mid value of left and right block offsets |
// get block offset no less than mid value of left and right block offsets |
| 352 |
mid = (left + right) / 2 + (right - left) % 2; |
mid = (left + right) / 2 + (left + right) % 2; |
|
|
|
|
if (mid >= p_article_block_pool->block_count) |
|
|
{ |
|
|
log_error("block(mid = %d) is out of boundary\n", mid); |
|
|
return NULL; |
|
|
} |
|
| 353 |
|
|
| 354 |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
| 355 |
{ |
{ |
| 356 |
right = mid; |
right = mid - 1; |
| 357 |
} |
} |
| 358 |
else |
else // if (aid >= p_article_block_pool->p_block[mid]->articles[0].aid) |
| 359 |
{ |
{ |
| 360 |
left = mid; |
left = mid; |
| 361 |
} |
} |
| 1084 |
} |
} |
| 1085 |
else // if (page_id >= p_section->page_count - 1) |
else // if (page_id >= p_section->page_count - 1) |
| 1086 |
{ |
{ |
| 1087 |
return MAX(0, (p_section->last_page_visible_article_count + p_section->ontop_article_count - |
return MIN(MAX(0, |
| 1088 |
BBS_article_limit_per_page * (page_id - p_section->page_count + 1))); |
(p_section->last_page_visible_article_count + p_section->ontop_article_count - |
| 1089 |
|
BBS_article_limit_per_page * (page_id - p_section->page_count + 1))), |
| 1090 |
|
BBS_article_limit_per_page); |
| 1091 |
} |
} |
| 1092 |
} |
} |
| 1093 |
|
|
| 1116 |
} |
} |
| 1117 |
|
|
| 1118 |
left = 0; |
left = 0; |
| 1119 |
right = p_section->page_count; |
right = p_section->page_count - 1; |
| 1120 |
|
|
| 1121 |
// aid in the range [ head aid of pages[left], tail aid of pages[right - 1] ] |
// aid in the range [ head aid of pages[left], tail aid of pages[right] ] |
| 1122 |
while (left < right - 1) |
while (left < right) |
| 1123 |
{ |
{ |
| 1124 |
// get page id no less than mid value of left page id and right page id |
// get page id no less than mid value of left page id and right page id |
| 1125 |
mid = (left + right) / 2 + (right - left) % 2; |
mid = (left + right) / 2 + (left + right) % 2; |
|
|
|
|
if (mid >= p_section->page_count) |
|
|
{ |
|
|
log_error("page id (mid = %d) is out of boundary\n", mid); |
|
|
return NULL; |
|
|
} |
|
| 1126 |
|
|
| 1127 |
if (aid < p_section->p_page_first_article[mid]->aid) |
if (aid < p_section->p_page_first_article[mid]->aid) |
| 1128 |
{ |
{ |
| 1129 |
right = mid; |
right = mid - 1; |
| 1130 |
} |
} |
| 1131 |
else |
else // if (aid < p_section->p_page_first_article[mid]->aid) |
| 1132 |
{ |
{ |
| 1133 |
left = mid; |
left = mid; |
| 1134 |
} |
} |
| 1562 |
return index; |
return index; |
| 1563 |
} |
} |
| 1564 |
|
|
| 1565 |
|
int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *master_list) |
| 1566 |
|
{ |
| 1567 |
|
if (p_section == NULL) |
| 1568 |
|
{ |
| 1569 |
|
log_error("NULL pointer error\n"); |
| 1570 |
|
return -1; |
| 1571 |
|
} |
| 1572 |
|
|
| 1573 |
|
if (section_list_rd_lock(p_section) < 0) |
| 1574 |
|
{ |
| 1575 |
|
log_error("section_list_rd_lock(sid=%d) error\n", p_section->sid); |
| 1576 |
|
return -2; |
| 1577 |
|
} |
| 1578 |
|
|
| 1579 |
|
if (sname != NULL) |
| 1580 |
|
{ |
| 1581 |
|
memcpy(sname, p_section->sname, sizeof(p_section->sname)); |
| 1582 |
|
} |
| 1583 |
|
if (stitle != NULL) |
| 1584 |
|
{ |
| 1585 |
|
memcpy(stitle, p_section->stitle, sizeof(p_section->stitle)); |
| 1586 |
|
} |
| 1587 |
|
if (master_list != NULL) |
| 1588 |
|
{ |
| 1589 |
|
memcpy(master_list, p_section->master_list, sizeof(p_section->master_list)); |
| 1590 |
|
} |
| 1591 |
|
|
| 1592 |
|
// release lock of section |
| 1593 |
|
if (section_list_rd_unlock(p_section) < 0) |
| 1594 |
|
{ |
| 1595 |
|
log_error("section_list_rd_unlock(sid=%d) error\n", p_section->sid); |
| 1596 |
|
return -2; |
| 1597 |
|
} |
| 1598 |
|
|
| 1599 |
|
return 0; |
| 1600 |
|
} |
| 1601 |
|
|
| 1602 |
int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec) |
int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec) |
| 1603 |
{ |
{ |
| 1604 |
int index; |
int index; |