The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Thread Class Reference

#include <Thread.h>

+ Collaboration diagram for Thread:

Classes

struct  StateLevel
 

Public Types

enum  Status {
  Ready, Running, Sleeping, Zombie,
  AwaitingJoin, Suspended
}
 
enum  DebugState { None, SemWait, CondWait, Joining }
 
enum  WakeReason {
  NotWoken, WokenByAlarm, WokenByEvent, WokenBecauseTerminating,
  WokenBecauseUnwinding, Unknown
}
 
enum  UnwindType { Continue = 0, ReleaseBlockingThread, Exit }
 
typedef int(* ThreadStartFunc) (void *)
 

Public Member Functions

 Thread (Process *pParent, ThreadStartFunc pStartFunction, void *pParam, void *pStack=0, bool semiUser=false, bool bDontPickCore=false, bool delayedStart=false)
 
 Thread (Process *pParent)
 
 Thread (Process *pParent, SyscallState &state, bool delayedStart=false)
 
virtual ~Thread ()
 
void shutdown ()
 
void forceToStartupProcessor ()
 
SchedulerState & state ()
 
SchedulerState & pushState ()
 
void popState (bool clean=true)
 
VirtualAddressSpace::StackgetStateUserStack ()
 
void setStateUserStack (VirtualAddressSpace::Stack *st)
 
size_t getStateLevel () const
 
void allocateStackAtLevel (size_t stateLevel)
 
void setKernelStack ()
 
void pokeState (size_t stateLevel, SchedulerState &state)
 
ProcessgetParent () const
 
void setParent (Process *p)
 
Status getStatus () const
 
void setStatus (Status s)
 
int getExitCode ()
 
void * getKernelStack ()
 
size_t getId ()
 
size_t getErrno ()
 
void setErrno (size_t err)
 
bool wasInterrupted ()
 
void setInterrupted (bool b)
 
UnwindType getUnwindState ()
 
void setUnwindState (UnwindType ut)
 
void setBlockingThread (Thread *pT)
 
ThreadgetBlockingThread (size_t level=~0UL)
 
DebugState getDebugState (uintptr_t &address)
 
void setDebugState (DebugState state, uintptr_t address)
 
SpinlockgetLock ()
 
bool sendEvent (Event *pEvent)
 
void inhibitEvent (size_t eventNumber, bool bInhibit)
 
void cullEvent (Event *pEvent)
 
void cullEvent (size_t eventNumber)
 
EventgetNextEvent ()
 
bool hasEvents ()
 
bool hasEvent (Event *pEvent)
 
bool hasEvent (size_t eventNumber)
 
void setPriority (size_t p)
 
size_t getPriority ()
 
void addRequest (RequestQueue::Request *req)
 
void removeRequest (RequestQueue::Request *req)
 
void unexpectedExit ()
 
uintptr_t getTlsBase ()
 
void resetTlsBase ()
 
void setTlsBase (uintptr_t base)
 
size_t getCpuId ()
 
void setCpuId (size_t id)
 
bool join ()
 
bool detach ()
 
bool detached () const
 
bool isInterruptible ()
 
void addWakeupWatcher (WakeReason *watcher)
 
void removeWakeupWatcher (WakeReason *watcher)
 
class PerProcessorSchedulergetScheduler () const
 

Static Public Member Functions

static void threadExited () NORETURN
 

Protected Member Functions

void setScheduler (class PerProcessorScheduler *pScheduler)
 
void setInterruptible (bool state)
 

Private Member Functions

 Thread (const Thread &)
 
Threadoperator= (const Thread &)
 
void cleanStateLevel (size_t level)
 
void reportWakeup (WakeReason reason)
 
void reportWakeupUnlocked (WakeReason reason)
 

Private Attributes

size_t m_nStateLevel = 0
 
Processm_pParent = nullptr
 
void * m_pAllocatedStack = nullptr
 
size_t m_Id = 0
 
size_t m_Errno = 0
 
uintptr_t m_DebugStateAddress = 0
 
class PerProcessorSchedulerm_pScheduler = nullptr
 
size_t m_Priority = DEFAULT_PRIORITY
 
void * m_pTlsBase = nullptr
 
size_t m_ProcId = 0
 
Threadm_pWaiter = nullptr
 
Spinlock m_Lock
 
Spinlock m_ConcurrencyLock
 
List< Event * > m_EventQueue
 
List< RequestQueue::Request * > m_PendingRequests
 
List< WakeReason * > m_WakeWatchers
 
StateLevel m_StateLevels [MAX_NESTED_EVENTS]
 
volatile Status m_Status = Ready
 
int m_ExitCode = 0
 
DebugState m_DebugState = None
 
UnwindType m_UnwindState = Continue
 
bool m_bInterrupted = false
 
bool m_bTlsBaseOverride = false
 
bool m_bRemovingRequests = false
 
bool m_bDetached = false
 
bool m_bInterruptible = true
 

Friends

class PerProcessorScheduler
 
class Uninterruptible
 

Detailed Description

An abstraction of a thread of execution.

The thread maintains not just one execution context (SchedulerState) but a stack of them, along with a stack of masks for inhibiting event dispatch.

This enables event dispatch at any time without affecting the previous state, as well as changing the event mask from nested event handlers without affecting the state of any other running handler.

Definition at line 54 of file Thread.h.

Member Typedef Documentation

typedef int(* Thread::ThreadStartFunc) (void *)

Thread start function type.

Definition at line 93 of file Thread.h.

Member Enumeration Documentation

"Debug state" - higher level state of the thread.

Definition at line 73 of file Thread.h.

The state that a thread can possibly have.

Definition at line 62 of file Thread.h.

Enum used by the following function.

Enumerator
Continue 

No unwind necessary, carry on as normal.

ReleaseBlockingThread 

(a) below.

Exit 

(b) below.

Definition at line 241 of file Thread.h.

Reasons for a wakeup.

Definition at line 82 of file Thread.h.

Constructor & Destructor Documentation

Thread::Thread ( Process pParent,
ThreadStartFunc  pStartFunction,
void *  pParam,
void *  pStack = 0,
bool  semiUser = false,
bool  bDontPickCore = false,
bool  delayedStart = false 
)

Creates a new Thread belonging to the given Process. It shares the Process' * virtual address space.

The constructor registers itself with the Scheduler and parent process - this * does not need to be done manually.

If kernelMode is true, and pStack is NULL, no stack space is assigned.

Parameters
pParentThe parent process. Can never be NULL.
kernelModeIs the thread going to be operating in kernel space only? *
pStartFunctionThe function to be run when the thread starts. *
pParamA parameter to give the startFunction. *
pStack(Optional) A (user mode) stack to give the thread - applicable for user mode threads * only. *
semiUser(Optional) Whether to start the thread as if it was a user mode thread, but begin in kernel mode (to do setup and jump to usermode manually). *
delayedStart(Optional) Start the thread in a halted state.

Definition at line 42 of file Thread.cc.

References Spinlock::acquire(), ProcessorThreadAllocator::addThread(), Scheduler::addThread(), Process::addThread(), allocateStackAtLevel(), FATAL, getScheduler(), Processor::information(), Scheduler::instance(), m_Id, m_Lock, m_pAllocatedStack, Thread::StateLevel::m_pAuxillaryStack, Thread::StateLevel::m_pKernelStack, m_pParent, and m_Status.

Thread::Thread ( Process pParent)

Alternative constructor - this should be used only by initialiseMultitasking() to define the first kernel thread.

Definition at line 116 of file Thread.cc.

References Scheduler::addThread(), Process::addThread(), FATAL, Scheduler::instance(), m_Id, and m_pParent.

Thread::Thread ( Process pParent,
SyscallState &  state,
bool  delayedStart = false 
)

Constructor for when forking a process. Assumes pParent has already been set up with a clone of the current address space and sets up the new thread to return to the caller in that address space.

Definition at line 135 of file Thread.cc.

References Spinlock::acquire(), ProcessorThreadAllocator::addThread(), Process::addThread(), allocateStackAtLevel(), FATAL, Processor::information(), m_bTlsBaseOverride, m_Id, m_Lock, m_pAllocatedStack, m_pParent, m_pTlsBase, and m_Status.

Thread::~Thread ( )
virtual
Thread::Thread ( const Thread )
private

Copy-constructor

Member Function Documentation

void Thread::addRequest ( RequestQueue::Request req)

