| 41 |
}; |
}; |
| 42 |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
| 43 |
|
|
| 44 |
|
#define SECTION_TRY_LOCK_WAIT_TIME 1 // second |
| 45 |
|
#define SECTION_TRY_LOCK_TIMES 10 |
| 46 |
|
|
| 47 |
#define ARTICLE_BLOCK_PER_SHM 400 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate |
#define ARTICLE_BLOCK_PER_SHM 400 // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate |
| 48 |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
#define ARTICLE_BLOCK_SHM_COUNT_LIMIT 200 // limited by length (8-bit) of proj_id in ftok(path, proj_id) |
| 49 |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
#define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT) |
| 1409 |
} |
} |
| 1410 |
|
|
| 1411 |
return ret; |
return ret; |
| 1412 |
|
} |
| 1413 |
|
|
| 1414 |
|
int section_list_rd_lock(SECTION_LIST *p_section) |
| 1415 |
|
{ |
| 1416 |
|
int timer = 0; |
| 1417 |
|
int sid = (p_section == NULL ? 0 : p_section->sid); |
| 1418 |
|
int ret = -1; |
| 1419 |
|
|
| 1420 |
|
while (!SYS_server_exit) |
| 1421 |
|
{ |
| 1422 |
|
ret = section_list_try_rd_lock(p_section, SECTION_TRY_LOCK_WAIT_TIME); |
| 1423 |
|
if (ret == 0) // success |
| 1424 |
|
{ |
| 1425 |
|
break; |
| 1426 |
|
} |
| 1427 |
|
else if (errno == EAGAIN || errno == EINTR) // retry |
| 1428 |
|
{ |
| 1429 |
|
timer++; |
| 1430 |
|
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1431 |
|
{ |
| 1432 |
|
log_error("section_list_rd_lock() tried %d times on section %d\n", sid, timer); |
| 1433 |
|
} |
| 1434 |
|
} |
| 1435 |
|
else // failed |
| 1436 |
|
{ |
| 1437 |
|
log_error("section_list_rd_lock() failed on section %d\n", sid); |
| 1438 |
|
break; |
| 1439 |
|
} |
| 1440 |
|
} |
| 1441 |
|
|
| 1442 |
|
return ret; |
| 1443 |
|
} |
| 1444 |
|
|
| 1445 |
|
int section_list_rw_lock(SECTION_LIST *p_section) |
| 1446 |
|
{ |
| 1447 |
|
int timer = 0; |
| 1448 |
|
int sid = (p_section == NULL ? 0 : p_section->sid); |
| 1449 |
|
int ret = -1; |
| 1450 |
|
|
| 1451 |
|
while (!SYS_server_exit) |
| 1452 |
|
{ |
| 1453 |
|
ret = section_list_try_rw_lock(p_section, SECTION_TRY_LOCK_WAIT_TIME); |
| 1454 |
|
if (ret == 0) // success |
| 1455 |
|
{ |
| 1456 |
|
break; |
| 1457 |
|
} |
| 1458 |
|
else if (errno == EAGAIN || errno == EINTR) // retry |
| 1459 |
|
{ |
| 1460 |
|
timer++; |
| 1461 |
|
if (timer % SECTION_TRY_LOCK_TIMES == 0) |
| 1462 |
|
{ |
| 1463 |
|
log_error("acquire_section_rw_lock() tried %d times on section %d\n", sid, timer); |
| 1464 |
|
} |
| 1465 |
|
} |
| 1466 |
|
else // failed |
| 1467 |
|
{ |
| 1468 |
|
log_error("acquire_section_rw_lock() failed on section %d\n", sid); |
| 1469 |
|
break; |
| 1470 |
|
} |
| 1471 |
|
} |
| 1472 |
|
|
| 1473 |
|
return ret; |
| 1474 |
} |
} |