thread_id-inl.h 913 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef THREAD_ID_INL_H_
  2. #error "Direct inclusion of this file is not allowed, include thread_id.h"
  3. // For the sake of sane code completion.
  4. #include "thread_id.h"
  5. #endif
  6. #include <library/cpp/yt/misc/tls.h>
  7. #include <atomic>
  8. #include <util/system/compiler.h>
  9. namespace NYT {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. YT_DECLARE_THREAD_LOCAL(TSequentialThreadId, CachedSequentialThreadId);
  12. extern std::atomic<TSequentialThreadId> SequentialThreadIdGenerator;
  13. inline TSequentialThreadId GetSequentialThreadId()
  14. {
  15. auto& cachedSequentialThreadId = CachedSequentialThreadId();
  16. if (Y_UNLIKELY(cachedSequentialThreadId == InvalidSequentialThreadId)) {
  17. cachedSequentialThreadId = ++SequentialThreadIdGenerator;
  18. }
  19. return cachedSequentialThreadId;
  20. }
  21. ////////////////////////////////////////////////////////////////////////////////
  22. } // namespace NYT