Back to index

python3.2  3.2.2
Classes | Defines | Functions
thread_nt.h File Reference
#include <windows.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  callobj

Defines

#define PNRMUTEX   HANDLE
#define THREAD_MIN_STACKSIZE   0x8000 /* 32kB */
#define THREAD_MAX_STACKSIZE   0x10000000 /* 256MB */
#define THREAD_SET_STACKSIZE(x)   _pythread_nt_set_stacksize(x)
#define Py_HAVE_NATIVE_TLS

Functions

PNRMUTEX AllocNonRecursiveMutex ()
VOID FreeNonRecursiveMutex (PNRMUTEX mutex)
DWORD EnterNonRecursiveMutex (PNRMUTEX mutex, DWORD milliseconds)
BOOL LeaveNonRecursiveMutex (PNRMUTEX mutex)
long PyThread_get_thread_ident (void)
static void PyThread__init_thread (void)
static unsigned __stdcall bootstrap (void *call)
long PyThread_start_new_thread (void(*func)(void *), void *arg)
void PyThread_exit_thread (void)
PyThread_type_lock PyThread_allocate_lock (void)
void PyThread_free_lock (PyThread_type_lock aLock)
PyLockStatus PyThread_acquire_lock_timed (PyThread_type_lock aLock, PY_TIMEOUT_T microseconds, int intr_flag)
int PyThread_acquire_lock (PyThread_type_lock aLock, int waitflag)
void PyThread_release_lock (PyThread_type_lock aLock)
static int _pythread_nt_set_stacksize (size_t size)
int PyThread_create_key (void)
void PyThread_delete_key (int key)
int PyThread_set_key_value (int key, void *value)
voidPyThread_get_key_value (int key)
void PyThread_delete_key_value (int key)
void PyThread_ReInitTLS (void)

Define Documentation

#define PNRMUTEX   HANDLE

Definition at line 12 of file thread_nt.h.

Definition at line 270 of file thread_nt.h.

#define THREAD_MAX_STACKSIZE   0x10000000 /* 256MB */

Definition at line 243 of file thread_nt.h.

#define THREAD_MIN_STACKSIZE   0x8000 /* 32kB */

Definition at line 242 of file thread_nt.h.

Definition at line 266 of file thread_nt.h.


Function Documentation

static int _pythread_nt_set_stacksize ( size_t  size) [static]

Definition at line 249 of file thread_nt.h.

{
    /* set to default */
    if (size == 0) {
        _pythread_stacksize = 0;
        return 0;
    }

    /* valid range? */
    if (size >= THREAD_MIN_STACKSIZE && size < THREAD_MAX_STACKSIZE) {
        _pythread_stacksize = size;
        return 0;
    }

    return -1;
}

Definition at line 15 of file thread_nt.h.

{
    return CreateSemaphore(NULL, 1, 1, NULL);
}

Here is the caller graph for this function:

static unsigned __stdcall bootstrap ( void call) [static]

Definition at line 65 of file thread_nt.h.

{
    callobj *obj = (callobj*)call;
    void (*func)(void*) = obj->func;
    void *arg = obj->arg;
    HeapFree(GetProcessHeap(), 0, obj);
    func(arg);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

DWORD EnterNonRecursiveMutex ( PNRMUTEX  mutex,
DWORD  milliseconds 
)

Definition at line 28 of file thread_nt.h.

{
    return WaitForSingleObject(mutex, milliseconds);
}

Here is the caller graph for this function:

Definition at line 21 of file thread_nt.h.

{
    /* No in-use check */
    CloseHandle(mutex);
}

Here is the caller graph for this function:

Definition at line 34 of file thread_nt.h.

{
    return ReleaseSemaphore(mutex, 1, NULL);
}

Here is the caller graph for this function:

static void PyThread__init_thread ( void  ) [static]

Definition at line 45 of file thread_nt.h.

{
}
int PyThread_acquire_lock ( PyThread_type_lock  aLock,
int  waitflag 
)

Definition at line 227 of file thread_nt.h.

{
    return PyThread_acquire_lock_timed(aLock, waitflag ? -1 : 0, 0);
}

Here is the call graph for this function:

PyLockStatus PyThread_acquire_lock_timed ( PyThread_type_lock  aLock,
PY_TIMEOUT_T  microseconds,
int  intr_flag 
)

Definition at line 191 of file thread_nt.h.

{
    /* Fow now, intr_flag does nothing on Windows, and lock acquires are
     * uninterruptible.  */
    PyLockStatus success;
    PY_TIMEOUT_T milliseconds;

    if (microseconds >= 0) {
        milliseconds = microseconds / 1000;
        if (microseconds % 1000 > 0)
            ++milliseconds;
        if ((DWORD) milliseconds != milliseconds)
            Py_FatalError("Timeout too large for a DWORD, "
                           "please check PY_TIMEOUT_MAX");
    }
    else
        milliseconds = INFINITE;

    dprintf(("%ld: PyThread_acquire_lock_timed(%p, %lld) called\n",
             PyThread_get_thread_ident(), aLock, microseconds));

    if (aLock && EnterNonRecursiveMutex((PNRMUTEX)aLock,
                                        (DWORD)milliseconds) == WAIT_OBJECT_0) {
        success = PY_LOCK_ACQUIRED;
    }
    else {
        success = PY_LOCK_FAILURE;
    }

    dprintf(("%ld: PyThread_acquire_lock(%p, %lld) -> %d\n",
             PyThread_get_thread_ident(), aLock, microseconds, success));

    return success;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 161 of file thread_nt.h.

{
    PNRMUTEX aLock;

    dprintf(("PyThread_allocate_lock called\n"));
    if (!initialized)
        PyThread_init_thread();

    aLock = AllocNonRecursiveMutex() ;

    dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock));

    return (PyThread_type_lock) aLock;
}

