next up previous contents index
Next: B.3 PVM C Header Up: B Header Dateien und Previous: B.1 Thread Definition Modul

B.2 Pthread Definition Modul

FOREIGN MODULE pthread;

(* Pthread Foreign Module. *)

FROM SYSTEM IMPORT ADDRESS;

FROM KSR1 IMPORT int, card, align128int, align128long; 

FROM thread IMPORT thread_t, processor_name_t;

(* For the definitions below see /usr/include/pthread.h *)

TYPE any_t               = LONGCARD; 
TYPE slot_t              = int;
TYPE timespec            = RECORD (* from <timers.h> *) 
              tv_sec     : CARDINAL;
              tv_nsec    : INTEGER;
                           END;

TYPE pthread_mutexattr   = RECORD 
             flags       : LONGINT;
             logfile     : POINTER TO ADDRESS;
             loginfo     : int;
             spinlimit   : int;
                           END;
TYPE pthread_mutexattr_t = POINTER TO pthread_mutex;


TYPE pthread_mutex      = RECORD 
             lock       : align128int;
             loginfo    : int;
             flags      : LONGINT;
             name       : POINTER TO CHAR;
             spinlimit  : int;
             yieldcount : int;
             logfile    : POINTER TO ADDRESS;
             locker     : POINTER TO pthread;
             unlocker   : POINTER TO pthread;
             timestamp  : timespec;
             attr       : pthread_mutexattr_t;
             dummy1     : ADDRESS; 
             dummy2     : ADDRESS; 
             dummy3     : ADDRESS; 
             dummy4     : ADDRESS; 
                          END;
TYPE pthread_mutex_t    = (*POINTER TO*) (*???*) pthread_mutex;


TYPE pthread_condattr   = RECORD 
             flags      : LONGINT;
             logfile    : POINTER TO ADDRESS;
             loginfo    : int;
                          END;
TYPE pthread_condattr_t = POINTER TO pthread_condattr;


TYPE pthread_func      = PROCEDURE(VAR ADDRESS): ADDRESS;
TYPE pthread_func_t    = POINTER TO pthread_func;


TYPE pthread_attr      = RECORD 
             flags     : LONGINT;
             stacksize : LONGINT;
             logfile   : POINTER TO ADDRESS;
             loginfo   : int;
                         END;
TYPE pthread_attr_t    = POINTER TO pthread_attr;


TYPE p_queue           = RECORD
             next      : POINTER TO p_queue;
             prev      : POINTER TO p_queue;
                         END;
TYPE pthread_queue     = POINTER TO p_queue;


TYPE pthread_condition = RECORD (*must fit in subpage*)
             lock      : align128int;
             waiters   : pthread_queue;
             flags     : LONGINT;
             name      : POINTER TO CHAR;
             loginfo   : int;
             logfile   : POINTER TO ADDRESS;
             timestamp : timespec; 
             attr      : pthread_condattr_t; 
                         END;
TYPE pthread_cond_t    = (*POINTER TO*) (*???*) pthread_condition;


TYPE pthread           = RECORD 
        link           : pthread_queue;
        all_thread_link: POINTER TO pthread;
        flags          : card; 
        state          : card; 
        vp             : POINTER TO ADDRESS;
        name           : POINTER TO CHAR;
        lock           : ADDRESS; 
        join_count     : card;
        loginfo        : int;
        logfile        : POINTER TO ADDRESS;
        done           : pthread_cond_t; 
        func           : pthread_func_t;
        arg            : any_t;
        returned       : any_t;
        attr           : pthread_attr_t; 
        specific_data  : POINTER TO ADDRESS; (*specific_data*)
        cancel_state   : ADDRESS; (*pthread_cancel_t*) 
        cleanup_queue  : POINTER TO ADDRESS; (*pthread_cleanup_handler_t*) 
        reserved       : ARRAY [0..7] OF LONGINT; (*for safety*)  
                         END;
TYPE pthread_t         = POINTER TO pthread;  


