diff --git a/ext-src/swoole_process.cc b/ext-src/swoole_process.cc
index a23c4ca0e40..bd611292361 100644
--- a/ext-src/swoole_process.cc
+++ b/ext-src/swoole_process.cc
@@ -544,7 +544,11 @@ static PHP_METHOD(swoole_process, signal) {
if (zcallback == nullptr) {
fci_cache = signal_fci_caches[signo];
if (fci_cache) {
+#ifdef SW_USE_THREAD_CONTEXT
+ swoole_event_defer([signo](void *) { swoole_signal_set(signo, nullptr); }, nullptr);
+#else
swoole_signal_set(signo, nullptr);
+#endif
signal_fci_caches[signo] = nullptr;
swoole_event_defer(sw_zend_fci_cache_free, fci_cache);
SwooleTG.signal_listener_num--;
@@ -576,7 +580,11 @@ static PHP_METHOD(swoole_process, signal) {
SwooleTG.signal_listener_num++;
}
signal_fci_caches[signo] = fci_cache;
+#ifdef SW_USE_THREAD_CONTEXT
+ swoole_event_defer([signo, handler](void *) { swoole_signal_set(signo, handler); }, nullptr);
+#else
swoole_signal_set(signo, handler);
+#endif
RETURN_TRUE;
}
@@ -601,7 +609,11 @@ static PHP_METHOD(swoole_process, signal) {
// use user settings
SwooleG.use_signalfd = SwooleG.enable_signalfd;
+#ifdef SW_USE_THREAD_CONTEXT
+ swoole_event_defer([signo, handler](void *) { swoole_signal_set(signo, handler); }, nullptr);
+#else
swoole_signal_set(signo, handler);
+#endif
RETURN_TRUE;
}
diff --git a/package.xml b/package.xml
index 9da3db39290..42e7575dd29 100644
--- a/package.xml
+++ b/package.xml
@@ -2288,5 +2288,9 @@
+
+
+
+
diff --git a/src/coroutine/system.cc b/src/coroutine/system.cc
index 349f95883ec..4ef750bf5d7 100644
--- a/src/coroutine/system.cc
+++ b/src/coroutine/system.cc
@@ -269,6 +269,20 @@ bool System::wait_signal(int signo, double timeout) {
}
/* always enable signalfd */
SwooleG.use_signalfd = SwooleG.enable_signalfd = 1;
+
+#ifdef SW_USE_THREAD_CONTEXT
+ swoole_event_defer(
+ [signo](void *) {
+ swoole_signal_set(signo, [](int signo) {
+ Coroutine *co = listeners[signo];
+ if (co) {
+ listeners[signo] = nullptr;
+ co->resume();
+ }
+ });
+ },
+ nullptr);
+#else
swoole_signal_set(signo, [](int signo) {
Coroutine *co = listeners[signo];
if (co) {
@@ -276,6 +290,8 @@ bool System::wait_signal(int signo, double timeout) {
co->resume();
}
});
+#endif
+
SwooleTG.co_signal_listener_num++;
TimerNode *timer = nullptr;
@@ -299,7 +315,12 @@ bool System::wait_signal(int signo, double timeout) {
};
co->yield(&cancel_fn);
+#ifdef SW_USE_THREAD_CONTEXT
+ swoole_event_defer([signo](void *) { swoole_signal_set(signo, nullptr); }, nullptr);
+#else
swoole_signal_set(signo, nullptr);
+#endif
+
SwooleTG.co_signal_listener_num--;
if (listeners[signo] != nullptr) {
@@ -506,15 +527,16 @@ struct EventWaiter {
}
if (timeout > 0) {
- timer = swoole_timer_add(timeout,
- false,
- [](Timer *timer, TimerNode *tnode) {
- EventWaiter *waiter = (EventWaiter *) tnode->data;
- waiter->timer = nullptr;
- waiter->error_ = ETIMEDOUT;
- waiter->co->resume();
- },
- this);
+ timer = swoole_timer_add(
+ timeout,
+ false,
+ [](Timer *timer, TimerNode *tnode) {
+ EventWaiter *waiter = (EventWaiter *) tnode->data;
+ waiter->timer = nullptr;
+ waiter->error_ = ETIMEDOUT;
+ waiter->co->resume();
+ },
+ this);
}
co->yield(&cancel_fn);
@@ -642,7 +664,7 @@ bool async(async::Handler handler, AsyncEvent &event, double timeout) {
return false;
} else {
event.canceled = _ev->canceled;
- event.error = errno = _ev->error;
+ event.error = errno = _ev->error;
event.retval = _ev->retval;
return true;
}
diff --git a/src/coroutine/thread_context.cc b/src/coroutine/thread_context.cc
index 56c8b4abdf5..7a4887a6bf9 100644
--- a/src/coroutine/thread_context.cc
+++ b/src/coroutine/thread_context.cc
@@ -16,6 +16,7 @@
#include "swoole_api.h"
#include "swoole_async.h"
+#include "swoole_signal.h"
#include "swoole_coroutine_context.h"
#ifdef SW_USE_THREAD_CONTEXT
@@ -84,6 +85,7 @@ bool Context::swap_out() {
}
void Context::context_func(void *arg) {
+ swoole_signal_block_all();
Context *_this = (Context *) arg;
SwooleTG.reactor = g_reactor;
SwooleTG.timer = g_timer;