Skip to content

Commit

Permalink
Make thread_local variables constinit where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Oipo committed Feb 9, 2024
1 parent 1a09849 commit 2650be7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/ichor/DependencyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ namespace Ichor {
namespace Detail {
// Used internally to insert events where passing around the DM isn't feasible
// Only use if you know for sure you're on the correct thread.
thread_local extern DependencyManager *_local_dm;
constinit thread_local extern DependencyManager *_local_dm;
}

/// Returns thread-local manager. Can only be used after the manager's start() function has been called.
Expand Down
4 changes: 2 additions & 2 deletions include/ichor/coroutines/AsyncGeneratorPromiseBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Ichor {
}

namespace Ichor::Detail {
thread_local extern DependencyManager *_local_dm;
constinit thread_local extern DependencyManager *_local_dm;

template<typename T>
class AsyncGeneratorIterator;
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace Ichor::Detail {
tl::optional<bool> _hasSuspended{};

private:
static thread_local uint64_t _idCounter;
static constinit thread_local uint64_t _idCounter;
};


Expand Down
2 changes: 1 addition & 1 deletion src/ichor/DependencyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::atomic<uint64_t> Ichor::_rfpCounter = 0;
#endif
thread_local Ichor::unordered_set<uint64_t> Ichor::Detail::emptyDependencies{};

thread_local Ichor::DependencyManager *Ichor::Detail::_local_dm = nullptr;
constinit thread_local Ichor::DependencyManager *Ichor::Detail::_local_dm = nullptr;

#ifdef ICHOR_USE_BACKWARD
#include <backward/backward.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ichor/coroutines/AsyncGeneratorPromise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#include <ichor/coroutines/AsyncGeneratorPromiseBase.h>

// 0 has a specific meaning.
uint64_t thread_local Ichor::Detail::AsyncGeneratorPromiseBase::_idCounter = 1;
uint64_t constinit thread_local Ichor::Detail::AsyncGeneratorPromiseBase::_idCounter = 1;

0 comments on commit 2650be7

Please sign in to comment.