AuroraRuntime/Include/Aurora/Threading/Threads/TLSView.hpp

42 lines
1.4 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: TLSView.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
namespace Aurora::Threading::Threads
{
static const AuUInt64 kTlsKeyFollowsConvention = AuUInt64(1) << AuUInt64(64 - 1);
static const AuUInt64 kTlsKeyStaticPointerHandle = AuUInt64(1) << AuUInt64(63 - 1);
static const AuUInt64 kTlsKeyResettablePointerHandle = AuUInt64(1) << AuUInt64(62 - 1);
static const AuUInt64 kTlsKeyMask = kTlsKeyResettablePointerHandle | kTlsKeyStaticPointerHandle | kTlsKeyFollowsConvention;
class TLSView
{
public:
using TlsCb = AuFunction<void(void *)>;
virtual void Remove(AuUInt64 key) = 0;
virtual void *GetTLS(AuUInt64 key, AuMach length, bool noAutoCreate = false) = 0;
virtual void *InitTLS(AuUInt64 key, AuMach length, const TlsCb &init, const TlsCb &deinit) = 0;
void *GetOrSetup(AuUInt64 key, AuMach length, const TlsCb &init, const TlsCb &deinit)
{
void *tls;
#if 0
if (!(tls = GetTLS(key, length, true)))
#endif
{
tls = InitTLS(key, length, init, deinit);
if (!tls)
{
return nullptr;
}
}
return tls;
}
};
}