Skip to content

Commit

Permalink
thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Mar 15, 2024
1 parent 3a17c34 commit 9bc606b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 deletions ext-src/php_swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class PHPCoroutine {
bool enable_deadlock_check;
};

static zend_array *options;
static thread_local zend_array *options;

enum HookType {
HOOK_NONE = 0,
Expand Down Expand Up @@ -261,12 +261,12 @@ class PHPCoroutine {
}

protected:
static bool activated;
static PHPContext main_context;
static Config config;
static thread_local bool activated;
static thread_local PHPContext main_context;
static thread_local Config config;

static bool interrupt_thread_running;
static std::thread interrupt_thread;
static thread_local bool interrupt_thread_running;
static thread_local std::thread interrupt_thread;

static void activate();
static void deactivate(void *ptr);
Expand Down
12 changes: 6 additions & 6 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend

enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1, SW_EXIT_IN_SERVER = 1 << 2 };

bool PHPCoroutine::activated = false;
zend_array *PHPCoroutine::options = nullptr;
thread_local bool PHPCoroutine::activated = false;
thread_local zend_array *PHPCoroutine::options = nullptr;

PHPCoroutine::Config PHPCoroutine::config{
thread_local PHPCoroutine::Config PHPCoroutine::config{
SW_DEFAULT_MAX_CORO_NUM,
0,
false,
true,
};

PHPContext PHPCoroutine::main_context{};
std::thread PHPCoroutine::interrupt_thread;
bool PHPCoroutine::interrupt_thread_running = false;
thread_local PHPContext PHPCoroutine::main_context{};
thread_local std::thread PHPCoroutine::interrupt_thread;
thread_local bool PHPCoroutine::interrupt_thread_running = false;

extern void php_swoole_load_library();

Expand Down
4 changes: 2 additions & 2 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ static zend_internal_arg_info *get_arginfo(const char *name, size_t l_name) {
#define SW_HOOK_LIBRARY_FE(name, arg_info) \
ZEND_RAW_FENTRY("swoole_hook_" #name, PHP_FN(swoole_user_func_handler), arg_info, 0)

static zend_array *tmp_function_table = nullptr;
static std::unordered_map<std::string, zend_class_entry *> child_class_entries;
static thread_local zend_array *tmp_function_table = nullptr;
static thread_local std::unordered_map<std::string, zend_class_entry *> child_class_entries;

SW_EXTERN_C_BEGIN
#include "ext/standard/file.h"
Expand Down
20 changes: 10 additions & 10 deletions include/swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Coroutine {
return ctx;
}

static std::unordered_map<long, Coroutine *> coroutines;
static thread_local std::unordered_map<long, Coroutine *> coroutines;

static void set_on_yield(SwapCallback func);
static void set_on_resume(SwapCallback func);
Expand Down Expand Up @@ -245,15 +245,15 @@ class Coroutine {
static void print_list();

protected:
static Coroutine *current;
static long last_cid;
static uint64_t peak_num;
static size_t stack_size;
static SwapCallback on_yield; /* before yield */
static SwapCallback on_resume; /* before resume */
static SwapCallback on_close; /* before close */
static BailoutCallback on_bailout; /* when bailout */
static bool activated;
static thread_local Coroutine *current;
static thread_local long last_cid;
static thread_local uint64_t peak_num;
static thread_local size_t stack_size;
static thread_local SwapCallback on_yield; /* before yield */
static thread_local SwapCallback on_resume; /* before resume */
static thread_local SwapCallback on_close; /* before close */
static thread_local BailoutCallback on_bailout; /* when bailout */
static thread_local bool activated;

enum State state = STATE_INIT;
enum ResumeCode resume_code_ = RC_OK;
Expand Down
22 changes: 11 additions & 11 deletions src/coroutine/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

namespace swoole {

Coroutine *Coroutine::current = nullptr;
long Coroutine::last_cid = 0;
std::unordered_map<long, Coroutine *> Coroutine::coroutines;
uint64_t Coroutine::peak_num = 0;
bool Coroutine::activated = false;

size_t Coroutine::stack_size = SW_DEFAULT_C_STACK_SIZE;
Coroutine::SwapCallback Coroutine::on_yield = nullptr;
Coroutine::SwapCallback Coroutine::on_resume = nullptr;
Coroutine::SwapCallback Coroutine::on_close = nullptr;
Coroutine::BailoutCallback Coroutine::on_bailout = nullptr;
thread_local Coroutine *Coroutine::current = nullptr;
thread_local long Coroutine::last_cid = 0;
thread_local std::unordered_map<long, Coroutine *> Coroutine::coroutines;
thread_local uint64_t Coroutine::peak_num = 0;
thread_local bool Coroutine::activated = false;

thread_local size_t Coroutine::stack_size = SW_DEFAULT_C_STACK_SIZE;
thread_local Coroutine::SwapCallback Coroutine::on_yield = nullptr;
thread_local Coroutine::SwapCallback Coroutine::on_resume = nullptr;
thread_local Coroutine::SwapCallback Coroutine::on_close = nullptr;
thread_local Coroutine::BailoutCallback Coroutine::on_bailout = nullptr;

#ifdef SW_USE_THREAD_CONTEXT
namespace coroutine {
Expand Down

0 comments on commit 9bc606b

Please sign in to comment.