conv-core/threads.c File Reference

Go to the source code of this file.

Data Structures

struct  CthThreadBase
struct  CthThreadStruct
struct  CthProcInfo
struct  CthThreadStruct
struct  CthThreadStruct
struct  CthThreadStruct
struct  CthThreadStruct

Typedefs

typedef CthProcInfoCthProcInfo
typedef VOID(WINAPI *) PFIBER_START_ROUTINE (LPVOID lpFiberParameter)
typedef PFIBER_START_ROUTINE LPFIBER_START_ROUTINE
typedef CthThread threadTable [100]
typedef void(*) uJcontext_fn_t (void)

Functions

int CmiThreadIs (int flag)
CthThreadTokenCthGetToken (CthThread t)
int CthAliasCreate (int stackSize)
 Create an aliasable area of this size.
void CthAliasFree (int fd)
void CthAliasEnable (CthThreadBase *t)
 CthCpvStatic (CthThread, CthCurrent)
 CthCpvDeclare (char *, CthData)
 CthCpvStatic (int, CthDatasize)
void CthSetThreadID (CthThread th, int a, int b, int c)
CmiObjIdCthGetThreadID (CthThread th)
char * CthGetData (CthThread t)
static void CthFixData (CthThread t)
int CthRegister (int size)
 Allocate another size bytes of thread-local storage, and return the offset into the thread storage buffer.
void CthRegistered (int maxOffset)
 Make sure we have room to store up to at least maxOffset bytes of thread-local storage.
 CthCpvStatic (int, _defaultStackSize)
static void CthThreadBaseInit (CthThreadBase *th)
static void * CthAllocateStack (CthThreadBase *th, int *stackSize, int useMigratable)
static void CthThreadBaseFree (CthThreadBase *th)
 CpvDeclare (int, _numSwitches)
static void CthBaseInit (char **argv)
int CthImplemented ()
CthThread CthSelf ()
void CthPupBase (pup_er p, CthThreadBase *t, int useMigratable)
static void CthThreadFinished (CthThread t)
void CthSetSuspendable (CthThread t, int val)
int CthIsSuspendable (CthThread t)
void CthSetNext (CthThread t, CthThread v)
CthThread CthGetNext (CthThread t)
static void CthNoStrategy (void)
void CthSetStrategy (CthThread t, CthAwkFn awkfn, CthThFn chsfn)
static void CthBaseResume (CthThread t)
void CthSwitchThread (CthThread t)
 switch the thread to t
void CthSuspend (void)
void CthAwaken (CthThread th)
void CthYield ()
void CthAwakenPrio (CthThread th, int s, int pb, unsigned int *prio)
void CthYieldPrio (int s, int pb, unsigned int *prio)
void CthAddListener (CthThread t, struct CthThreadListener *l)
 This listener is about to begin receiving suspend and resume events for this thread.
CthThread CthPup (pup_er p, CthThread t)
 CthCpvDeclare (CthProcInfo, CthProc)
static void CthThreadInit (CthThread t, CthVoidFn fn, void *arg)
static void CthThreadFree (CthThread t)
void CthFree (CthThread t)
void CthDummy ()
void CthInit (char **argv)
static void CthOnly (CthThread t, void *dum1, void *dum2)
size_t CthStackOffset (CthThread t, char *p)
char * CthPointer (CthThread t, size_t pos)
static void CthResume1 (qt_t *sp, CthProcInfo proc, CthThread t)
void CthResume (CthThread t)
CthThread CthCreate (CthVoidFn fn, void *arg, int size)
CthThread CthCreateMigratable (CthVoidFn fn, void *arg, int size)
WINBASEAPI LPVOID WINAPI CreateFiber (DWORD dwStackSize, LPFIBER_START_ROUTINE lpStartAddress, LPVOID lpParameter)
WINBASEAPI VOID WINAPI DeleteFiber (LPVOID lpFiber)
WINBASEAPI LPVOID WINAPI ConvertThreadToFiber (LPVOID lpParameter)
WINBASEAPI VOID WINAPI SwitchToFiber (LPVOID lpFiber)
WINBASEAPI BOOL WINAPI SwitchToThread (VOID)
 CthCpvStatic (CthThread, CthPrevious)
 CthCpvStatic (threadTable, exitThreads)
 CthCpvStatic (int, nExit)
static void CthThreadInit (CthThread t)
static void CthClearThreads ()
void CthFiberBlock (CthThread t)
VOID CALLBACK FiberSetUp (PVOID fiberData)
 CthCpvStatic (pthread_mutex_t, sched_mutex)
 The sched_mutex is the current token of execution.
static void * CthOnly (void *arg)
 CpvStaticDeclare (CthThread, doomedThreadPool)
void CthStartThread (CmiUInt4 fn1, CmiUInt4 fn2, CmiUInt4 arg1, CmiUInt4 arg2)
void CthStartThread (qt_userf_t fn, void *arg)
int ptrDiffLen (const void *a, const void *b)
static CthThread CthCreateInner (CthVoidFn fn, void *arg, int size, int migratable)
void setProtection (char *, char *, int, int)
static CthThread CthThreadInit (void)
static void * CthAbortHelp (qt_t *sp, CthThread old, void *null)
static void * CthBlockHelp (qt_t *sp, CthThread old, void *null)
static void CthOnly (void *arg, void *vt, qt_userf_t fn)
void CthTraceResume (CthThread t)

Variables

static int CmiThreadIs_flag = 0
CthThreadBase_curMappedStack = 0
 CthAliasEnable brings this thread's stack into memory.


Typedef Documentation

typedef struct CthProcInfo* CthProcInfo

Definition at line 719 of file threads.c.

typedef VOID(WINAPI *) PFIBER_START_ROUTINE(LPVOID lpFiberParameter)

Definition at line 933 of file threads.c.

typedef PFIBER_START_ROUTINE LPFIBER_START_ROUTINE

Definition at line 936 of file threads.c.

typedef CthThread threadTable[100]

Definition at line 987 of file threads.c.

typedef void(*) uJcontext_fn_t(void)

Definition at line 1339 of file threads.c.


Function Documentation

int CmiThreadIs ( int  flag  ) 

Definition at line 176 of file threads.c.

References CmiThreadIs_flag.

Referenced by checkAddress().

CthThreadToken* CthGetToken ( CthThread  t  ) 

Definition at line 186 of file threads.c.

Referenced by CthResumeSchedulingThread().

int CthAliasCreate ( int  stackSize  ) 

Create an aliasable area of this size.

Returns alias handle.

Definition at line 228 of file threads.c.

References CmiAbort().

Referenced by CthAllocateStack().

void CthAliasFree ( int  fd  ) 

Definition at line 246 of file threads.c.

Referenced by CthThreadBaseFree().

void CthAliasEnable ( CthThreadBase t  ) 

Definition at line 259 of file threads.c.

References _curMappedStack, CthThreadBase::aliasStackHandle, CmiAbort(), dest, CthThreadBase::isMigratable, printf(), s, CthThreadBase::stack, and CthThreadBase::stacksize.

Referenced by CthBaseResume(), CthCreateInner(), and CthPupBase().

CthCpvStatic ( CthThread  ,
CthCurrent   
)

CthCpvDeclare ( char *  ,
CthData   
)

CthCpvStatic ( int  ,
CthDatasize   
)

void CthSetThreadID ( CthThread  th,
int  a,
int  b,
int  c 
)

Definition at line 306 of file threads.c.

References c.

Referenced by Group::CkAddThreadListeners(), and CkMigratable::CkAddThreadListeners().

CmiObjId* CthGetThreadID ( CthThread  th  ) 

Definition at line 314 of file threads.c.

Referenced by traceThreadListener_resume().

char* CthGetData ( CthThread  t  ) 

Definition at line 319 of file threads.c.

static void CthFixData ( CthThread  t  )  [inline, static]

Definition at line 328 of file threads.c.

References data, and realloc().

Referenced by CthBaseResume(), CthRegister(), CthRegistered(), and CthThreadBaseInit().

int CthRegister ( int  size  ) 

Allocate another size bytes of thread-local storage, and return the offset into the thread storage buffer.

Definition at line 345 of file threads.c.

References CthFixData(), CthThreadBase::data, and size.

Referenced by Cpthread_key_create().

void CthRegistered ( int  maxOffset  ) 

Make sure we have room to store up to at least maxOffset bytes of thread-local storage.

Definition at line 364 of file threads.c.

References CthFixData(), and CthThreadBase::data.

CthCpvStatic ( int  ,
_defaultStackSize   
)

static void CthThreadBaseInit ( CthThreadBase th  )  [static]

Definition at line 376 of file threads.c.

References CthThreadBase::aliasStackHandle, CthThreadBase::awakenfn, CthThreadBase::choosefn, CmiMyPe(), CthFixData(), CthSetStrategyDefault(), CthThreadBase::data, CthThreadBase::datasize, CthThreadBase::exiting, _CmiObjId::id, CthThreadBase::isMigratable, CthThreadBase::listener, malloc(), CthThreadBase::next, CthThreadBase::scheduled, CthThreadBase::stack, CthThreadBase::stacksize, CthThreadBase::suspendable, CthThreadToken::thread, CthThreadBase::tid, and CthThreadBase::token.

Referenced by CthThreadInit().

static void* CthAllocateStack ( CthThreadBase th,
int stackSize,
int  useMigratable 
) [static]

Definition at line 417 of file threads.c.

References CthThreadBase::aliasStackHandle, CmiIsomalloc(), CthAliasCreate(), CthThreadBase::isMigratable, malloc(), CthThreadBase::stack, and CthThreadBase::stacksize.

Referenced by CthCreateInner(), and CthPupBase().

static void CthThreadBaseFree ( CthThreadBase th  )  [static]

Definition at line 437 of file threads.c.

References CthThreadBase::aliasStackHandle, CmiIsomallocFree(), CthAliasFree(), CthThreadBase::data, CthThreadListener::free, free(), CthThreadBase::isMigratable, CthThreadBase::listener, CthThreadListener::next, CthThreadBase::scheduled, CthThreadBase::stack, CthThreadToken::thread, and CthThreadBase::token.

Referenced by CthThreadFree().

CpvDeclare ( int  ,
_numSwitches   
)

static void CthBaseInit ( char **  argv  )  [static]

Definition at line 472 of file threads.c.

References CmiGetArgIntDesc().

Referenced by CthInit().

int CthImplemented ( void   ) 

Definition at line 490 of file threads.c.

CthThread CthSelf ( void   ) 

Definition at line 492 of file threads.c.

Referenced by bgMain(), CfutureWait(), Tempo::ckTempoRecv(), CkWaitFuture(), CmiExit(), CmiGetNonLocal(), CmiNotifyIdle(), ConverseInit(), CpmThread3(), Cpthread_cond_wait(), Cpthread_join(), Cpthread_mutex_lock(), Cpthread_mutex_trylock(), Cpthread_mutex_unlock(), CthFree(), CthOnly(), CthResumeSchedulingThread(), CthSchedInit(), CthStartThread(), PythonObject::executeThread(), FiberSetUp(), MSA_CacheGroup< ENTRY_TYPE, ENTRY_OPS_CLASS, ENTRIES_PER_PAGE >::getListener(), TCharm::getSema(), CkCallback::impl_thread_delay(), ParFUMShadowArray::lockRegion(), commThreadInfo::run(), TCharm::stop(), MSA_Thread_Listener::suspend(), TCharm::TCharm(), Tempo::Tempo(), CkSema::wait(), CkSema::waitN(), and waitqd_QDChare::waitQD().

void CthPupBase ( pup_er  p,
CthThreadBase t,
int  useMigratable 
)

Definition at line 497 of file threads.c.

References CthThreadBase::awakenfn, CthThreadBase::choosefn, CmiAbort(), CmiIsomallocPup(), CthAliasEnable(), CthAllocateStack(), CthThreadBase::data, CthThreadBase::datasize, CthThreadBase::isMigratable, CthThreadBase::listener, malloc(), CthThreadBase::next, pup_bytes(), pup_isUnpacking(), CthThreadBase::scheduled, CthThreadBase::stack, CthThreadBase::stacksize, CthThreadBase::suspendable, CthThreadToken::thread, and CthThreadBase::token.

Referenced by CthPup().

static void CthThreadFinished ( CthThread  t  )  [static]

Definition at line 547 of file threads.c.

References CthSuspend().

Referenced by CthOnly(), CthStartThread(), and FiberSetUp().

void CthSetSuspendable ( CthThread  t,
int  val 
)

Definition at line 555 of file threads.c.

int CthIsSuspendable ( CthThread  t  ) 

Definition at line 556 of file threads.c.

void CthSetNext ( CthThread  t,
CthThread  v 
)

Definition at line 558 of file threads.c.

Referenced by CfutureWait(), CkWaitFuture(), and CthResumeSchedulingThread().

CthThread CthGetNext ( CthThread  t  ) 

Definition at line 559 of file threads.c.

Referenced by CfutureAwaken(), CthSuspendSchedulingThread(), and setFuture().

static void CthNoStrategy ( void   )  [static]

Definition at line 561 of file threads.c.

References CmiAbort().

Referenced by CthAwaken(), CthAwakenPrio(), and CthSuspend().

void CthSetStrategy ( CthThread  t,
CthAwkFn  awkfn,
CthThFn  chsfn 
)

Definition at line 566 of file threads.c.

Referenced by BgSetStrategyBigSimDefault(), CthSchedInit(), CthSetStrategyDefault(), and CthSuspendSchedulingThread().

static void CthBaseResume ( CthThread  t  )  [inline, static]

Definition at line 575 of file threads.c.

References CthAliasEnable(), CthFixData(), CthThreadListener::next, and CthThreadListener::resume.

Referenced by CthResume(), CthResume1(), and CthSwitchThread().

void CthSwitchThread ( CthThread  t  ) 

switch the thread to t

Definition at line 591 of file threads.c.

References CthBaseResume().

Referenced by CmiSwitchToPEFn().

void CthSuspend ( void   ) 

Definition at line 599 of file threads.c.

References CthThreadBase::choosefn, CmiAbort(), CthNoStrategy(), CthResume(), CthThreadBase::listener, CthThreadListener::next, CthThreadBase::scheduled, CthThreadListener::suspend, CthThreadBase::suspendable, and traceSuspend().

Referenced by CfutureWait(), Tempo::ckTempoRecv(), CkWaitFuture(), CPathRecv(), CpmThread3(), Cpthread_cond_wait(), Cpthread_exit(), Cpthread_join(), Cpthread_mutex_lock(), CthThreadFinished(), CthYield(), CthYieldPrio(), CkCallback::impl_thread_delay(), ParFUMShadowArray::lockRegion(), commThreadInfo::run(), workThreadInfo::scheduler(), BgNode::startCommTh(), BgNode::startWorkTh(), TCharm::stop(), MSA_Thread_Listener::suspend(), ParFUMShadowArray::unlockRegion(), CkSema::wait(), CkSema::waitN(), and waitqd_QDChare::waitQD().

void CthAwaken ( CthThread  th  ) 

Definition at line 626 of file threads.c.

References CthNoStrategy(), and traceAwaken().

Referenced by CkIndex_TempoArray::_call_TempoArray_void(), CkIndex_TempoChare::_call_TempoChare_void(), CkIndex_TempoGroup::_call_TempoGroup_void(), CkIndex_waitqd_QDChare::_call_waitQD_void(), workThreadInfo::addAffMessage(), nodeInfo::addBgNodeInbuffer(), nodeInfo::addBgNodeMessage(), BgNode::addMessage(), BgNode::assignMsg(), BgNode::BgNode(), BgNodeInitialize(), CfutureAwaken(), CPathGetSingle(), CPathSendHandler(), CpmThread2(), CpmThreadSize2(), Cpthread_cond_broadcast(), Cpthread_cond_signal(), Cpthread_cond_wait(), Cpthread_create3(), Cpthread_exit(), Cpthread_mutex_unlock(), CthYield(), ParFUMShadowArray::lockReply(), waitqd_QDChare::onQD(), scheduleWorkerThread(), CkCallback::send(), setFuture(), CkSema::signal(), MSA_Thread_Listener::signal(), TCharm::start(), BgNode::startCommTh(), BgNode::startWorkTh(), Tempo::tempoGeneric(), and ParFUMShadowArray::unlockReply().

void CthYield ( void   ) 

Definition at line 639 of file threads.c.

References CthAwaken(), and CthSuspend().

Referenced by chunk::addRemoteEdge(), FEM_Adapt_Algs::Coarsen(), chunk::coarseningElements(), FEM_AdaptL::edge_bisect(), FEM_AdaptL::edge_contraction(), FEM_AdaptL::edge_contraction_help(), FEM_AdaptL::edge_flip(), chunk::getAccessLock(), chunk::getAdjustLock(), FEM_MUtil::idxllockLocal(), FEM_lock::lock(), element::lockArc(), element::lockLF(), FEM_AdaptL::lockNodes(), NetFEM_Begin(), ParFUMShadowArray::recv_splits(), FEM_Adapt_Algs::Refine(), Bulk_Adapt::Refine_h(), element::refineCP(), element::refineLE(), element::refineLF(), chunk::refiningElements(), commThreadInfo::run(), workThreadInfo::scheduler(), FEM_lock::unlock(), and FEM_AdaptL::vertex_remove().

void CthAwakenPrio ( CthThread  th,
int  s,
int  pb,
unsigned int prio 
)

Definition at line 645 of file threads.c.

References CthNoStrategy(), s, and traceAwaken().

Referenced by workThreadInfo::addAffMessage(), nodeInfo::addBgNodeInbuffer(), nodeInfo::addBgNodeMessage(), CthYieldPrio(), findLeastTime(), and updateRealMsgs().

void CthYieldPrio ( int  s,
int  pb,
unsigned int prio 
)

Definition at line 658 of file threads.c.

References CthAwakenPrio(), CthSuspend(), and s.

Referenced by workThreadInfo::scheduler().

void CthAddListener ( CthThread  th,
struct CthThreadListener l 
)

This listener is about to begin receiving suspend and resume events for this thread.

"suspend", "resume", "free", and "data" fields must all already be set. When this thread exits, l->free will be called on this listener, which should deallocate the listener memory.

Definition at line 667 of file threads.c.

References CthThreadListener::next, p, and CthThreadListener::thread.

Referenced by CkMigratable::CkAddThreadListeners(), and TraceProjections::traceAddThreadListeners().

CthThread CthPup ( pup_er  p,
CthThread  t 
)

Definition at line 732 of file threads.c.

References CmiAbort(), CthFree(), CthPupBase(), malloc(), pup_bytes(), pup_isDeleting(), and pup_isUnpacking().

Referenced by TCharm::pupThread().

CthCpvDeclare ( CthProcInfo  ,
CthProc   
)

static void CthThreadInit ( CthThread  t,
CthVoidFn  fn,
void *  arg 
) [static]

Definition at line 763 of file threads.c.

References CthThreadStruct::base, CthThreadBaseInit(), CthThreadStruct::savedptr, CthThreadStruct::savedsize, CthThreadStruct::savedstack, CthThreadStruct::stacklen, CthThreadStruct::startarg, and CthThreadStruct::startfn.

Referenced by CthCreate(), CthCreateInner(), and CthInit().

static void CthThreadFree ( CthThread  t  )  [static]

Definition at line 774 of file threads.c.

References CthThreadStruct::base, CthThreadBaseFree(), free(), and CthThreadStruct::savedstack.

Referenced by CthAbortHelp(), CthClearThreads(), CthFiberBlock(), CthFree(), and CthResume1().

void CthFree ( CthThread  t  ) 

Definition at line 781 of file threads.c.

References CthThreadStruct::base, CthClearThreads(), CthSelf(), CthThreadFree(), and CthThreadBase::exiting.

Referenced by TCharm::clear(), CpmThread3(), Cpthread_exit(), CthPup(), and TCharm::~TCharm().

void CthDummy (  ) 

Definition at line 793 of file threads.c.

Referenced by CthInit(), and CthResume1().

void CthInit ( char **  argv  ) 

Definition at line 795 of file threads.c.

References CmiThreadIs_flag, CthBaseInit(), CthDummy(), CthThreadInit(), malloc(), and p.

Referenced by CommunicationServer(), ConverseInit(), ConverseRunPE(), KillOnAllSigs(), and threadInit().

static void CthOnly ( CthThread  t,
void *  dum1,
void *  dum2 
) [static]

Definition at line 830 of file threads.c.

References CthThreadFinished(), CthThreadStruct::startarg, and CthThreadStruct::startfn.

