mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
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
30 lines
741 B
C++
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
|