Skip to content

Commit

Permalink
Disable ASR by default (#649)
Browse files Browse the repository at this point in the history
* Make windows use pthread

* Separate vector stack root tracking into a new macro

* Add error if both macros are set to true

* Add clang-format
  • Loading branch information
jesswong authored Jan 9, 2025
1 parent 7e17b0e commit 48072b0
Showing 1 changed file with 15 additions and 7 deletions.
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

0 comments on commit 48072b0

Please sign in to comment.