Skip to content

Commit

Permalink
TLS: remove dummy and locker; just alignas()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornaukhov03 committed Nov 20, 2023
1 parent dcdd225 commit dae0a65
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions compiler/threading/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ inline uint32_t get_default_threads_count() noexcept {
template<class T>
struct TLS {
private:
static constexpr std::size_t PAGE_SIZE = 4096;
static constexpr std::size_t CACHE_LINE_SIZE = 64;
struct TLSRaw {
struct alignas(CACHE_LINE_SIZE) TLSRaw {
T data{};
volatile int locker = 0;
char dummy[CACHE_LINE_SIZE];
// char dummy[CACHE_LINE_SIZE];
};

TLSRaw arr[MAX_THREADS_COUNT + 1];
Expand Down Expand Up @@ -67,19 +65,6 @@ struct TLS {
int size() {
return MAX_THREADS_COUNT + 1;
}

T *lock_get() {
TLSRaw *raw = get_raw();
bool ok = try_lock(&raw->locker);
assert(ok);
return &raw->data;
}

void unlock_get(T *ptr) {
TLSRaw *raw = get_raw();
assert(&raw->data == ptr);
unlock(&raw->locker);
}
};

#pragma GCC diagnostic pop

0 comments on commit dae0a65

Please sign in to comment.