aboutsummaryrefslogtreecommitdiffstats
path: root/common/uintmap.h
blob: 0646d2b591577d29f739750c485a5079179fe990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef AL_UINTMAP_H
#define AL_UINTMAP_H

#include <unordered_map>
#include <mutex>

#include "AL/al.h"

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;
    }
};

#endif /* AL_UINTMAP_H */