udf_helpers.cpp 689 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "udf_helpers.h"
  2. #include <library/cpp/resource/resource.h>
  3. #include <util/generic/singleton.h>
  4. #include <mutex>
  5. #include <unordered_map>
  6. namespace NYql {
  7. namespace NUdf {
  8. namespace {
  9. struct TLoadedResources {
  10. TString Get(TStringBuf resourceId) {
  11. const std::unique_lock lock(Sync);
  12. const auto ins = Resources.emplace(resourceId, "");
  13. if (ins.second)
  14. ins.first->second = NResource::Find(resourceId);
  15. return ins.first->second;
  16. }
  17. std::mutex Sync;
  18. std::unordered_map<TString, TString> Resources;
  19. };
  20. }
  21. TString LoadResourceOnce(TStringBuf resourceId) {
  22. return Singleton<TLoadedResources>()->Get(resourceId);
  23. }
  24. }
  25. }