ThreadLocalPythonObjects.h 632 B

1234567891011121314151617181920212223
  1. #pragma once
  2. #include <c10/core/SafePyObject.h>
  3. #include <c10/macros/Macros.h>
  4. #include <unordered_map>
  5. namespace at {
  6. namespace impl {
  7. struct TORCH_API ThreadLocalPythonObjects {
  8. static void set(const std::string& key, std::shared_ptr<SafePyObject> value);
  9. static const std::shared_ptr<SafePyObject>& get(const std::string& key);
  10. static bool contains(const std::string& key);
  11. static const ThreadLocalPythonObjects& get_state();
  12. static void set_state(ThreadLocalPythonObjects state);
  13. private:
  14. std::unordered_map<std::string, std::shared_ptr<c10::SafePyObject>> obj_dict_;
  15. };
  16. } // namespace impl
  17. } // namespace at