thread_id-inl.h 846 B

123456789101112131415161718192021222324252627282930
  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. extern YT_THREAD_LOCAL(TSequentialThreadId) CachedSequentialThreadId;
  12. extern std::atomic<TSequentialThreadId> SequentialThreadIdGenerator;
  13. inline TSequentialThreadId GetSequentialThreadId()
  14. {
  15. if (Y_UNLIKELY(CachedSequentialThreadId == InvalidSequentialThreadId)) {
  16. CachedSequentialThreadId = ++SequentialThreadIdGenerator;
  17. }
  18. return CachedSequentialThreadId;
  19. }
  20. ////////////////////////////////////////////////////////////////////////////////
  21. } // namespace NYT