Commit 9603376e authored by SND\kernelnet_cp's avatar SND\kernelnet_cp
Browse files

[pykd] fixed: TLS problem

git-svn-id: https://pykd.svn.codeplex.com/svn@69886 9b283d60-5439-405e-af05-b73fd8c4d996
parent 549cb797
......@@ -39,7 +39,7 @@ DbgExt *dbgExt = NULL;
dbgClient g_dbgClient;
//
__declspec( thread ) PyThreadStatePtr ptrPyThreadState = NULL;
PyThreadStateSaver g_pyThreadState;
//////////////////////////////////////////////////////////////////////////////
......
#pragma once
#include <windows.h>
///////////////////////////////////////////////////////////////////////////////
typedef PyThreadState *PyThreadStatePtr;
extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
class PyThreadStateSaver {
public:
PyThreadStateSaver() {
m_index = TlsAlloc();
}
~PyThreadStateSaver() {
TlsFree( m_index );
}
void saveState() {
TlsSetValue( m_index, PyEval_SaveThread() );
}
void restoreState() {
PyThreadState* state = (PyThreadState*)TlsGetValue( m_index );
if ( state )
PyEval_RestoreThread( state );
}
private:
DWORD m_index;
};
extern PyThreadStateSaver g_pyThreadState;
//typedef PyThreadState *PyThreadStatePtr;
//extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
// --> call back
// { PyThread_StateSave state( winext->getThreadState() );
......@@ -19,22 +51,13 @@ class PyThread_StateSave {
public:
PyThread_StateSave()
: m_bRestored(false)
{
if (ptrPyThreadState)
{
PyEval_RestoreThread( ptrPyThreadState );
m_bRestored = true;
}
g_pyThreadState.restoreState();
}
~PyThread_StateSave() {
if ( m_bRestored )
ptrPyThreadState = PyEval_SaveThread();
g_pyThreadState.saveState();
}
private:
bool m_bRestored;
};
// { PyThread_StateRestore state;
......@@ -46,11 +69,11 @@ class PyThread_StateRestore
public:
PyThread_StateRestore() {
ptrPyThreadState = PyEval_SaveThread();
g_pyThreadState.saveState();
}
~PyThread_StateRestore() {
PyEval_RestoreThread( ptrPyThreadState );
g_pyThreadState.restoreState();
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment