-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making this part of the PAL allows other platforms to replace with something more suitable.
- Loading branch information
Showing
7 changed files
with
64 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <atomic> | ||
|
||
namespace snmalloc | ||
{ | ||
class PalTidDefault | ||
{ | ||
public: | ||
using ThreadIdentity = size_t; | ||
|
||
/** | ||
* @brief Get the an id for the current thread. | ||
* | ||
* @return the thread id, this should never be the default of | ||
* ThreadIdentity. Callers can assume it is a non-default value. | ||
*/ | ||
static inline ThreadIdentity get_tid() noexcept | ||
{ | ||
static thread_local size_t tid{0}; | ||
static std::atomic<size_t> tid_source{0}; | ||
|
||
if (tid == 0) | ||
{ | ||
tid = ++tid_source; | ||
} | ||
return tid; | ||
} | ||
}; | ||
} // namespace snmalloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters