Files
pytorch/c10/core/impl/PythonDispatcherTLS.cpp
cyy 4a019047ad Enable nested namespace check in clang-tidy (#118506)
It is time to enable nested namespaces in the code.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118506
Approved by: https://github.com/albanD
2024-01-31 00:32:35 +00:00

30 lines
741 B
C++

#include <c10/core/DispatchKey.h>
#include <c10/core/impl/LocalDispatchKeySet.h>
#include <c10/core/impl/PythonDispatcherTLS.h>
namespace c10::impl {
thread_local PyInterpreter* pythonDispatcherState;
void PythonDispatcherTLS::set_state(PyInterpreter* state) {
if (state) {
c10::impl::tls_set_dispatch_key_included(
DispatchKey::PythonDispatcher, true);
} else {
PythonDispatcherTLS::reset_state();
}
pythonDispatcherState = state;
}
PyInterpreter* PythonDispatcherTLS::get_state() {
return pythonDispatcherState;
}
void PythonDispatcherTLS::reset_state() {
pythonDispatcherState = nullptr;
c10::impl::tls_set_dispatch_key_included(
DispatchKey::PythonDispatcher, false);
}
} // namespace c10::impl