| 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 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| 281 |
|
|
| 282 |
int detach_article_block_shm(void) |
int detach_article_block_shm(void) |
| 283 |
{ |
{ |
| 284 |
|
int shm_count; |
| 285 |
|
size_t pool_shm_size; |
| 286 |
|
|
| 287 |
if (p_article_block_pool == NULL) |
if (p_article_block_pool == NULL) |
| 288 |
{ |
{ |
| 289 |
return -1; |
return -1; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
for (int i = 0; i < p_article_block_pool->shm_count; i++) |
shm_count = p_article_block_pool->shm_count; |
| 293 |
|
pool_shm_size = p_article_block_pool->shm_size; |
| 294 |
|
|
| 295 |
|
for (int i = 0; i < shm_count; i++) |
| 296 |
{ |
{ |
| 297 |
if ((p_article_block_pool->shm_pool + i)->p_shm != NULL && |
if ((p_article_block_pool->shm_pool + i)->p_shm != NULL && |
| 298 |
munmap((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size) < 0) |
munmap((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size) < 0) |
| 302 |
} |
} |
| 303 |
} |
} |
| 304 |
|
|
| 305 |
if (p_article_block_pool != NULL && munmap(p_article_block_pool, p_article_block_pool->shm_size) < 0) |
if (p_article_block_pool != NULL && munmap(p_article_block_pool, pool_shm_size) < 0) |
| 306 |
{ |
{ |
| 307 |
log_error("munmap() error (%d)", errno); |
log_error("munmap() error (%d)", errno); |
| 308 |
return -3; |
return -3; |
| 379 |
while (left < right) |
while (left < right) |
| 380 |
{ |
{ |
| 381 |
// 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 |
| 382 |
mid = (left + right) / 2 + (left + right) % 2; |
mid = left + (right - left + 1) / 2; |
| 383 |
|
|
| 384 |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
if (aid < p_article_block_pool->p_block[mid]->articles[0].aid) |
| 385 |
{ |
{ |
| 399 |
// aid in the range [ aid of articles[left], aid of articles[right] ] |
// aid in the range [ aid of articles[left], aid of articles[right] ] |
| 400 |
while (left < right) |
while (left < right) |
| 401 |
{ |
{ |
| 402 |
mid = (left + right) / 2; |
mid = left + (right - left) / 2; |
| 403 |
|
|
| 404 |
if (aid <= p_block->articles[mid].aid) |
if (aid <= p_block->articles[mid].aid) |
| 405 |
{ |
{ |
| 1223 |
while (left < right) |
while (left < right) |
| 1224 |
{ |
{ |
| 1225 |
// 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 |
| 1226 |
mid = (left + right) / 2 + (left + right) % 2; |
mid = left + (right - left + 1) / 2; |
| 1227 |
|
|
| 1228 |
if (aid < p_section->p_page_first_article[mid]->aid) |
if (aid < p_section->p_page_first_article[mid]->aid) |
| 1229 |
{ |
{ |
| 1520 |
{ |
{ |
| 1521 |
p_section_src->p_article_tail = p_article->p_prior; |
p_section_src->p_article_tail = p_article->p_prior; |
| 1522 |
} |
} |
| 1523 |
if (p_section_src->p_article_head == p_article) // || p_section_src->p_article_tail == p_article |
if (p_section_src->p_article_head == p_article) // Single element list |
| 1524 |
{ |
{ |
| 1525 |
p_section_src->p_article_head = NULL; |
p_section_src->p_article_head = NULL; |
| 1526 |
p_section_src->p_article_tail = NULL; |
p_section_src->p_article_tail = NULL; |
| 1527 |
} |
} |
| 1528 |
|
else |
| 1529 |
p_article->p_prior->p_next = p_article->p_next; |
{ |
| 1530 |
p_article->p_next->p_prior = p_article->p_prior; |
// Only update neighbor pointers if list is not empty after removal |
| 1531 |
|
p_article->p_prior->p_next = p_article->p_next; |
| 1532 |
|
p_article->p_next->p_prior = p_article->p_prior; |
| 1533 |
|
} |
| 1534 |
|
|
| 1535 |
// Update sid of article |
// Update sid of article |
| 1536 |
p_article->sid = p_section_dest->sid; |
p_article->sid = p_section_dest->sid; |