File: error_state.cpp

package info (click to toggle)
level-zero 1.26.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,468 kB
  • sloc: cpp: 130,327; ansic: 16,197; python: 9,824; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 971 bytes parent folder | download
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
#include "error_state.h"

namespace error_state
{
    std::unordered_map<std::thread::id, std::string> errorDescs;
    std::mutex errorDescsMutex;

    void setErrorDesc(const std::string &desc)
    {
        auto threadId = std::this_thread::get_id();
        std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
        if (errorDescs.find(threadId) == errorDescs.end())
        {
            errorDescs[threadId] = desc;
        }
        else
        {
            errorDescs[threadId].clear();
            errorDescs[threadId] = desc;
        }
    }

    void getErrorDesc(const char **ppString)
    {
        auto threadId = std::this_thread::get_id();
        std::lock_guard<std::mutex> errorDescsLock(errorDescsMutex);
        if (errorDescs.find(threadId) == errorDescs.end())
        {
            errorDescs[threadId] = std::string();
        }
        if(ppString != nullptr) {
            *ppString = errorDescs[threadId].c_str();
        }
    }
}