Back to index

python3.2  3.2.2
Classes | Defines | Functions
thread_lwp.h File Reference
#include <stdlib.h>
#include <lwp/lwp.h>
#include <lwp/stackdep.h>

Go to the source code of this file.

Classes

struct  lock

Defines

#define STACKSIZE   1000 /* stacksize for a thread */
#define NSTACKS   2 /* # stacks to be put in cache initially */

Functions

static void PyThread__init_thread (void)
long PyThread_start_new_thread (void(*func)(void *), void *arg)
long PyThread_get_thread_ident (void)
void PyThread_exit_thread (void)
PyThread_type_lock PyThread_allocate_lock (void)
void PyThread_free_lock (PyThread_type_lock lock)
int PyThread_acquire_lock (PyThread_type_lock lock, int waitflag)
void PyThread_release_lock (PyThread_type_lock lock)

Class Documentation

struct lock

Definition at line 9 of file thread_lwp.h.

Class Members
cv_t lock_condvar
int lock_locked
mon_t lock_monitor

Define Documentation

#define NSTACKS   2 /* # stacks to be put in cache initially */

Definition at line 7 of file thread_lwp.h.

#define STACKSIZE   1000 /* stacksize for a thread */

Definition at line 6 of file thread_lwp.h.


Function Documentation

static void PyThread__init_thread ( void  ) [static]

Definition at line 19 of file thread_lwp.h.

{
    lwp_setstkcache(STACKSIZE, NSTACKS);
}
int PyThread_acquire_lock ( PyThread_type_lock  lock,
int  waitflag 
)

Definition at line 85 of file thread_lwp.h.

{
    int success;

    dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));
    success = 0;

    (void) mon_enter(((struct lock *) lock)->lock_monitor);
    if (waitflag)
        while (((struct lock *) lock)->lock_locked)
            cv_wait(((struct lock *) lock)->lock_condvar);
    if (!((struct lock *) lock)->lock_locked) {
        success = 1;
        ((struct lock *) lock)->lock_locked = 1;
    }
    cv_broadcast(((struct lock *) lock)->lock_condvar);
    mon_exit(((struct lock *) lock)->lock_monitor);
    dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));
    return success;
}

Here is the call graph for this function:

Definition at line 61 of file thread_lwp.h.

{
    struct lock *lock;
    extern char *malloc(size_t);

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

    lock = (struct lock *) malloc(sizeof(struct lock));
    lock->lock_locked = 0;
    (void) mon_create(&lock->lock_monitor);
    (void) cv_create(&lock->lock_condvar, lock->lock_monitor);
    dprintf(("PyThread_allocate_lock() -> %p\n", lock));
    return (PyThread_type_lock) lock;
}

Here is the call graph for this function:

Definition at line 50 of file thread_lwp.h.

{
    dprintf(("PyThread_exit_thread called\n"));
    if (!initialized)
        exit(0);
    lwp_destroy(SELF);
}

Definition at line 78 of file thread_lwp.h.

{
    dprintf(("PyThread_free_lock(%p) called\n", lock));
    mon_destroy(((struct lock *) lock)->lock_monitor);
    free((char *) lock);
}

Definition at line 40 of file thread_lwp.h.

{
    thread_t tid;
    if (!initialized)
        PyThread_init_thread();
    if (lwp_self(&tid) < 0)
        return -1;
    return tid.thread_id;
}

Here is the call graph for this function:

Definition at line 106 of file thread_lwp.h.

{
    dprintf(("PyThread_release_lock(%p) called\n", lock));
    (void) mon_enter(((struct lock *) lock)->lock_monitor);
    ((struct lock *) lock)->lock_locked = 0;
    cv_broadcast(((struct lock *) lock)->lock_condvar);
    mon_exit(((struct lock *) lock)->lock_monitor);
}

Here is the call graph for this function:

long PyThread_start_new_thread ( void(*)(void *)  func,
void arg 
)

Definition at line 29 of file thread_lwp.h.

{
    thread_t tid;
    int success;
    dprintf(("PyThread_start_new_thread called\n"));
    if (!initialized)
        PyThread_init_thread();
    success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg);
    return success < 0 ? -1 : 0;
}

Here is the call graph for this function: