Skip to content

Commit

Permalink
Merge pull request clementgallet#580 from CasualPokePlayer/native_fla…
Browse files Browse the repository at this point in the history
…g_to_native_thread

Ensure that native created threads will be passed the native flag
  • Loading branch information
clementgallet authored Oct 22, 2023
2 parents 1f4f3d7 + 8410a8b commit dcad788
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/library/checkpoint/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ ThreadInfo* ThreadManager::getNewThread()

/* No free thread, create a new one */
if (!thread) {
thread = new ThreadInfo;
thread = new ThreadInfo();
debuglogstdio(LCF_THREAD, "Allocate a new ThreadInfo struct");
threadListChanged = true;
}
Expand Down
19 changes: 17 additions & 2 deletions src/library/pthreadwrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,29 @@ static void *pthread_start(void *arg)
return thread->retval;
}

static void *pthread_native_start(void *arg)
{
ThreadInfo* thread = static_cast<ThreadInfo*>(arg);
ThreadManager::update(thread);

auto thread_start = thread->start;
auto thread_arg = thread->arg;
delete thread;

return thread_start(thread_arg);
}


/* Override */ int pthread_create (pthread_t * tid_p, const pthread_attr_t * attr, void * (* start_routine) (void *), void * arg) __THROW
{
LINK_NAMESPACE(pthread_create, "pthread");
LINK_NAMESPACE(pthread_detach, "pthread");

if (GlobalState::isNative())
return orig::pthread_create(tid_p, attr, start_routine, arg);
if (GlobalState::isNative()) {
ThreadInfo* thread = new ThreadInfo();
ThreadManager::initThreadFromParent(thread, start_routine, arg, __builtin_return_address(0));
return orig::pthread_create(tid_p, attr, pthread_native_start, thread);
}

debuglogstdio(LCF_THREAD, "Thread is created with routine %p", (void*)start_routine);

Expand Down

0 comments on commit dcad788

Please sign in to comment.