Skip to content

Commit e752c79

Browse files
committed
Avoid extern inline
I think the code is worse for doing this, but it was requested during code review and I don't care to die on this hill.
1 parent 35c5a7c commit e752c79

File tree

10 files changed

+65
-44
lines changed

10 files changed

+65
-44
lines changed

Zend/zend_atomic.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@ ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired) {
2727
ZEND_ATOMIC_BOOL_INIT(obj, desired);
2828
}
2929

30-
extern inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj,
31-
bool desired);
32-
extern inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj,
33-
bool desired);
30+
ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
31+
return zend_atomic_bool_exchange_ex(obj, desired);
32+
}
33+
34+
ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
35+
return zend_atomic_bool_store_ex(obj, desired);
36+
}
3437

3538
#if ZEND_WIN32 || HAVE_SYNC_ATOMICS
3639
/* On these platforms it is non-const due to underlying APIs. */
37-
extern inline ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj);
40+
ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
41+
return zend_atomic_bool_load_ex(obj);
42+
}
3843
#else
39-
extern inline ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj);
44+
ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
45+
return zend_atomic_bool_load_ex(obj);
46+
}
4047
#endif

Zend/zend_atomic.h

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,61 +63,61 @@ BEGIN_EXTERN_C()
6363

6464
#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
6565

66-
inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
66+
static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
6767
return InterlockedExchange8(&obj->value, desired);
6868
}
6969

7070
/* On this platform it is non-const due to Iterlocked API*/
71-
inline ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
71+
static zend_always_inline bool zend_atomic_bool_load_ex(zend_atomic_bool *obj) {
7272
/* Or'ing with false won't change the value. */
7373
return InterlockedOr8(&obj->value, false);
7474
}
7575

76-
inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
76+
static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
7777
(void)InterlockedExchange8(&obj->value, desired);
7878
}
7979

8080
#elif HAVE_C11_ATOMICS
8181

8282
#define ZEND_ATOMIC_BOOL_INIT(obj, desired) __c11_atomic_init(&(obj)->value, (desired))
8383

84-
inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
84+
static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
8585
return __c11_atomic_exchange(&obj->value, desired, __ATOMIC_SEQ_CST);
8686
}
8787

88-
inline ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
88+
static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
8989
return __c11_atomic_load(&obj->value, __ATOMIC_SEQ_CST);
9090
}
9191

92-
inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
92+
static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
9393
__c11_atomic_store(&obj->value, desired, __ATOMIC_SEQ_CST);
9494
}
9595

9696
#elif HAVE_GNUC_ATOMICS
9797

9898
#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
9999

100-
inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
100+
static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
101101
bool prev = false;
102102
__atomic_exchange(&obj->value, &desired, &prev, __ATOMIC_SEQ_CST);
103103
return prev;
104104
}
105105

106-
inline ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
106+
static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
107107
bool prev = false;
108108
__atomic_load(&obj->value, &prev, __ATOMIC_SEQ_CST);
109109
return prev;
110110
}
111111

112-
inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
112+
static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
113113
__atomic_store(&obj->value, &desired, __ATOMIC_SEQ_CST);
114114
}
115115

116116
#elif HAVE_SYNC_ATOMICS
117117

118118
#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
119119

120-
inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
120+
static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
121121
bool prev = __sync_lock_test_and_set(&obj->value, desired);
122122

123123
/* __sync_lock_test_and_set only does an acquire barrier, so sync
@@ -127,12 +127,12 @@ inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desir
127127
return prev;
128128
}
129129

130-
inline ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
130+
static zend_always_inline bool zend_atomic_bool_load_ex(zend_atomic_bool *obj) {
131131
/* Or'ing false won't change the value */
132132
return __sync_fetch_and_or(&obj->value, false);
133133
}
134134

135-
inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
135+
static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
136136
__sync_synchronize();
137137
obj->value = desired;
138138
__sync_synchronize();
@@ -147,25 +147,39 @@ inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired)
147147
* improvement. As more platforms support C11 atomics, or as we add support
148148
* for more platforms through intrinsics/asm, this should be used less and
149149
* less until it can be removed.
150-
* At the time of this writing, all platforms in CI avoided this fallback.
150+
* At the time of this writing, all platforms in CI avoided this fallback,
151+
* so we emit an error. If there ends up being some platform that needs it,
152+
* we can remove the error or add support for whatever platform that is.
151153
*/
154+
#error No atomics support detected. Please open an issue with platform deatils.
152155

