Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ASR by default #649

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions source/async_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@
#include <cassert>
#include <mutex>

#if !defined(UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD)
#if !defined(UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD) || \
!defined(UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR)
// defaults to using pthread if linux, otherwise no async stack root
# if defined(__linux__)
# define UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD 1
# define UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR 0
# else
// defaults to using vector to store AsyncStackRoots instead of a pthread key
# define UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD 0
# define UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR 0
# endif
#endif

#if UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD && UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR
# error \
"Only one of UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD and UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR can be set to true"
#endif

#if UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD

# include <pthread.h>
Expand All @@ -41,7 +49,7 @@ extern "C" {
// Initialise to some value that will be interpreted as an invalid key.
inline pthread_key_t folly_async_stack_root_tls_key = 0xFFFF'FFFFu;
}
#else
#elif UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR
# include <vector>
# if defined(_WIN32)
# include <windows.h>
Expand All @@ -52,7 +60,7 @@ inline pthread_key_t folly_async_stack_root_tls_key = 0xFFFF'FFFFu;

namespace unifex {

#if UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD == 0
#if UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR

struct AsyncStackRootHolderList {
std::vector<void*> asyncStackRootHolders_;
Expand Down Expand Up @@ -107,7 +115,7 @@ static std::uint64_t get_os_thread_id() {
# error "Unsupported platform in get_os_thread_id"
# endif
}
#endif // UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD == 0
#endif // UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR

namespace {

Expand Down Expand Up @@ -136,13 +144,13 @@ struct AsyncStackRootHolder {
[[maybe_unused]] const int result =
pthread_setspecific(folly_async_stack_root_tls_key, this);
UNIFEX_ASSERT(result == 0);
#else
#elif UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR
kUnifexAsyncStackRootHolderList->add(this);
threadId = unifex::get_os_thread_id();
#endif
}

#if !UNIFEX_ASYNC_STACK_ROOT_USE_PTHREAD
#if UNIFEX_ASYNC_STACK_ROOT_USE_VECTOR
~AsyncStackRootHolder() noexcept {
kUnifexAsyncStackRootHolderList->remove(this);
}
Expand Down
Loading