CONST rcsid = "$Id: pthread.md,v 1.1.1.1 1993/06/11 12:54:54 kredel Exp $";
CONST copyright = "Copyright (c) 1993 - 1994 Universitaet Mannheim";


CONST TH_BOUND_PROCESSOR = 2;
(*      TH_BOUND_RING0 = 1;
        TH_BOUND_NOWHERE = 0;
*)

VAR (*pthread_*) condattr_default: pthread_condattr_t;

VAR (*pthread_*) mutexattr_default: pthread_mutexattr_t;

VAR (*pthread_*) attr_default: pthread_attr_t;


(* POSIX thread functions for mutexes. *)

PROCEDURE pthread_mutex_init(VAR mutex: pthread_mutex_t; 
                          attr: pthread_mutexattr_t): int;
(*Initialize a mutex. *)

PROCEDURE pthread_mutex_destroy(VAR mutex: pthread_mutex_t): int;
(*Destroy a mutex. *)

PROCEDURE pthread_mutex_lock(VAR mutex: pthread_mutex_t): int;
(*Lock a mutex. *)

PROCEDURE pthread_mutex_trylock(VAR mutex: pthread_mutex_t): int;
(*Try to lock a mutex. *)
 
PROCEDURE pthread_mutex_unlock(VAR mutex: pthread_mutex_t): int;
(*Unlock a mutex. *)


(* POSIX thread functions for condition variables. *)

PROCEDURE pthread_cond_init(VAR cond: pthread_cond_t; 
                            attr: pthread_condattr_t): int;
(*Initialize a condition variable. *)

PROCEDURE pthread_cond_destroy(VAR cond: pthread_cond_t): int;
(*Destroy a condition variable. *)

PROCEDURE pthread_cond_wait(VAR cond: pthread_cond_t; 
                            VAR mutex: pthread_mutex_t): int;
(*Wait on a condition wrt mutex. *)

PROCEDURE pthread_cond_timedwait(VAR cond: pthread_cond_t; 
                                 VAR mutex: pthread_mutex_t;
                                 VAR timeout: timespec): int;
(*Wait with timeout on a condition wrt mutex. *)

PROCEDURE pthread_cond_signal(VAR cond: pthread_cond_t): int;
(*Signal a condition. *)

PROCEDURE pthread_cond_broadcast(VAR cond: pthread_cond_t): int;
(*Broadcast a condition. *)


(* POSIX thread functions for threads. *)

PROCEDURE pthread_self(): pthread_t; 
(*Get thread id of myself. *)

PROCEDURE pthread_create( VAR    thread: pthread_t; 
                                   attr: pthread_attr_t;
                          start_routine: pthread_func; 
                          VAR       arg: ADDRESS         ): int;
(*Create and start a thread. *)

PROCEDURE pthread_detach( VAR thread: pthread_t): int;
(*Detach a thread. *)

PROCEDURE pthread_join(thread: pthread_t; VAR status: ADDRESS): int;
(*Join a thread. *)

PROCEDURE pthread_exit(VAR status: ADDRESS);
(*Exit a thread. *)

PROCEDURE pthread_yield(status: ADDRESS);
(*Yield. *)

PROCEDURE pthread_cancel(thread: pthread_t); 
(*Cancel a thread. *)


(* POSIX thread scheduling for threads. *)

PROCEDURE pthread_getproc(thread: pthread_t; VAR processor: processor_name_t)
          : int; 
(*Get the processor a thread runs on. *)

PROCEDURE pthread_move(thread: pthread_t; destproc: processor_name_t; 
          bind: int): int; 
(*Move a thread to a processor. *)

PROCEDURE pthread_procsetinfo(pcell: ARRAY OF processor_name_t; 
          len: int): int; 
(*Information about processors in procset. *)

PROCEDURE pthread_getthread(thread: pthread_t; VAR machthread: thread_t): int; 
(*Get the MACH thread id of a pthread. *)

END pthread.



parallel@rz.uni-mannheim.de
Mon Okt 28 14:38:25 PST 1996