[K/N] Add utilities to check if thread is registered now
This commit is contained in:
@@ -192,13 +192,17 @@ struct DestructorRecord {
|
||||
|
||||
static void onThreadExitCallback(void* value) {
|
||||
DestructorRecord* record = reinterpret_cast<DestructorRecord*>(value);
|
||||
pthread_setspecific(terminationKey, nullptr);
|
||||
while (record != nullptr) {
|
||||
record->destructor(record->destructorParameter);
|
||||
auto next = record->next;
|
||||
free(record);
|
||||
record = next;
|
||||
}
|
||||
pthread_setspecific(terminationKey, nullptr);
|
||||
}
|
||||
|
||||
bool isOnThreadExitNotSetOrAlreadyStarted() {
|
||||
return terminationKey != 0 && pthread_getspecific(terminationKey) == nullptr;
|
||||
}
|
||||
|
||||
#if KONAN_LINUX
|
||||
|
||||
@@ -41,6 +41,7 @@ RUNTIME_NORETURN void exit(int32_t status);
|
||||
|
||||
// Thread control.
|
||||
void onThreadExit(void (*destructor)(void*), void* destructorParameter);
|
||||
bool isOnThreadExitNotSetOrAlreadyStarted();
|
||||
|
||||
// String/byte operations.
|
||||
// memcpy/memmove/memcmp are not here intentionally, as frequently implemented/optimized
|
||||
|
||||
@@ -20,7 +20,7 @@ mm::ThreadRegistry::Node* mm::ThreadRegistry::RegisterCurrentThread() noexcept {
|
||||
auto* threadDataNode = list_.Emplace(pthread_self());
|
||||
AssertThreadState(threadDataNode->Get(), ThreadState::kNative);
|
||||
Node*& currentDataNode = currentThreadDataNode_;
|
||||
RuntimeAssert(currentDataNode == nullptr, "This thread already had some data assigned to it.");
|
||||
RuntimeAssert(!IsCurrentThreadRegistered(), "This thread already had some data assigned to it.");
|
||||
currentDataNode = threadDataNode;
|
||||
return threadDataNode;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
ALWAYS_INLINE ThreadData* CurrentThreadData() const noexcept;
|
||||
Node* CurrentThreadDataNode() const noexcept { return currentThreadDataNode_; }
|
||||
|
||||
bool IsCurrentThreadRegistered() const noexcept { return currentThreadDataNode_ != nullptr; }
|
||||
|
||||
class TestSupport {
|
||||
public:
|
||||
static void ClearCurrentThreadData() { currentThreadDataNode_ = nullptr; }
|
||||
|
||||
Reference in New Issue
Block a user