The use of PyW32_BEGIN_ALLOW_THREADS and PyW32_END_ALLOW_THREADS

S

sam

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));
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,540
Members
48,274
Latest member
HowardKipp

Latest Threads

Top