Skip to content

Commit aef9660

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents 5e307d0 + aee1a2f commit aef9660

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
@@ -441,9 +441,10 @@ static void lsapi_close_connection(LSAPI_Request *pReq)
441441
lsapi_close(pReq->m_fd);
442442
pReq->m_fd = -1;
443443
if (s_busy_workers)
444-
__sync_fetch_and_sub(s_busy_workers, 1);
444+
__atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
445445
if (s_worker_status)
446-
__sync_lock_test_and_set(&s_worker_status->m_state, LSAPI_STATE_IDLE);
446+
__atomic_store_n(&s_worker_status->m_state, LSAPI_STATE_IDLE,
447+
__ATOMIC_SEQ_CST);
447448
}
448449

449450

@@ -1587,10 +1588,10 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
15871588
else
15881589
{
15891590
if (s_worker_status)
1590-
__sync_lock_test_and_set(&s_worker_status->m_state,
1591-
LSAPI_STATE_CONNECTED);
1591+
__atomic_store_n(&s_worker_status->m_state,
1592+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
15921593
if (s_busy_workers)
1593-
__sync_fetch_and_add(s_busy_workers, 1);
1594+
__atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
15941595
lsapi_set_nblock( pReq->m_fd , 0 );
15951596
if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
15961597
{
@@ -2918,16 +2919,18 @@ void LSAPI_reset_server_state( void )
29182919
++pStatus;
29192920
}
29202921
if (s_busy_workers)
2921-
__sync_lock_release(s_busy_workers);
2922+
__atomic_store_n(s_busy_workers, 0, __ATOMIC_SEQ_CST);
29222923
if (s_accepting_workers)
2923-
__sync_lock_release(s_accepting_workers);
2924+
__atomic_store_n(s_accepting_workers, 0, __ATOMIC_SEQ_CST);
29242925

29252926
}
29262927

29272928

29282929
static void lsapi_sigchild( int signal )
29292930
{
29302931
int status, pid;
2932+
char expect_connected = LSAPI_STATE_CONNECTED;
2933+
char expect_accepting = LSAPI_STATE_ACCEPTING;
29312934
lsapi_child_status * child_status;
29322935
if (g_prefork_server == NULL)
29332936
return;
@@ -2964,19 +2967,23 @@ static void lsapi_sigchild( int signal )
29642967
child_status = find_child_status( pid );
29652968
if ( child_status )
29662969
{
2967-
if (__sync_bool_compare_and_swap(&child_status->m_state,
2968-
LSAPI_STATE_CONNECTED,
2969-
LSAPI_STATE_IDLE))
2970+
if (__atomic_compare_exchange_n(&child_status->m_state,
2971+
&expect_connected,
2972+
LSAPI_STATE_IDLE, 1,
2973+
__ATOMIC_SEQ_CST,
2974+
__ATOMIC_SEQ_CST))
29702975
{
29712976
if (s_busy_workers)
2972-
__sync_fetch_and_sub(s_busy_workers, 1);
2977+
__atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
29732978
}
2974-
else if (__sync_bool_compare_and_swap(&child_status->m_state,
2975-
LSAPI_STATE_ACCEPTING,
2976-
LSAPI_STATE_IDLE))
2979+
else if (__atomic_compare_exchange_n(&child_status->m_state,
2980+
&expect_accepting,
2981+
LSAPI_STATE_IDLE, 1,
2982+
__ATOMIC_SEQ_CST,
2983+
__ATOMIC_SEQ_CST))
29772984
{
29782985
if (s_accepting_workers)
2979-
__sync_fetch_and_sub(s_accepting_workers, 1);
2986+
__atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
29802987
}
29812988
child_status->m_pid = 0;
29822989
--g_prefork_server->m_iCurChildren;
@@ -3249,7 +3256,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
32493256
{
32503257
int accepting = 0;
32513258
if (s_accepting_workers)
3252-
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3259+
accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
32533260

32543261
if (pServer->m_iCurChildren > 0
32553262
&& accepting > 0)
@@ -3315,10 +3322,10 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
33153322
if (pthread_atfork_func)
33163323
(*pthread_atfork_func)(NULL, NULL, set_skip_write);
33173324

3318-
__sync_lock_test_and_set(&s_worker_status->m_state,
3319-
LSAPI_STATE_CONNECTED);
3325+
__atomic_store_n(&s_worker_status->m_state,
3326+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
33203327
if (s_busy_workers)
3321-
__sync_add_and_fetch(s_busy_workers, 1);
3328+
__atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
33223329
lsapi_set_nblock( pReq->m_fd, 0 );
33233330
//keep it open if busy_count is used.
33243331
if (!s_keep_listener && s_busy_workers
@@ -3390,7 +3397,7 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
33903397
{
33913398
int max_children = g_prefork_server->m_iMaxChildren;
33923399
s_pid = getpid();
3393-
__sync_lock_test_and_set(&pReq->child_status->m_pid, s_pid);
3400+
__atomic_store_n(&pReq->child_status->m_pid, s_pid, __ATOMIC_SEQ_CST);
33943401
s_worker_status = pReq->child_status;
33953402

33963403
setsid();
@@ -3402,10 +3409,10 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
34023409
if (pthread_atfork_func)
34033410
(*pthread_atfork_func)(NULL, NULL, set_skip_write);
34043411

3405-
__sync_lock_test_and_set(&s_worker_status->m_state,
3406-
LSAPI_STATE_CONNECTED);
3412+
__atomic_store_n(&s_worker_status->m_state,
3413+
LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
34073414
if (s_busy_workers)
3408-
__sync_add_and_fetch(s_busy_workers, 1);
3415+
__atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
34093416
lsapi_set_nblock( pReq->m_fd, 0 );
34103417
//keep it open if busy_count is used.
34113418
if (!s_keep_listener && s_busy_workers
@@ -3522,7 +3529,7 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
35223529
{
35233530
int accepting = 0;
35243531
if (s_accepting_workers)
3525-
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3532+
accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
35263533

35273534
if (pServer->m_iCurChildren > 0
35283535
&& accepting > 0)
@@ -3607,7 +3614,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36073614
}
36083615
else if (s_req_processed > 0 && s_max_busy_workers > 0 && s_busy_workers)
36093616
{
3610-
ret = __sync_fetch_and_add(s_busy_workers, 0);
3617+
ret = __atomic_load_n(s_busy_workers, __ATOMIC_SEQ_CST);
36113618
if (ret >= s_max_busy_workers)
36123619
{
36133620
send_conn_close_notification(pReq->m_fd);
@@ -3651,19 +3658,19 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36513658
if (fd == pReq->m_fdListen)
36523659
{
36533660
if (s_worker_status)
3654-
__sync_lock_test_and_set(&s_worker_status->m_state,
3655-
LSAPI_STATE_ACCEPTING);
3661+
__atomic_store_n(&s_worker_status->m_state,
3662+
LSAPI_STATE_ACCEPTING, __ATOMIC_SEQ_CST);
36563663
if (s_accepting_workers)
3657-
__sync_fetch_and_add(s_accepting_workers, 1);
3664+
__atomic_fetch_add(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
36583665
}
36593666
ret = (*g_fnSelect)(fd+1, &readfds, NULL, NULL, &timeout);
36603667
if (fd == pReq->m_fdListen)
36613668
{
36623669
if (s_accepting_workers)
3663-
__sync_fetch_and_sub(s_accepting_workers, 1);
3670+
__atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
36643671
if (s_worker_status)
3665-
__sync_lock_test_and_set(&s_worker_status->m_state,
3666-
LSAPI_STATE_IDLE);
3672+
__atomic_store_n(&s_worker_status->m_state,
3673+
LSAPI_STATE_IDLE, __ATOMIC_SEQ_CST);
36673674
}
36683675

36693676
if ( ret == 0 )
@@ -3711,10 +3718,11 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
37113718
if ( pReq->m_fd != -1 )
37123719
{
37133720
if (s_worker_status)
3714-
__sync_lock_test_and_set(&s_worker_status->m_state,
3715-
LSAPI_STATE_CONNECTED);
3721+
__atomic_store_n(&s_worker_status->m_state,
3722+
LSAPI_STATE_CONNECTED,
3723+
__ATOMIC_SEQ_CST);
37163724
if (s_busy_workers)
3717-
__sync_fetch_and_add(s_busy_workers, 1);
3725+
__atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
37183726

37193727
fd = pReq->m_fd;
37203728

@@ -4385,5 +4393,5 @@ int LSAPI_Set_Restored_Parent_Pid(int pid)
43854393

43864394
int LSAPI_Inc_Req_Processed(int cnt)
43874395
{
4388-
return __sync_add_and_fetch(s_global_counter, cnt);
4396+
return __atomic_add_fetch(s_global_counter, cnt, __ATOMIC_SEQ_CST);
43894397
}

0 commit comments

Comments
 (0)