fix memory leak of dynamic creation and release of threads
This commit is contained in:
9
deps/oblib/src/lib/coro/co_routine.cpp
vendored
9
deps/oblib/src/lib/coro/co_routine.cpp
vendored
@ -144,13 +144,13 @@ void CoRoutine::__start(transfer_t from)
|
|||||||
|
|
||||||
int CoRoutine::at_create()
|
int CoRoutine::at_create()
|
||||||
{
|
{
|
||||||
CVC.at_routine_create();
|
CVC.at_routine_create(get_crls_buffer());
|
||||||
return OB_SUCCESS;
|
return OB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoRoutine::at_exit()
|
void CoRoutine::at_exit()
|
||||||
{
|
{
|
||||||
CVC.at_routine_exit();
|
CVC.at_routine_exit(get_crls_buffer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +190,11 @@ void CoMainRoutine::start()
|
|||||||
free_coidx(idx_);
|
free_coidx(idx_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoMainRoutine::at_exit()
|
||||||
|
{
|
||||||
|
CoRoutine::at_exit();
|
||||||
|
}
|
||||||
|
|
||||||
void CoMainRoutine::destroy()
|
void CoMainRoutine::destroy()
|
||||||
{
|
{
|
||||||
CoCtx::destroy(&cc_);
|
CoCtx::destroy(&cc_);
|
||||||
|
|||||||
3
deps/oblib/src/lib/coro/co_routine.h
vendored
3
deps/oblib/src/lib/coro/co_routine.h
vendored
@ -235,8 +235,7 @@ public:
|
|||||||
void start();
|
void start();
|
||||||
// Destroy resources.
|
// Destroy resources.
|
||||||
void destroy();
|
void destroy();
|
||||||
void at_exit() override
|
void at_exit() override;
|
||||||
{}
|
|
||||||
|
|
||||||
void usleep(uint32_t usec) final;
|
void usleep(uint32_t usec) final;
|
||||||
void sleep_until(int64_t abs_time) final;
|
void sleep_until(int64_t abs_time) final;
|
||||||
|
|||||||
32
deps/oblib/src/lib/coro/co_var_center.cpp
vendored
32
deps/oblib/src/lib/coro/co_var_center.cpp
vendored
@ -72,35 +72,21 @@ int CoVarCenter::register_hook(CoVarHook* hook)
|
|||||||
return static_cast<int>(num);
|
return static_cast<int>(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoVarCenter::at_routine_create()
|
void CoVarCenter::at_routine_create(char *buffer)
|
||||||
{
|
{
|
||||||
char* buffer = nullptr;
|
int64_t &num = reinterpret_cast<int64_t&>(*(&buffer[coro::CoConfig::MAX_CRLS_SIZE]-8));
|
||||||
if (OB_LIKELY(CoSched::get_active_routine() != nullptr)) {
|
|
||||||
buffer = CoSched::get_active_routine()->get_crls_buffer();
|
|
||||||
assert(buffer != nullptr);
|
|
||||||
} else {
|
|
||||||
ob_abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t& num = reinterpret_cast<int64_t&>(*(&buffer[coro::CoConfig::MAX_CRLS_SIZE] - 8));
|
|
||||||
num = 0;
|
num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoVarCenter::at_routine_exit()
|
void CoVarCenter::at_routine_exit(char *buffer)
|
||||||
{
|
{
|
||||||
if (CoSched::get_active_routine() != CoSched::get_instance()) {
|
const auto MAX_CRLS_SIZE = coro::CoConfig::MAX_CRLS_SIZE;
|
||||||
char* buffer = nullptr;
|
int64_t &num = reinterpret_cast<int64_t&>(*(&buffer[MAX_CRLS_SIZE]-8));
|
||||||
if (OB_LIKELY(CoSched::get_active_routine() != nullptr)) {
|
CoVarHook **last = reinterpret_cast<CoVarHook**>(&buffer[MAX_CRLS_SIZE]-16);
|
||||||
buffer = CoSched::get_active_routine()->get_crls_buffer();
|
for (int64_t i = num-1; i >= 0; i--) {
|
||||||
}
|
last[-i]->deinit_();
|
||||||
const auto MAX_CRLS_SIZE = coro::CoConfig::MAX_CRLS_SIZE;
|
|
||||||
int64_t& num = reinterpret_cast<int64_t&>(*(&buffer[MAX_CRLS_SIZE] - 8));
|
|
||||||
CoVarHook** last = reinterpret_cast<CoVarHook**>(&buffer[MAX_CRLS_SIZE] - 16);
|
|
||||||
for (int64_t i = num - 1; i >= 0; i--) {
|
|
||||||
last[-i]->deinit_();
|
|
||||||
}
|
|
||||||
num = 0;
|
|
||||||
}
|
}
|
||||||
|
num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace lib
|
} // namespace lib
|
||||||
|
|||||||
6
deps/oblib/src/lib/coro/co_var_center.h
vendored
6
deps/oblib/src/lib/coro/co_var_center.h
vendored
@ -72,9 +72,9 @@ public:
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int register_hook(CoVarHook* hook);
|
int register_hook(CoVarHook *hook);
|
||||||
void at_routine_create();
|
void at_routine_create(char *buffer);
|
||||||
void at_routine_exit();
|
void at_routine_exit(char *buffer);
|
||||||
|
|
||||||
static CoVarCenter& instance()
|
static CoVarCenter& instance()
|
||||||
{
|
{
|
||||||
|
|||||||
3
deps/oblib/src/lib/coro/thread.cpp
vendored
3
deps/oblib/src/lib/coro/thread.cpp
vendored
@ -229,6 +229,9 @@ void* Thread::__th_start(void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mem_context != nullptr && *mem_context != nullptr) {
|
||||||
|
DESTROY_CONTEXT(*mem_context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user