Here is the call graph for this function:

Definition at line 274 of file thread_nt.h.

{
    DWORD result= TlsAlloc();
    if (result == TLS_OUT_OF_INDEXES)
        return -1;
    return (int)result;
}

Definition at line 283 of file thread_nt.h.

{
    TlsFree(key);
}

Definition at line 324 of file thread_nt.h.

{
    /* NULL is used as "key missing", and it is also the default
     * given by TlsGetValue() if nothing has been set yet.
     */
    TlsSetValue(key, NULL);
}

Definition at line 143 of file thread_nt.h.

{
    dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident()));
    if (!initialized)
        exit(0);
#if defined(MS_WINCE)
    ExitThread(0);
#else
    _endthreadex(0);
#endif
}

Here is the call graph for this function:

Definition at line 177 of file thread_nt.h.

{
    dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock));

    FreeNonRecursiveMutex(aLock) ;
}

Here is the call graph for this function:

Definition at line 309 of file thread_nt.h.

{
    /* because TLS is used in the Py_END_ALLOW_THREAD macro,
     * it is necessary to preserve the windows error state, because
     * it is assumed to be preserved across the call to the macro.
     * Ideally, the macro should be fixed, but it is simpler to
     * do it here.
     */
    DWORD error = GetLastError();
    void *result = TlsGetValue(key);
    SetLastError(error);
    return result;
}

Definition at line 336 of file thread_nt.h.

{}

Definition at line 233 of file thread_nt.h.

{
    dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));

    if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock)))
        dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError()));
}

Here is the call graph for this function:

int PyThread_set_key_value ( int  key,
void value 
)

Definition at line 292 of file thread_nt.h.

{
    BOOL ok;
    void *oldvalue;

    assert(value != NULL);
    oldvalue = TlsGetValue(key);
    if (oldvalue != NULL)
        /* ignore value if already set */
        return 0;
    ok = TlsSetValue(key, value);
    if (!ok)
        return -1;
    return 0;
}
long PyThread_start_new_thread ( void(*)(void *)  func,
void arg 
)

Definition at line 76 of file thread_nt.h.

{
    HANDLE hThread;
    unsigned threadID;
    callobj *obj;

    dprintf(("%ld: PyThread_start_new_thread called\n",
             PyThread_get_thread_ident()));
    if (!initialized)
        PyThread_init_thread();

    obj = (callobj*)HeapAlloc(GetProcessHeap(), 0, sizeof(*obj));
    if (!obj)
        return -1;
    obj->func = func;
    obj->arg = arg;
#if defined(MS_WINCE)
    hThread = CreateThread(NULL,
                           Py_SAFE_DOWNCAST(_pythread_stacksize, Py_ssize_t, SIZE_T),
                           bootstrap, obj, 0, &threadID);
#else
    hThread = (HANDLE)_beginthreadex(0,
                      Py_SAFE_DOWNCAST(_pythread_stacksize,
                                       Py_ssize_t, unsigned int),
                      bootstrap, obj,
                      0, &threadID);
#endif
    if (hThread == 0) {
#if defined(MS_WINCE)
        /* Save error in variable, to prevent PyThread_get_thread_ident
           from clobbering it. */
        unsigned e = GetLastError();
        dprintf(("%ld: PyThread_start_new_thread failed, win32 error code %u\n",
                 PyThread_get_thread_ident(), e));
#else
        /* I've seen errno == EAGAIN here, which means "there are
         * too many threads".
         */
        int e = errno;
        dprintf(("%ld: PyThread_start_new_thread failed, errno %d\n",
                 PyThread_get_thread_ident(), e));
#endif
        threadID = (unsigned)-1;
        HeapFree(GetProcessHeap(), 0, obj);
    }
    else {
        dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n",
                 PyThread_get_thread_ident(), (void*)hThread));
        CloseHandle(hThread);
    }
    return (long) threadID;
}

Here is the call graph for this function: