mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 18:42:28 +00:00
69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#ifndef STORM_HASH_TS_EXPORT_TABLE_SIMPLE_REUSE_HPP
|
|
#define STORM_HASH_TS_EXPORT_TABLE_SIMPLE_REUSE_HPP
|
|
|
|
#include "storm/hash/Hashkey.hpp"
|
|
#include "storm/hash/TSHashTableReuse.hpp"
|
|
|
|
template <class T, class THandle>
|
|
class TSExportTableSimpleReuse : public TSHashTableReuse<T, HASHKEY_NONE> {
|
|
public:
|
|
// Virtual member functions
|
|
virtual ~TSExportTableSimpleReuse() = default;
|
|
|
|
// Member functions
|
|
void Delete(T* ptr);
|
|
T* New(THandle* handlePtr);
|
|
T* Ptr(THandle handle);
|
|
|
|
private:
|
|
// Member variables
|
|
HASHKEY_NONE m_key;
|
|
uint32_t m_sequence = ~reinterpret_cast<uintptr_t>(this) & 0xFFFFFFF;
|
|
int32_t m_wrapped = 0;
|
|
|
|
// Member functions
|
|
THandle GenerateUniqueHandle();
|
|
};
|
|
|
|
template <class T, class THandle>
|
|
void TSExportTableSimpleReuse<T, THandle>::Delete(T* ptr) {
|
|
TSHashTable<T, HASHKEY_NONE>::Delete(ptr);
|
|
}
|
|
|
|
template <class T, class THandle>
|
|
THandle TSExportTableSimpleReuse<T, THandle>::GenerateUniqueHandle() {
|
|
while (true) {
|
|
while (true) {
|
|
this->m_sequence += 1;
|
|
|
|
if (this->m_sequence) {
|
|
break;
|
|
}
|
|
|
|
this->m_wrapped = 1;
|
|
}
|
|
|
|
if (!this->m_wrapped || !this->Ptr(reinterpret_cast<THandle>(this->m_sequence))) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return reinterpret_cast<THandle>(this->m_sequence);
|
|
}
|
|
|
|
template <class T, class THandle>
|
|
T* TSExportTableSimpleReuse<T, THandle>::New(THandle* handlePtr) {
|
|
auto handle = this->GenerateUniqueHandle();
|
|
*handlePtr = handle;
|
|
|
|
auto hashval = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(handle));
|
|
return this->TSHashTable<T, HASHKEY_NONE>::New(hashval, this->m_key, 0, 0x0);
|
|
}
|
|
|
|
template <class T, class THandle>
|
|
T* TSExportTableSimpleReuse<T, THandle>::Ptr(THandle handle) {
|
|
auto hashval = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(handle));
|
|
return this->TSHashTable<T, HASHKEY_NONE>::Ptr(hashval, this->m_key);
|
|
}
|
|
|
|
#endif
|