aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/udf/udf_helpers.cpp
blob: 91e2c1d779f07b2dd101ddd195ccb7e2d95969ba (plain) (blame)
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
#include "udf_helpers.h"

#include <library/cpp/resource/resource.h>

#include <util/generic/singleton.h>
#include <mutex>
#include <unordered_map>

namespace NYql {
namespace NUdf {

namespace {

struct TLoadedResources {
    TString Get(TStringBuf resourceId) {
        const std::unique_lock lock(Sync);
        const auto ins = Resources.emplace(resourceId, "");
        if (ins.second)
            ins.first->second = NResource::Find(resourceId);
        return ins.first->second;
    }

    std::mutex Sync;
    std::unordered_map<TString, TString> Resources;
};

}

TString LoadResourceOnce(TStringBuf resourceId) {
    return Singleton<TLoadedResources>()->Get(resourceId);
}

}
}