Skip to content

Commit

Permalink
Optimize thread context
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 23, 2024
1 parent afecffc commit 0a2671f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
3 changes: 1 addition & 2 deletions ext-src/php_swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class PHPCoroutine {
}

static inline void init_main_context() {
main_context.co = Coroutine::init_main_coroutine();
main_context.co = nullptr;
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
main_context.fiber_context = EG(main_fiber_context);
main_context.fiber_init_notified = true;
Expand All @@ -261,7 +261,6 @@ class PHPCoroutine {
}

static inline void free_main_context() {
delete main_context.co;
main_context = {};
}

Expand Down
6 changes: 0 additions & 6 deletions include/swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@ class Coroutine {
#endif
}

static inline Coroutine *init_main_coroutine() {
Coroutine *co = new Coroutine(0, nullptr, nullptr);
co->state = STATE_RUNNING;
return co;
}

static void activate();
static void deactivate();

Expand Down
8 changes: 4 additions & 4 deletions include/swoole_coroutine_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ typedef fcontext_t coroutine_context_t;
typedef transfer_t coroutine_transfer_t;
#endif

#if defined(USE_UCONTEXT) || defined(SW_USE_THREAD_CONTEXT)
typedef void * coroutine_transfer_t;
#endif

typedef std::function<void(void *)> CoroutineFunc;

namespace swoole {
Expand Down Expand Up @@ -90,11 +94,7 @@ class Context {
void *private_data_;
bool end_;

#if defined(USE_UCONTEXT) || defined(SW_USE_THREAD_CONTEXT)
static void context_func(void *arg);
#else
static void context_func(coroutine_transfer_t arg);
#endif
};

} // namespace coroutine
Expand Down
4 changes: 1 addition & 3 deletions src/coroutine/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ bool Context::swap_out() {
#endif
}

void Context::context_func(
void Context::context_func(coroutine_transfer_t arg) {
#if defined(USE_UCONTEXT) || defined(SW_USE_THREAD_CONTEXT)
void *arg) {
auto *_this = (Context *) arg;
#else
coroutine_transfer_t arg) {
auto *_this = (Context *) arg.data;
_this->swap_ctx_ = arg.fctx;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/coroutine/thread_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ bool Context::swap_out() {
return true;
}

void Context::context_func(void *arg) {
void Context::context_func(coroutine_transfer_t arg) {
swoole_signal_block_all();
Context *_this = (Context *) arg;
SwooleTG.reactor = g_reactor;
Expand Down

0 comments on commit 0a2671f

Please sign in to comment.