The use of PyW32_BEGIN_ALLOW_THREADS and PyW32_END_ALLOW_THREADS
sam
samschul at pacbell.net
Fri May 19 12:57:22 EDT 2006
The follllowing code lifted from Mark Hammond Pywin32 code shows and
example of calling the Windows Kernel32 GetTickCount(),using
PyW32_BEGIN_ALLOW_THREADS and PYW32_END_ALLOW_THREADS. My Code does not
use this,but uses SetThreadAffinityMask(GetCurrentThread(),1). My
questions are:
1) What is the difference?
2) What happens after I leave my function, to the previous threads that
I may have had running?
3) Should I be using the BEGIN/END ALLOW_THREADS?
/ @pymethod string|win32api|GetTickCount|Returns the number of
milliseconds since windows started.
static PyObject *
PyGetTickCount(PyObject * self, PyObject * args)
{
if (!PyArg_ParseTuple (args, ":PyGetTickCount"))
return NULL;
PyW32_BEGIN_ALLOW_THREADS
DWORD count = GetTickCount();
PyW32_END_ALLOW_THREADS
return Py_BuildValue("l",(long)count);
}
Now my code uses the Microsoft
"SetThreadAffinityMask(GetCurrentThread(),1)"
//
// PROGRAMMER: Samuel W. Schulenburg
// DATE: May 18,2006
//
// FUNCTION: double dMyClock()
//
// DESCRIPTION: This function will return the seconds since the system
was started
// as a double. If a call to QueryPerformanceFrequency()
returns a true
// then QueryPerformanceCounter() will be used else the
standard 'C'
// dMyClock() function will be used.
//
// PARAMETERS: None
//
// RETURN: double The seconds passed sense the system was started
//
double dMyClock()
{
double dLow;
double dHigh;
if(iPerformanceClocks == 1) // if the hardware supports the high
performance clock
{
SetThreadAffinityMask(GetCurrentThread(),1);
QueryPerformanceCounter(&liPerformanceCount);
dLow = (double)liPerformanceCount.LowPart;
dHigh = (double)(liPerformanceCount.HighPart)*(4294967296.0);
return((dLow+dHigh)/dTicksPerSecond);
}
else // use the standard C clock function
return((double) (clock()/dTicksPerSecond));
}
More information about the Python-list
mailing list