2013-10-28 12:48:13 -07:00
|
|
|
#ifndef AL_UINTMAP_H
|
|
|
|
#define AL_UINTMAP_H
|
|
|
|
|
2018-11-17 05:31:29 -08:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <mutex>
|
2017-08-30 12:01:49 -07:00
|
|
|
|
2013-10-28 12:48:13 -07:00
|
|
|
#include "AL/al.h"
|
2018-11-17 05:31:29 -08:00
|
|
|
|
|
|
|
template<typename T0, typename T1>
|
|
|
|
class ThrSafeMap {
|
|
|
|
std::unordered_map<T0, T1> mValues;
|
|
|
|
std::mutex mLock;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void InsertEntry(T0 key, T1 value) noexcept
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> _{mLock};
|
|
|
|
mValues[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
T1 RemoveKey(T0 key) noexcept
|
|
|
|
{
|
|
|
|
T1 retval{};
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> _{mLock};
|
|
|
|
auto iter = mValues.find(key);
|
|
|
|
if(iter != mValues.end())
|
|
|
|
retval = iter->second;
|
|
|
|
mValues.erase(iter);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
};
|
2014-05-29 04:22:30 -07:00
|
|
|
|
2013-10-28 12:48:13 -07:00
|
|
|
#endif /* AL_UINTMAP_H */
|