Adds a request to the Thread's pending request list

Definition at line 730 of file Thread.cc.

References m_bRemovingRequests, m_PendingRequests, and List< T, nodePoolSize >::pushBack().

Referenced by RequestQueue::addRequest().

+ Here is the caller graph for this function:

void Thread::addWakeupWatcher ( WakeReason watcher)

Add a new watcher location that is updated when this thread is woken.

Note
the location is removed upon the first wakeup

Definition at line 988 of file Thread.cc.

References m_Lock, m_WakeWatchers, and List< T, nodePoolSize >::pushBack().

Referenced by Semaphore::acquireWithResult().

+ Here is the caller graph for this function:

void Thread::allocateStackAtLevel ( size_t  stateLevel)

Allocates a new stack for a specific nesting level, if required

Definition at line 484 of file Thread.cc.

References VirtualAddressSpace::allocateStack(), VirtualAddressSpace::getKernelAddressSpace(), and Thread::StateLevel::m_pKernelStack.

Referenced by pushState(), and Thread().

+ Here is the caller graph for this function:

void Thread::cleanStateLevel ( size_t  level)
private
void Thread::cullEvent ( Event pEvent)

Walks the event queue, removing the event pEvent , if found.

Definition at line 580 of file Thread.cc.

References List< T, nodePoolSize >::begin(), Event::deregisterThread(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, and m_Lock.

void Thread::cullEvent ( size_t  eventNumber)

Walks the event queue, removing the event with number eventNumber , if found.

Definition at line 613 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, m_Lock, and Vector< T >::pushBack().

bool Thread::detach ( )

Marks the thread as detached.

A detached thread cannot be joined and will be automatically cleaned up when the thread entry point returns, or the thread is otherwise terminated. A thread cannot be detached if another thread is already join()ing it.

Definition at line 885 of file Thread.cc.

References SharedPointer< T >::allocate(), ERROR, join(), m_bDetached, m_ConcurrencyLock, Thread::StateLevel::m_InhibitMask, Thread::StateLevel::m_pAuxillaryStack, Thread::StateLevel::m_pKernelStack, m_pWaiter, Thread::StateLevel::m_State, m_Status, and WARNING.

Referenced by RequestQueue::addAsyncRequest(), KernelElf::getDependingModule(), Ps2Mouse::initialise(), PerProcessorScheduler::initialise(), Dm9601::initialiseDriver(), PosixSubsystem::invoke(), Ehci::irq(), Ne2k::Ne2k(), Nic3C90x::Nic3C90x(), pocketknife::runConcurrently(), and X86Keyboard::setLedState().

+ Here is the caller graph for this function:

bool Thread::detached ( ) const
inline

Checks detached state of the thread.

Definition at line 417 of file Thread.h.

References NORETURN, and PerProcessorScheduler::operator=().

Referenced by PerProcessorScheduler::killCurrentThread(), and Process::~Process().

+ Here is the caller graph for this function:

size_t Thread::getCpuId ( )
inline

Gets this thread's CPU ID

Definition at line 378 of file Thread.h.

Referenced by ThreadsCommand::execute().

+ Here is the caller graph for this function:

DebugState Thread::getDebugState ( uintptr_t &  address)
inline

Returns the thread's debug state.

Definition at line 288 of file Thread.h.

Referenced by ThreadsCommand::execute().

+ Here is the caller graph for this function:

size_t Thread::getErrno ( )
inline

Returns the last error that occurred (errno).

Definition at line 216 of file Thread.h.

int Thread::getExitCode ( )
inline

Retrieves the exit status of the Thread.

Definition at line 201 of file Thread.h.

size_t Thread::getId ( )
inline

Returns the Thread's ID.

Definition at line 210 of file Thread.h.

Referenced by PerProcessorScheduler::checkEventState(), ThreadsCommand::execute(), X64InterruptManager::interrupt(), PosixSubsystem::sendSignal(), and PosixSubsystem::threadException().

+ Here is the caller graph for this function:

void * Thread::getKernelStack ( )

Retrieves a pointer to the top of the Thread's kernel stack.

Definition at line 493 of file Thread.cc.

References FATAL, m_nStateLevel, and Thread::StateLevel::m_pKernelStack.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::initialise(), PerProcessorScheduler::killCurrentThread(), and PerProcessorScheduler::schedule().

+ Here is the caller graph for this function:

Spinlock& Thread::getLock ( )
inline

Returns the thread's scheduler lock.

Definition at line 301 of file Thread.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::killCurrentThread(), Semaphore::release(), PerProcessorScheduler::schedule(), shutdown(), and ConditionVariable::signal().

+ Here is the caller graph for this function:

Event * Thread::getNextEvent ( )

Grabs the first available unmasked event and pops it off the queue. This also pushes the inhibit mask stack.

Note
This is intended only to be called by PerProcessorScheduler.

Definition at line 643 of file Thread.cc.

References List< T, nodePoolSize >::count(), Event::deregisterThread(), ERROR, Event::getNumber(), Event::getSpecificNestingLevel(), m_bInterruptible, m_EventQueue, m_Lock, m_nStateLevel, List< T, nodePoolSize >::popFront(), and List< T, nodePoolSize >::pushBack().

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

Process* Thread::getParent ( ) const
inline
PerProcessorScheduler * Thread::getScheduler ( ) const

Gets the per-processor scheduler for this Thread.

Definition at line 956 of file Thread.cc.

Referenced by PerProcessorScheduler::checkEventState(), PerProcessorScheduler::schedule(), and Thread().

+ Here is the caller graph for this function:

size_t Thread::getStateLevel ( ) const

Returns the state nesting level.

Definition at line 474 of file Thread.cc.

References m_nStateLevel.

Referenced by PerProcessorScheduler::checkEventState(), PosixSubsystem::exit(), PosixSubsystem::invoke(), PerProcessorScheduler::schedule(), and TimeoutGuard::TimeoutGuard().

+ Here is the caller graph for this function:

Status Thread::getStatus ( ) const
inline
uintptr_t Thread::getTlsBase ( )
UnwindType Thread::getUnwindState ( )
inline

Returns nonzero if the thread has been asked to unwind quickly.

This happens if this thread (or a thread blocking on this thread) is scheduled for deletion. The intended behaviour is that the stack is unwound as quickly as possible with all semaphores and buffers deleted to a point where

(a) no threads can possibly be blocking on this or (b) The thread has no more locks taken and is ready to be destroyed, at which point it should call the subsys exit() function.

Whether to adopt option A or B depends on whether this thread or not has been asked to terminate, given by the return value.

Definition at line 261 of file Thread.h.

Referenced by RequestQueue::addRequest(), join(), PerProcessorScheduler::timer(), and ConditionVariable::wait().

+ Here is the caller graph for this function:

bool Thread::hasEvent ( Event pEvent)

Determines if the given event is currently in the event queue.

Definition at line 698 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), m_EventQueue, and m_Lock.

Referenced by PosixSubsystem::sendSignal().

+ Here is the caller graph for this function:

void Thread::inhibitEvent ( size_t  eventNumber,
bool  bInhibit 
)

Sets the given event number as inhibited.

Parameters
bInhibitTrue if the event is to be inhibited, false if the event is to be allowed.

Definition at line 571 of file Thread.cc.

References ExtensibleBitmap::clear(), Thread::StateLevel::m_InhibitMask, m_Lock, m_nStateLevel, and ExtensibleBitmap::set().

bool Thread::isInterruptible ( )

Gets whether this thread is interruptible or not.

Definition at line 940 of file Thread.cc.

References m_bInterruptible.

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

bool Thread::join ( )

Blocks until the Thread returns.

After join() returns successfully, the thread object is NOT valid.

Returns
whether the thread was joined or not.

Definition at line 836 of file Thread.cc.

References Spinlock::acquire(), Continue, getUnwindState(), Processor::information(), m_bDetached, m_ConcurrencyLock, m_pWaiter, m_Status, Spinlock::release(), setDebugState(), and wasInterrupted().

Referenced by pocketknife::attachTo(), detach(), RequestQueue::halt(), and InputManager::shutdown().

+ Here is the caller graph for this function:

Thread& Thread::operator= ( const Thread )
private

Assignment operator

Referenced by Process::hasSharedAddressSpace().

+ Here is the caller graph for this function:

void Thread::pokeState ( size_t  stateLevel,
SchedulerState &  state 
)

Overwrites the state at the given nesting level.

Parameters
stateLevelThe nesting level to edit.
stateThe state to copy.

Definition at line 517 of file Thread.cc.

References ERROR, and Thread::StateLevel::m_State.

void Thread::popState ( bool  clean = true)

Decreases the state nesting level by one, popping both the state stack and the inhibit mask stack. If clean == true, the stacks and other resources will also be cleaned up. Pass clean = false if losing the stack would be dangerous in a particular context.

Definition at line 444 of file Thread.cc.

References cleanStateLevel(), ERROR, m_nStateLevel, and setKernelStack().

Referenced by PerProcessorScheduler::checkEventState(), PerProcessorScheduler::eventHandlerReturned(), and PosixSubsystem::invoke().

+ Here is the caller graph for this function:

SchedulerState & Thread::pushState ( )

Increases the state nesting level by one - pushes a new state to the top of the state stack. This also pushes to the top of the inhibited events stack, copying the current inhibit mask.

Todo:
This should also push errno and m_bInterrupted, so syscalls can be used safely in interrupt handlers.
Returns
A reference to the previous state.
Todo:
Take some action here - possibly kill the thread?

Definition at line 425 of file Thread.cc.

References allocateStackAtLevel(), ERROR, Thread::StateLevel::m_InhibitMask, m_nStateLevel, Thread::StateLevel::m_State, and setKernelStack().

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

void Thread::removeRequest ( RequestQueue::Request req)

Removes a request from the Thread's pending request list

Definition at line 738 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_bRemovingRequests, and m_PendingRequests.

Referenced by RequestQueue::addRequest(), and RequestQueue::work().

+ Here is the caller graph for this function:

void Thread::removeWakeupWatcher ( WakeReason watcher)

Remove a wakeup watcher.

Definition at line 995 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_Lock, and m_WakeWatchers.

Referenced by Semaphore::acquireWithResult().

+ Here is the caller graph for this function:

void Thread::reportWakeup ( WakeReason  reason)
private

Report a wakeup.

Definition at line 1012 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::clear(), List< T, nodePoolSize >::end(), m_Lock, and m_WakeWatchers.

Referenced by sendEvent(), and shutdown().

+ Here is the caller graph for this function:

void Thread::resetTlsBase ( )

Resets the TLS base address for this thread and re-maps it. Note: doesn't free the memory - only call after a call to something like revertToKernelAddressSpace!

Definition at line 811 of file Thread.cc.

References getTlsBase(), m_bTlsBaseOverride, m_pTlsBase, and Processor::setTlsBase().

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

bool Thread::sendEvent ( Event pEvent)

Sends the asynchronous event pEvent to this thread.

If the thread ID is greater than or equal to EVENT_TID_MAX, the event will be ignored.

Todo:
we should be checking inhibits HERE! so we don't wake a thread that has inhibited the sent event

Definition at line 529 of file Thread.cc.

References Spinlock::acquire(), Scheduler::instance(), m_bInterruptible, m_EventQueue, m_Lock, m_Status, List< T, nodePoolSize >::pushBack(), Event::registerThread(), Spinlock::release(), reportWakeup(), and WARNING.

Referenced by PerProcessorScheduler::checkEventState(), File::dataChanged(), GPTimer::interrupt(), HostedTimer::irq(), Rtc::irq(), PosixSubsystem::kill(), InputManager::mainThread(), Buffer< T, allowShortOperation >::notifyMonitors(), PosixSubsystem::sendSignal(), and ConsoleFile::triggerEvent().

+ Here is the caller graph for this function:

void Thread::setCpuId ( size_t  id)
inline

Sets this thread's CPU ID

Definition at line 384 of file Thread.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::initialise(), and PerProcessorScheduler::processorAddThread().

+ Here is the caller graph for this function:

void Thread::setDebugState ( DebugState  state,
uintptr_t  address 
)
inline

Sets the thread's debug state.

Definition at line 294 of file Thread.h.

Referenced by Semaphore::acquireWithResult(), join(), and ConditionVariable::wait().

+ Here is the caller graph for this function:

void Thread::setErrno ( size_t  err)
inline

Sets the last error - errno.

Definition at line 222 of file Thread.h.

void Thread::setInterrupted ( bool  b)
inline

Sets whether the thread was just interrupted deliberately.

Definition at line 235 of file Thread.h.

Referenced by Semaphore::acquireWithResult(), and ConditionVariable::wait().

+ Here is the caller graph for this function:

void Thread::setInterruptible ( bool  state)
protected

Sets or unsets the interruptible state of the Thread.

Definition at line 945 of file Thread.cc.

References m_bInterruptible, m_Lock, and state().

void Thread::setKernelStack ( )

Sets the new kernel stack for the current state level in the TSS

Definition at line 507 of file Thread.cc.

References Processor::information(), m_nStateLevel, and Thread::StateLevel::m_pKernelStack.

Referenced by popState(), and pushState().

+ Here is the caller graph for this function:

void Thread::setScheduler ( class PerProcessorScheduler pScheduler)
protected

Sets the scheduler for the Thread.

Definition at line 951 of file Thread.cc.

Referenced by PerProcessorScheduler::addThread().

+ Here is the caller graph for this function:

void Thread::setStatus ( Thread::Status  s)
void Thread::setTlsBase ( uintptr_t  base)

Set the TLS base for this thread. Once set, it must be cleaned up by the caller when the thread terminates, which makes this primarily useful for userspace TLS segments.

Todo:
clean up old base

Definition at line 818 of file Thread.cc.

References getTlsBase(), Processor::information(), m_bTlsBaseOverride, m_pTlsBase, and Processor::setTlsBase().

void Thread::setUnwindState ( UnwindType  ut)
inline

Sets the above unwind state.

Definition at line 266 of file Thread.h.

Referenced by Semaphore::acquireWithResult(), and PosixSubsystem::exit().

+ Here is the caller graph for this function:

void Thread::shutdown ( )

Performs termination steps on the thread, while the thread is still able to reschedule. Required as ~Thread() is called in a context where the thread has been removed from the scheduler, and triggering a reschedule may add the thread back to the ready queue by accident.

Todo:
identify a way to make cleanup work here.

Definition at line 234 of file Thread.cc.

