Skip to content

Commit 20a1d5d

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 27ef451 + aef9660 commit 20a1d5d

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

sapi/litespeed/lsapilib.c

+43-35
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ static void lsapi_close_connection(LSAPI_Request *pReq)
442442
lsapi_close(pReq->m_fd);
443443
pReq->m_fd = -1;
444444
if (s_busy_workers)
445-
__sync_fetch_and_sub(s_busy_workers, 1);
445+
__atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
446446
if (s_worker_status)
447-
__sync_lock_test_and_set(&s_worker_status->m_state, LSAPI_STATE_IDLE);
447+
__atomic_store_n(&s_worker_status->m_state, LSAPI_STATE_IDLE,
448+
__ATOMIC_SEQ_CST);
448449
}
449450

450451

@@ -1588,10 +1589,10 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
15881589
else
15891590
{
15901591
if (s_worker_status)
1591-
__sync_lock_test_and_set(&s_worker_status->m_state,
1592-
LSAPI_STATE_CONNECTED);
1592+
__atomic_store_n(&s_worker_status->m_state,
1593+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
15931594
if (s_busy_workers)
1594-
__sync_fetch_and_add(s_busy_workers, 1);
1595+
__atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
15951596
lsapi_set_nblock( pReq->m_fd , 0 );
15961597
if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
15971598
{
@@ -2919,16 +2920,18 @@ void LSAPI_reset_server_state( void )
29192920
++pStatus;
29202921
}
29212922
if (s_busy_workers)
2922-
__sync_lock_release(s_busy_workers);
2923+
__atomic_store_n(s_busy_workers, 0, __ATOMIC_SEQ_CST);
29232924
if (s_accepting_workers)
2924-
__sync_lock_release(s_accepting_workers);
2925+
__atomic_store_n(s_accepting_workers, 0, __ATOMIC_SEQ_CST);
29252926

29262927
}
29272928

29282929

29292930
static void lsapi_sigchild( int signal )
29302931
{
29312932
int status, pid;
2933+
char expect_connected = LSAPI_STATE_CONNECTED;
2934+
char expect_accepting = LSAPI_STATE_ACCEPTING;
29322935
lsapi_child_status * child_status;
29332936
if (g_prefork_server == NULL)
29342937
return;
@@ -2965,19 +2968,23 @@ static void lsapi_sigchild( int signal )
29652968
child_status = find_child_status( pid );
29662969
if ( child_status )
29672970
{
2968-
if (__sync_bool_compare_and_swap(&child_status->m_state,
2969-
LSAPI_STATE_CONNECTED,
2970-
LSAPI_STATE_IDLE))
2971+
if (__atomic_compare_exchange_n(&child_status->m_state,
2972+
&expect_connected,
2973+
LSAPI_STATE_IDLE, 1,
2974+
__ATOMIC_SEQ_CST,
2975+
__ATOMIC_SEQ_CST))
29712976
{
29722977
if (s_busy_workers)
2973-
__sync_fetch_and_sub(s_busy_workers, 1);
2978+
__atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
29742979
}
2975-
else if (__sync_bool_compare_and_swap(&child_status->m_state,
2976-
LSAPI_STATE_ACCEPTING,
2977-
LSAPI_STATE_IDLE))
2980+
else if (__atomic_compare_exchange_n(&child_status->m_state,
2981+
&expect_accepting,
2982+
LSAPI_STATE_IDLE, 1,
2983+
__ATOMIC_SEQ_CST,
2984+
__ATOMIC_SEQ_CST))
29782985
{
29792986
if (s_accepting_workers)
2980-
__sync_fetch_and_sub(s_accepting_workers, 1);
2987+
__atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
29812988
}
29822989
child_status->m_pid = 0;
29832990
--g_prefork_server->m_iCurChildren;
@@ -3250,7 +3257,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
32503257
{
32513258
int accepting = 0;
32523259
if (s_accepting_workers)
3253-
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3260+
accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
32543261

32553262
if (pServer->m_iCurChildren > 0
32563263
&& accepting > 0)
@@ -3316,10 +3323,10 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
33163323
if (pthread_atfork_func)
33173324
(*pthread_atfork_func)(NULL, NULL, set_skip_write);
33183325

3319-
__sync_lock_test_and_set(&s_worker_status->m_state,
3320-
LSAPI_STATE_CONNECTED);
3326+
__atomic_store_n(&s_worker_status->m_state,
3327+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
33213328
if (s_busy_workers)
3322-
__sync_add_and_fetch(s_busy_workers, 1);
3329+
__atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
33233330
lsapi_set_nblock( pReq->m_fd, 0 );
33243331
//keep it open if busy_count is used.
33253332
if (!s_keep_listener && s_busy_workers
@@ -3391,7 +3398,7 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
33913398
{
33923399
int max_children = g_prefork_server->m_iMaxChildren;
33933400
s_pid = getpid();
3394-
__sync_lock_test_and_set(&pReq->child_status->m_pid, s_pid);
3401+
__atomic_store_n(&pReq->child_status->m_pid, s_pid, __ATOMIC_SEQ_CST);
33953402
s_worker_status = pReq->child_status;
33963403

33973404
setsid();
@@ -3403,10 +3410,10 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
34033410
if (pthread_atfork_func)
34043411
(*pthread_atfork_func)(NULL, NULL, set_skip_write);
34053412

3406-
__sync_lock_test_and_set(&s_worker_status->m_state,
3407-
LSAPI_STATE_CONNECTED);
3413+
__atomic_store_n(&s_worker_status->m_state,
3414+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
34083415
if (s_busy_workers)
3409-
__sync_add_and_fetch(s_busy_workers, 1);
3416+
__atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
34103417
lsapi_set_nblock( pReq->m_fd, 0 );
34113418
//keep it open if busy_count is used.
34123419
if (!s_keep_listener && s_busy_workers
@@ -3523,7 +3530,7 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
35233530
{
35243531
int accepting = 0;
35253532
if (s_accepting_workers)
3526-
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3533+
accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
35273534

35283535
if (pServer->m_iCurChildren > 0
35293536
&& accepting > 0)
@@ -3608,7 +3615,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36083615
}
36093616
else if (s_req_processed > 0 && s_max_busy_workers > 0 && s_busy_workers)
36103617
{
3611-
ret = __sync_fetch_and_add(s_busy_workers, 0);
3618+
ret = __atomic_load_n(s_busy_workers, __ATOMIC_SEQ_CST);
36123619
if (ret >= s_max_busy_workers)
36133620
{
36143621
send_conn_close_notification(pReq->m_fd);
@@ -3652,19 +3659,19 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36523659
if (fd == pReq->m_fdListen)
36533660
{
36543661
if (s_worker_status)
3655-
__sync_lock_test_and_set(&s_worker_status->m_state,
3656-
LSAPI_STATE_ACCEPTING);
3662+
__atomic_store_n(&s_worker_status->m_state,
3663+
LSAPI_STATE_ACCEPTING, __ATOMIC_SEQ_CST);
36573664
if (s_accepting_workers)
3658-
__sync_fetch_and_add(s_accepting_workers, 1);
3665+
__atomic_fetch_add(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
36593666
}
36603667
ret = (*g_fnSelect)(fd+1, &readfds, NULL, NULL, &timeout);
36613668
if (fd == pReq->m_fdListen)
36623669
{
36633670
if (s_accepting_workers)
3664-
__sync_fetch_and_sub(s_accepting_workers, 1);
3671+
__atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
36653672
if (s_worker_status)
3666-
__sync_lock_test_and_set(&s_worker_status->m_state,
3667-
LSAPI_STATE_IDLE);
3673+
__atomic_store_n(&s_worker_status->m_state,
3674+
LSAPI_STATE_IDLE, __ATOMIC_SEQ_CST);
36683675
}
36693676

36703677
if ( ret == 0 )
@@ -3712,10 +3719,11 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
37123719
if ( pReq->m_fd != -1 )
37133720
{
37143721
if (s_worker_status)
3715-
__sync_lock_test_and_set(&s_worker_status->m_state,
3716-
LSAPI_STATE_CONNECTED);
3722+
__atomic_store_n(&s_worker_status->m_state,
3723+
LSAPI_STATE_CONNECTED,
3724+
__ATOMIC_SEQ_CST);
37173725
if (s_busy_workers)
3718-
__sync_fetch_and_add(s_busy_workers, 1);
3726+
__atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
37193727

37203728
fd = pReq->m_fd;
37213729

@@ -4386,5 +4394,5 @@ int LSAPI_Set_Restored_Parent_Pid(int pid)
43864394

43874395
int LSAPI_Inc_Req_Processed(int cnt)
43884396
{
4389-
return __sync_add_and_fetch(s_global_counter, cnt);
4397+
return __atomic_add_fetch(s_global_counter, cnt, __ATOMIC_SEQ_CST);
43904398
}

0 commit comments

Comments
 (0)