mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.0 -> 0.1 ] integrated : pyaux.h
git-svn-id: https://pykd.svn.codeplex.com/svn@70638 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
379e97abf3
commit
ff2db46e11
90
pykd/pyaux.h
Normal file
90
pykd/pyaux.h
Normal file
@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PyThreadStateSaver {
|
||||
|
||||
public:
|
||||
|
||||
PyThreadStateSaver() {
|
||||
m_index = TlsAlloc();
|
||||
}
|
||||
|
||||
~PyThreadStateSaver() {
|
||||
TlsFree( m_index );
|
||||
}
|
||||
|
||||
void saveState() {
|
||||
if ( !isWindbgExt() )
|
||||
TlsSetValue( m_index, PyEval_SaveThread() );
|
||||
else
|
||||
WindbgGlobalSession::SavePyState();
|
||||
}
|
||||
|
||||
void restoreState() {
|
||||
if ( !isWindbgExt() )
|
||||
{
|
||||
PyThreadState* state = (PyThreadState*)TlsGetValue( m_index );
|
||||
if ( state )
|
||||
PyEval_RestoreThread( state );
|
||||
}
|
||||
else
|
||||
{
|
||||
WindbgGlobalSession::RestorePyState();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DWORD m_index;
|
||||
};
|
||||
|
||||
extern PyThreadStateSaver g_pyThreadState;
|
||||
|
||||
|
||||
//typedef PyThreadState *PyThreadStatePtr;
|
||||
//extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
|
||||
|
||||
// --> call back
|
||||
// { PyThread_StateSave state( winext->getThreadState() );
|
||||
// do_callback();
|
||||
// }
|
||||
//
|
||||
// Ĺńëč ęîëáĺę áűë âűçâŕí č ďđč ýňîě ó ňĺęůĺăî ďîňîęŕ ńîőđŕíĺí ęîíňĺęńň ( áűë âűçîâ setExecutionStatus )
|
||||
// ňî ďĺđĺä âűďîëíĺíčĺě ďčňîíîâńęîăî ęîäŕ íóćíî âîńńňŕíîâčňü ęîíňĺęńň, ŕ ďîńëĺ âîçâđŕňŕ óďđŕâëĺíč˙,
|
||||
// ńíîâŕ ńîőđŕíčňü ĺăî
|
||||
|
||||
class PyThread_StateSave {
|
||||
|
||||
public:
|
||||
|
||||
PyThread_StateSave()
|
||||
{
|
||||
g_pyThreadState.restoreState();
|
||||
}
|
||||
|
||||
~PyThread_StateSave() {
|
||||
g_pyThreadState.saveState();
|
||||
}
|
||||
};
|
||||
|
||||
// { PyThread_StateRestore state;
|
||||
// long_or_block_opreration();
|
||||
// }
|
||||
|
||||
class PyThread_StateRestore
|
||||
{
|
||||
public:
|
||||
|
||||
PyThread_StateRestore() {
|
||||
g_pyThreadState.saveState();
|
||||
}
|
||||
|
||||
~PyThread_StateRestore() {
|
||||
g_pyThreadState.restoreState();
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue
Block a user