pthread.c File Reference

#include "thread.h"
#include <pthread.h>

Data Structures

struct  Thread

Defines

#define STACK_MAGIC   0xefefefef

Functions

void NsInitThreads (void)
void ** NsGetTls (void)
int NsGetStack (void **addrPtr, size_t *sizePtr)
char * NsThreadLibName (void)
void * NsLockAlloc (void)
void NsLockFree (void *lock)
void NsLockSet (void *lock)
int NsLockTry (void *lock)
void NsLockUnset (void *lock)
void NsCreateThread (void *arg, long stacksize, Ns_Thread *resultPtr)
void Ns_ThreadExit (void *arg)
void Ns_ThreadJoin (Ns_Thread *thread, void **argPtr)
void Ns_ThreadYield (void)
int Ns_ThreadId (void)
void Ns_ThreadSelf (Ns_Thread *threadPtr)
void Ns_CondInit (Ns_Cond *cond)
void Ns_CondDestroy (Ns_Cond *cond)
void Ns_CondSignal (Ns_Cond *cond)
void Ns_CondBroadcast (Ns_Cond *cond)
void Ns_CondWait (Ns_Cond *cond, Ns_Mutex *mutex)
int Ns_CondTimedWait (Ns_Cond *cond, Ns_Mutex *mutex, Ns_Time *timePtr)

Define Documentation

#define STACK_MAGIC   0xefefefef

The following constants define an integer magic number for marking pages at thread startup to be later checked at thread exit for stack usage and possible overflow.


Function Documentation

void Ns_CondBroadcast ( Ns_Cond *  cond  ) 

----------------------------------------------------------------------

Ns_CondBroadcast --

Pthread condition broadcast.

Results: None.

Side effects: See pthread_cond_broadcast.

----------------------------------------------------------------------

void Ns_CondDestroy ( Ns_Cond *  cond  ) 

----------------------------------------------------------------------

Ns_CondDestroy --

Pthread condition destroy. Note this routine is almost never used as condition variables normally exist in memory until the process exits.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void Ns_CondInit ( Ns_Cond *  cond  ) 

----------------------------------------------------------------------

Ns_CondInit --

Pthread condition variable initialization. Note this routine isn't used directly very often as static condition variables are now self initialized when first used.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void Ns_CondSignal ( Ns_Cond *  cond  ) 

----------------------------------------------------------------------

Ns_CondSignal --

Pthread condition signal.

Results: None.

Side effects: See pthread_cond_signal.

----------------------------------------------------------------------

int Ns_CondTimedWait ( Ns_Cond *  cond,
Ns_Mutex *  mutex,
Ns_Time *  timePtr 
)

----------------------------------------------------------------------

Ns_CondTimedWait --

Pthread absolute time wait.

Results: None.

Side effects: See pthread_cond_timewait.

----------------------------------------------------------------------

Convert the microsecond-based Ns_Time to a nanosecond-based struct timespec.

As documented on Linux, pthread_cond_timedwait may return EINTR if a signal arrives. We have noticed that EINTR can be returned on Solaris as well although this is not documented. We assume the wakeup is truely spurious and simply restart the wait knowing that the ts structure has not been modified.

void Ns_CondWait ( Ns_Cond *  cond,
Ns_Mutex *  mutex 
)

----------------------------------------------------------------------

Ns_CondWait --

Pthread indefinite condition wait.

Results: None.

Side effects: See pthread_cond_wait.

----------------------------------------------------------------------

void Ns_ThreadExit ( void *  arg  ) 

----------------------------------------------------------------------

Ns_ThreadExit --

Terminate a thread.

Results: None.

Side effects: Cleanup will be handled by the pthread call to CleanupTls.

----------------------------------------------------------------------

int Ns_ThreadId ( void   ) 

----------------------------------------------------------------------

Ns_ThreadId --

Return the numeric thread id.

Results: Integer thread id.

Side effects: None.

----------------------------------------------------------------------

void Ns_ThreadJoin ( Ns_Thread *  thread,
void **  argPtr 
)

----------------------------------------------------------------------

Ns_ThreadJoin --

Wait for exit of a non-detached thread.

Results: None.

Side effects: Requested thread is destroyed after join.

----------------------------------------------------------------------

void Ns_ThreadSelf ( Ns_Thread *  threadPtr  ) 

----------------------------------------------------------------------

Ns_ThreadSelf --

Return thread handle suitable for Ns_ThreadJoin.

Results: None.

Side effects: Value at threadPtr is updated with thread's handle.

----------------------------------------------------------------------

void Ns_ThreadYield ( void   ) 

----------------------------------------------------------------------

Ns_ThreadYield --

Yield the cpu to another thread.

Results: None.

Side effects: See sched_yield().

----------------------------------------------------------------------

void NsCreateThread ( void *  arg,
long  stacksize,
Ns_Thread *  resultPtr 
)

----------------------------------------------------------------------

NsCreateThread --

Pthread specific thread create function called by Ns_ThreadCreate.

Results: None.

Side effects: Depends on thread startup routine.

----------------------------------------------------------------------

Round the stacksize to a pagesize and include the guardzone.

System scope always preferred, ignore any unsupported error.

int NsGetStack ( void **  addrPtr,
size_t *  sizePtr 
)

----------------------------------------------------------------------

NsGetStack --

Return information about the stack.

Results: 0: Could not return stack. -1: Stack grows down. 1: Stack grows up.

Side effects: Given addrPtr and sizePtr are updated with stack base address and size.

----------------------------------------------------------------------

void** NsGetTls ( void   ) 

----------------------------------------------------------------------

NsGetTls --

Return the TLS slots.

Results: Pointer to slots array.

Side effects: None.

----------------------------------------------------------------------

void NsInitThreads ( void   ) 

----------------------------------------------------------------------

NsInitThreads --

Pthread library load time init routine.

Results: None.

Side effects: Creates pthread key and set various stack management values.

----------------------------------------------------------------------

void* NsLockAlloc ( void   ) 

----------------------------------------------------------------------

NsLockAlloc --

Allocate and initialize a mutex lock.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsLockFree ( void *  lock  ) 

----------------------------------------------------------------------

NsLockFree --

Free a mutex lock.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsLockSet ( void *  lock  ) 

----------------------------------------------------------------------

NsLockSet --

Set a mutex lock.

Results: None.

Side effects: May wait wakeup event if lock already held.

----------------------------------------------------------------------

int NsLockTry ( void *  lock  ) 

----------------------------------------------------------------------

NsLockTry --

Try to set a mutex lock once.

Results: 1 if lock set, 0 otherwise.

Side effects: None.

----------------------------------------------------------------------

void NsLockUnset ( void *  lock  ) 

----------------------------------------------------------------------

NsLockUnset --

Unset a mutex lock.

Results: None.

Side effects: May signal wakeup event for a waiting thread.

----------------------------------------------------------------------

char* NsThreadLibName ( void   ) 

----------------------------------------------------------------------

NsThreadLibName --

Return the string name of the thread library.

Results: Pointer to static string.

Side effects: None.

----------------------------------------------------------------------


Generated on Tue Sep 4 19:58:57 2007 by  doxygen 1.5.1