References Spinlock::acquire(), Scheduler::addThread(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::count(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), ERROR, getLock(), RequestQueue::halt(), Processor::information(), Scheduler::instance(), RequestQueue::isRequestValid(), m_bDetached, m_bRemovingRequests, m_ConcurrencyLock, m_PendingRequests, m_pWaiter, m_Status, Spinlock::release(), Semaphore::release(), Scheduler::removeThread(), reportWakeup(), RequestQueue::resume(), setStatus(), and Scheduler::yield().

Referenced by PerProcessorScheduler::killCurrentThread(), Process::~Process(), and ~Thread().

+ Here is the caller graph for this function:

SchedulerState & Thread::state ( )

Returns a reference to the Thread's saved context. This function is intended only for use by the Scheduler.

Definition at line 420 of file Thread.cc.

References m_nStateLevel, and Thread::StateLevel::m_State.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::eventHandlerReturned(), NMFaultHandler::interrupt(), PosixSubsystem::invoke(), PerProcessorScheduler::killCurrentThread(), NMFaultHandler::NMFaultHandler(), PerProcessorScheduler::schedule(), and setInterruptible().

+ Here is the caller graph for this function:

void Thread::threadExited ( )
static

Sets the exit code of the Thread and sets the state to Zombie, if it is being waited on; if it is not being waited on the Thread is destroyed.

Note
This is meant to be called only by the thread trampoline - this is the only reason it is public. It should NOT be called by anyone else!

Definition at line 479 of file Thread.cc.

References Processor::information().

void Thread::unexpectedExit ( )

An unexpected exit has occurred, perform cleanup

Definition at line 754 of file Thread.cc.

Referenced by PosixSubsystem::exit().

+ Here is the caller graph for this function:

bool Thread::wasInterrupted ( )
inline

Returns whether the thread was just interrupted deliberately (e.g. because of a timeout).

Definition at line 229 of file Thread.h.

Referenced by Semaphore::acquireWithResult(), RequestQueue::addRequest(), join(), and ConditionVariable::wait().

+ Here is the caller graph for this function:

Member Data Documentation

bool Thread::m_bDetached = false
private

Whether this thread has been detached or not.

Definition at line 577 of file Thread.h.

Referenced by detach(), join(), and shutdown().

bool Thread::m_bInterrupted = false
private

Whether the thread was interrupted deliberately.

See also
Thread::wasInterrupted

Definition at line 567 of file Thread.h.

bool Thread::m_bInterruptible = true
private

Whether this thread has been marked interruptible or not.

Definition at line 580 of file Thread.h.

Referenced by getNextEvent(), isInterruptible(), sendEvent(), and setInterruptible().

bool Thread::m_bRemovingRequests = false
private

Are we in the process of removing tracked RequestQueue::Request objects?

Definition at line 574 of file Thread.h.

Referenced by addRequest(), removeRequest(), shutdown(), and ~Thread().

bool Thread::m_bTlsBaseOverride = false
private

Whether or not userspace has overridden its TLS base.

Definition at line 570 of file Thread.h.

Referenced by resetTlsBase(), setTlsBase(), Thread(), and ~Thread().

Spinlock Thread::m_ConcurrencyLock
private

General concurrency lock, not touched by schedulers.

Definition at line 540 of file Thread.h.

Referenced by detach(), join(), and shutdown().

DebugState Thread::m_DebugState = None
private

Debug state - a higher level state information for display in the debugger for debugging races and deadlocks.

Definition at line 561 of file Thread.h.

uintptr_t Thread::m_DebugStateAddress = 0
private

Address to supplement the DebugState information

Definition at line 516 of file Thread.h.

size_t Thread::m_Errno = 0
private

The number of the last error to occur.

Definition at line 513 of file Thread.h.

List<Event *> Thread::m_EventQueue
private

Queue of Events ready to run.

Definition at line 543 of file Thread.h.

Referenced by cullEvent(), getNextEvent(), hasEvent(), sendEvent(), and setStatus().

int Thread::m_ExitCode = 0
private

Our exit code.

Definition at line 557 of file Thread.h.

size_t Thread::m_Id = 0
private

Our thread ID.

Definition at line 510 of file Thread.h.

Referenced by Process::getId(), getTlsBase(), and Thread().

Spinlock Thread::m_Lock
private
size_t Thread::m_nStateLevel = 0
private

The current index into m_States (head of the state stack).

Definition at line 499 of file Thread.h.

Referenced by getKernelStack(), getNextEvent(), getStateLevel(), inhibitEvent(), popState(), pushState(), setKernelStack(), and state().

void* Thread::m_pAllocatedStack = nullptr
private

The stack that we allocated from the VMM. This may or may not also be the kernel stack - depends on whether we are a user or kernel mode thread. This is used solely for housekeeping/cleaning up purposes.

Definition at line 507 of file Thread.h.

Referenced by Thread().

List<RequestQueue::Request *> Thread::m_PendingRequests
private

List of requests pending on this Thread

Definition at line 546 of file Thread.h.

Referenced by addRequest(), removeRequest(), and shutdown().

Process* Thread::m_pParent = nullptr
private

Our parent process.

Definition at line 502 of file Thread.h.

Referenced by cleanStateLevel(), Process::getParent(), getTlsBase(), setStatus(), Thread(), and ~Thread().

size_t Thread::m_Priority = DEFAULT_PRIORITY
private

Thread priority: 0..MAX_PRIORITIES-1, 0 being highest.

Definition at line 521 of file Thread.h.

void* Thread::m_pTlsBase = nullptr
private

Memory mapping for the TLS base of this thread (userspace-only)

Definition at line 524 of file Thread.h.

Referenced by getTlsBase(), resetTlsBase(), setTlsBase(), Thread(), and ~Thread().

Thread* Thread::m_pWaiter = nullptr
private

Waiters on this thread.

Definition at line 534 of file Thread.h.

Referenced by detach(), join(), and shutdown().

volatile Status Thread::m_Status = Ready
private

Our current status.

Definition at line 554 of file Thread.h.

Referenced by detach(), join(), sendEvent(), setStatus(), shutdown(), and Thread().

List<WakeReason *> Thread::m_WakeWatchers
private

List of wakeup watchers that need to be informed when we wake up.

Definition at line 549 of file Thread.h.

Referenced by addWakeupWatcher(), removeWakeupWatcher(), and reportWakeup().


The documentation for this class was generated from the following files: