2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
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:
|
2022-01-19 17:08:13 +00:00
|
|
|
using TlsCb = AuFunction<void(void *)>;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|