153-
inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
156+
static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
154157
obj->value = desired;
155158
}
156159

157-
inline ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
160+
static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
158161
return obj->value;
159162
}
160163

161-
inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
164+
static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
162165
bool prev = obj->value;
163166
obj->value = true;
164167
return prev;
165168
}
166169

167170
#endif
168171

172+
ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired);
173+
ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired);
174+
ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired);
175+
176+
#if ZEND_WIN32 || HAVE_SYNC_ATOMICS
177+
/* On these platforms it is non-const due to underlying APIs. */
178+
ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj);
179+
#else
180+
ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj);
181+
#endif
182+
169183
END_EXTERN_C()
170184

171185
#endif

Zend/zend_execute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,13 +3726,13 @@ ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data *exec
37263726
/* }}} */
37273727

37283728
#define ZEND_VM_INTERRUPT_CHECK() do { \
3729-
if (UNEXPECTED(zend_atomic_bool_load(&EG(vm_interrupt)))) { \
3729+
if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
37303730
ZEND_VM_INTERRUPT(); \
37313731
} \
37323732
} while (0)
37333733

37343734
#define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \
3735-
if (UNEXPECTED(zend_atomic_bool_load(&EG(vm_interrupt)))) { \
3735+
if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
37363736
ZEND_VM_LOOP_INTERRUPT(); \
37373737
} \
37383738
} while (0)

Zend/zend_execute_API.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,8 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
960960