Referenced by CthResume1().

size_t CthStackOffset ( CthThread  t,
char *  p 
)

Definition at line 839 of file threads.c.

References s, and CthProcInfo::stackbase.

Referenced by TCharm::UserData::UserData().

char* CthPointer ( CthThread  t,
size_t  pos 
)

Definition at line 845 of file threads.c.

References p, CthThreadStruct::savedsize, and CthThreadStruct::savedstack.

Referenced by TCharm::UserData::getData(), and TCharm::UserData::pup().

static void CthResume1 ( qt_t *  sp,
CthProcInfo  proc,
CthThread  t 
) [static]

Definition at line 857 of file threads.c.

References CthThreadStruct::base, bytes, CthBaseResume(), CthDummy(), CthOnly(), CthThreadFree(), CthThreadBase::exiting, free(), malloc(), CthThreadStruct::savedptr, CthThreadStruct::savedsize, CthThreadStruct::savedstack, CthProcInfo::stackbase, and CthThreadStruct::stacklen.

Referenced by CthResume().

void CthResume ( CthThread  t  ) 

Definition at line 897 of file threads.c.

References CthThreadStruct::base, CthBaseResume(), CthFiberBlock(), CthResume1(), CthThreadBase::exiting, CthThreadStruct::fiber, CthProcInfo::switchbuf_sp, and SwitchToFiber().

Referenced by CmiNext(), CthResumeNormalThread(), CthResumeSchedulingThread(), CthSuspend(), and PythonObject::execute().

CthThread CthCreate ( CthVoidFn  fn,
void *  arg,
int  size 
)

Definition at line 904 of file threads.c.

References CmiAbort(), CreateFiber(), CthThreadInit(), CthThreadStruct::fiber, FiberSetUp(), malloc(), and size.

Referenced by CkIndex_TempoArray::_call_TempoArray_void(), CkIndex_TempoChare::_call_TempoChare_void(), CkIndex_TempoGroup::_call_TempoGroup_void(), CkIndex_waitqd_QDChare::_call_waitQD_void(), BgNode::BgNode(), BgNodeInitialize(), ConverseInit(), CPathGetSingle(), CpmThread2(), CpmThreadSize2(), Cpthread_create3(), CthCreateMigratable(), CthSuspendSchedulingThread(), PythonObject::execute(), and TCharm::TCharm().

CthThread CthCreateMigratable ( CthVoidFn  fn,
void *  arg,
int  size 
)

Definition at line 911 of file threads.c.

References CthCreate(), and size.

Referenced by TCharm::TCharm().

WINBASEAPI LPVOID WINAPI CreateFiber ( DWORD  dwStackSize,
LPFIBER_START_ROUTINE  lpStartAddress,
LPVOID  lpParameter 
)

Referenced by CthCreate().

WINBASEAPI VOID WINAPI DeleteFiber ( LPVOID  lpFiber  ) 

WINBASEAPI LPVOID WINAPI ConvertThreadToFiber ( LPVOID  lpParameter  ) 

WINBASEAPI VOID WINAPI SwitchToFiber ( LPVOID  lpFiber  ) 

Referenced by CthFiberBlock(), and CthResume().

WINBASEAPI BOOL WINAPI SwitchToThread ( VOID   ) 

CthCpvStatic ( CthThread  ,
CthPrevious   
)

CthCpvStatic ( threadTable  ,
exitThreads   
)

CthCpvStatic ( int  ,
nExit   
)

static void CthThreadInit ( CthThread  t  )  [static]

Definition at line 991 of file threads.c.

References CthThreadStruct::base, and CthThreadBaseInit().

static void CthClearThreads (  )  [static]

Definition at line 1025 of file threads.c.

References CthThreadFree(), n, and p.

Referenced by CthFree(), and FiberSetUp().

void CthFiberBlock ( CthThread  t  ) 

Definition at line 1071 of file threads.c.

References CthThreadFree(), CthThreadStruct::fiber, and SwitchToFiber().

Referenced by CthResume().

VOID CALLBACK FiberSetUp ( PVOID  fiberData  ) 

Definition at line 1101 of file threads.c.

References CthClearThreads(), CthSelf(), CthThreadFinished(), and ptr.

Referenced by CthCreate().