961961
/* This flag is regularly checked while running user functions, but not internal
962962
* So see whether interrupt flag was set while the function was running... */
963-
if (zend_atomic_bool_exchange(&EG(vm_interrupt), false)) {
964-
if (zend_atomic_bool_load(&EG(timed_out))) {
963+
if (zend_atomic_bool_exchange_ex(&EG(vm_interrupt), false)) {
964+
if (zend_atomic_bool_load_ex(&EG(timed_out))) {
965965
zend_timeout();
966966
} else if (zend_interrupt_function) {
967967
zend_interrupt_function(EG(current_execute_data));
@@ -1329,14 +1329,14 @@ ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void) /* {{{ */
13291329
timer is not restarted properly, it could hang in the shutdown
13301330
function. */
13311331
if (EG(hard_timeout) > 0) {
1332-
zend_atomic_bool_store(&EG(timed_out), false);
1332+
zend_atomic_bool_store_ex(&EG(timed_out), false);
13331333
zend_set_timeout_ex(EG(hard_timeout), 1);
13341334
/* XXX Abused, introduce an additional flag if the value needs to be kept. */
13351335
EG(hard_timeout) = 0;
13361336
}
13371337
# endif
13381338
#else
1339-
zend_atomic_bool_store(&EG(timed_out), false);
1339+
zend_atomic_bool_store_ex(&EG(timed_out), false);
13401340
zend_set_timeout_ex(0, 1);
13411341
#endif
13421342

@@ -1348,7 +1348,7 @@ ZEND_API ZEND_NORETURN void ZEND_FASTCALL zend_timeout(void) /* {{{ */
13481348
static void zend_timeout_handler(int dummy) /* {{{ */
13491349
{
13501350
#ifndef ZTS
1351-
if (zend_atomic_bool_load(&EG(timed_out))) {
1351+
if (zend_atomic_bool_load_ex(&EG(timed_out))) {
13521352
/* Die on hard timeout */
13531353
const char *error_filename = NULL;
13541354
uint32_t error_lineno = 0;
@@ -1383,8 +1383,8 @@ static void zend_timeout_handler(int dummy) /* {{{ */
13831383
zend_on_timeout(EG(timeout_seconds));
13841384
}
13851385

1386-
zend_atomic_bool_store(&EG(timed_out), true);
1387-
zend_atomic_bool_store(&EG(vm_interrupt), true);
1386+
zend_atomic_bool_store_ex(&EG(timed_out), true);
1387+
zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
13881388

13891389
#ifndef ZTS
13901390
if (EG(hard_timeout) > 0) {
@@ -1408,8 +1408,8 @@ VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
14081408
}
14091409

14101410
eg = (zend_executor_globals *)arg;
1411-
zend_atomic_bool_store(&eg->timed_out, true);
1412-
zend_atomic_bool_store(&eg->vm_interrupt, true);
1411+
zend_atomic_bool_store_ex(&eg->timed_out, true);
1412+
zend_atomic_bool_store_ex(&eg->vm_interrupt, true);
14131413
}
14141414
#endif
14151415

@@ -1495,7 +1495,7 @@ void zend_set_timeout(zend_long seconds, bool reset_signals) /* {{{ */
14951495

14961496
EG(timeout_seconds) = seconds;
14971497
zend_set_timeout_ex(seconds, reset_signals);
1498-
zend_atomic_bool_store(&EG(timed_out), false);
1498+
zend_atomic_bool_store_ex(&EG(timed_out), false);
14991499
}
15001500
/* }}} */
15011501

@@ -1504,7 +1504,7 @@ void zend_unset_timeout(void) /* {{{ */
15041504
#ifdef ZEND_WIN32
15051505
if (NULL != tq_timer) {
15061506
if (!DeleteTimerQueueTimer(NULL, tq_timer, INVALID_HANDLE_VALUE)) {
1507-
zend_atomic_bool_store(&EG(timed_out), false);
1507+
zend_atomic_bool_store_ex(&EG(timed_out), false);
15081508
tq_timer = NULL;
15091509
zend_error_noreturn(E_ERROR, "Could not delete queued timer");
15101510
return;
@@ -1524,7 +1524,7 @@ void zend_unset_timeout(void) /* {{{ */
15241524
# endif
15251525
}
15261526
#endif
1527-
zend_atomic_bool_store(&EG(timed_out), false);
1527+
zend_atomic_bool_store_ex(&EG(timed_out), false);
15281528
}
15291529
/* }}} */
15301530

Zend/zend_vm_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9892,9 +9892,9 @@ ZEND_VM_DEFINE_OP(137, ZEND_OP_DATA);
98929892

98939893
ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY)
98949894
{
9895-
zend_atomic_bool_store(&EG(vm_interrupt), false);
9895+
zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
98969896
SAVE_OPLINE();
9897-
if (zend_atomic_bool_load(&EG(timed_out))) {
9897+
if (zend_atomic_bool_load_ex(&EG(timed_out))) {
98989898
zend_timeout();
98999899
} else if (zend_interrupt_function) {
99009900
zend_interrupt_function(execute_data);

Zend/zend_vm_execute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,9 +3537,9 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_JMP_FORWARD_SPEC_H
35373537

35383538
static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_interrupt_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
35393539
{
3540-
zend_atomic_bool_store(&EG(vm_interrupt), false);
3540+
zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
35413541
SAVE_OPLINE();
3542-
if (zend_atomic_bool_load(&EG(timed_out))) {
3542+
if (zend_atomic_bool_load_ex(&EG(timed_out))) {
35433543
zend_timeout();
35443544
} else if (zend_interrupt_function) {
35453545
zend_interrupt_function(execute_data);

ext/opcache/jit/zend_jit_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8052,7 +8052,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num, zend_jit_registers_buf
80528052
EX(opline) = opline;
80538053
}
80548054

8055-
if (zend_atomic_bool_load(&EG(vm_interrupt)) || JIT_G(tracing)) {
8055+
if (zend_atomic_bool_load_ex(&EG(vm_interrupt)) || JIT_G(tracing)) {
80568056
return 1;
80578057
/* Lock-free check if the side trace was already JIT-ed or blacklist-ed in another process */
80588058
} else if (t->exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED)) {

ext/pcntl/pcntl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ static void pcntl_signal_handler(int signo)
13831383
PCNTL_G(tail) = psig;
13841384
PCNTL_G(pending_signals) = 1;
13851385
if (PCNTL_G(async_signals)) {
1386-
zend_atomic_bool_store(&EG(vm_interrupt), true);
1386+
zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
13871387
}
13881388
}
13891389

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
16631663
}
16641664

16651665
#ifdef ZEND_WIN32
1666-
if (zend_atomic_bool_load(&EG(timed_out))) {
1666+
if (zend_atomic_bool_load_ex(&EG(timed_out))) {
16671667
zend_timeout();
16681668
}
16691669
#endif

win32/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static BOOL WINAPI php_win32_signal_system_ctrl_handler(DWORD evt)
7777
return FALSE;
7878
}
7979

80-
zend_atomic_bool_store(vm_interrupt_flag, true);
80+
zend_atomic_bool_store_ex(vm_interrupt_flag, true);
8181

8282
ctrl_evt = evt;
8383

0 commit comments

Comments
 (0)