SIMLIB/C++
3.07
|
Abstract base class for all simulation processesProcess behavior is specified by Behavior method and can be interrupted during execution by e.g. More...
#include <simlib.h>
Public Member Functions | |
Process (Priority_t p=DEFAULT_PRIORITY) | |
Process constructor sets state to PREPARED. More... | |
virtual | ~Process () |
Process destructor Sets status to TERMINATED and removes process from queue/calendar/waituntil list. More... | |
virtual void | Behavior ()=0 |
behavior description More... | |
virtual void | Output () const override |
print object to default output More... | |
virtual std::string | Name () const override |
name of object More... | |
virtual void | Activate (double t) override |
activate at time t (schedule) More... | |
virtual void | Passivate () override |
process deactivation (sleep) More... | |
virtual void | Wait (double dtime) |
wait for dtime interval More... | |
bool | _WaitUntil (bool test) |
wait for condition (slow!) More... | |
void | Interrupt () |
test of WaitUntil list, allow running others More... | |
virtual void | Terminate () override |
kill process More... | |
void | Seize (Facility &f, ServicePriority_t sp=0) |
seize facility More... | |
void | Release (Facility &f) |
release facility More... | |
void | Enter (Store &s, unsigned long ReqCap=1) |
acquire some capacity More... | |
void | Leave (Store &s, unsigned long ReqCap=1) |
return some capacity More... | |
virtual void | Into (Queue &q) |
insert process into queue More... | |
![]() | |
unsigned long | id () const |
Entity (Priority_t p=DEFAULT_PRIORITY) | |
constructor More... | |
virtual | ~Entity () |
destructor More... | |
operator Entity * () | |
double | ActivationTime () |
get activation time of entity - iff scheduled it is here, because Entity has no knowledge of calendar activation record structure More... | |
void | Activate () |
activate now More... | |
bool | Idle () |
entity activation is not scheduled in calendar More... | |
void | Cancel () |
end Behavior() and remove entity More... | |
virtual void | Out () override |
remove entity from queue More... | |
EventNotice * | GetEventNotice () |
![]() | |
Link () | |
virtual | ~Link () |
virtual void | Into (List *l) |
insert last More... | |
List * | Where () |
where is linked More... | |
virtual bool | isInQueue () |
present in queue More... | |
![]() | |
bool | TestAndSetFlag (bool new_value, unsigned n) |
internal method for flag manipulation is used for algebraic loop checking in continuous blocks More... | |
SimObject () | |
constructor More... | |
virtual | ~SimObject () |
virtual destructor More... | |
void * | operator new (size_t size) |
allocate object, set _flags More... | |
void | operator delete (void *ptr) |
deallocate object More... | |
void * | operator new[] (size_t size)=delete |
void | operator delete[] (void *ptr)=delete |
bool | isAllocated () const |
bool | HasName () const |
void | SetName (const std::string &name) |
assign the name More... | |
Private Types | |
enum | ProcessStatus_t { _PREPARED =1, _RUNNING, _INTERRUPTED, _TERMINATED } |
possible process status values More... | |
Private Member Functions | |
virtual void | _Run () noexcept override |
Process dispatch method. More... | |
bool | isPrepared () const |
bool | isCurrent () const |
bool | isInterrupted () const |
bool | isTerminated () const |
void | _WaitUntilRemove () |
Private Attributes | |
void * | _context |
process context pointer More... | |
enum simlib3::Process::ProcessStatus_t | _status |
bool | _wait_until |
Friends | |
class | WaitUntilList |
Additional Inherited Members | |
![]() | |
typedef EntityPriority_t | Priority_t |
![]() | |
enum | _Flags { _CLEAR_ALL_FLAGS = 0, _ALLOCATED_FLAG = 1<<0, _EVAL_FLAG = 1<<1, _HAS_NAME_FLAG = 1<<2 } |
![]() | |
Priority_t | Priority |
priority of the entity (scheduling,queues) More... | |
![]() | |
Link (Link *p, Link *s, List *h) | |
![]() | |
unsigned long | _Ident |
unique identification number of entity More... | |
double | _MarkTime |
union { | |
double _RemainingTime | |
unsigned long _RequiredCapacity | |
}; | |
ServicePriority_t | _SPrio |
priority of service in Facility More... | |
![]() | |
unsigned | _flags |
bool flags for internal use (TODO bitfield?) More... | |
![]() | |
static unsigned long | _Number = 0L |
current number of entities More... | |
Abstract base class for all simulation processes
Process behavior is specified by Behavior method and can be interrupted during execution by e.g.
Wait method call (it is coroutine)
|
private |
simlib3::Process::Process | ( | Priority_t | p = DEFAULT_PRIORITY | ) |
Process constructor sets state to PREPARED.
Definition at line 250 of file process.cc.
References _context, _PREPARED, _status, _wait_until, and Dprintf.
|
virtual |
Process destructor Sets status to TERMINATED and removes process from queue/calendar/waituntil list.
TODO: Warn if this==Current? (e.g. "delete this;" in Behavior())
Definition at line 262 of file process.cc.
References _context, _status, _TERMINATED, _wait_until, _WaitUntilRemove(), Dprintf, simlib3::SQS::Get(), simlib3::Entity::Idle(), simlib3::Entity::Out(), and simlib3::Link::Where().
|
overrideprivatevirtualnoexcept |
Process dispatch method.
The dispatcher starts/reactivates process behavior
IMPORTANT notes:
This function: 1) marks current position on stack 2) marks current CPU context 3) calls Behavior() 4) after interruption of Behavior() returns 5) if called next time, do 1), 2) and move stack pointer (SP) 6) copy saved stack content back 7) do longjmp() to restore Behavior() execution
Implements simlib3::Entity.
Definition at line 455 of file process.cc.
References _context, simlib3::Entity::_Ident, _INTERRUPTED, _PREPARED, _RUNNING, _status, _TERMINATED, Behavior(), CANARY1, DBG_THREAD, DEBUG, Dprintf, simlib3::SQS::Get(), simlib3::Entity::Idle(), simlib3::SimObject::isAllocated(), isTerminated(), simlib3::Entity::Out(), simlib3::P_Context, simlib3::P_StackBase, simlib3::P_StackSize, simlib3::ProcessNotInitialized, simlib3::SIMLIB_error(), simlib3::P_Context_t::size, simlib3::P_Context_t::stack, STACK_RESERVED, simlib3::P_Context_t::status, THREAD_DEBUG, and simlib3::Link::Where().
bool simlib3::Process::_WaitUntil | ( | bool | test | ) |
wait for condition (slow!)
Definition at line 123 of file waitunti.cc.
References Dprintf, simlib3::WaitUntilList::GetCurrent(), simlib3::WaitUntilList::InsertCurrent(), simlib3::Passivate(), simlib3::SIMLIB_Current, and SIMLIB_internal_error.
|
private |
Definition at line 142 of file waitunti.cc.
References simlib3::WaitUntilList::Remove().
Referenced by simlib3::WaitUntilList::clear(), and ~Process().
|
overridevirtual |
activate at time t (schedule)
Activate process at time t.
Reimplemented from simlib3::Entity.
Definition at line 323 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), and THREAD_INTERRUPT.
Referenced by main().
|
pure virtual |
void simlib3::Process::Enter | ( | Store & | s, |
unsigned long | ReqCap = 1 |
||
) |
acquire some capacity
Enter - use cap capacity of store s possibly waiting in input queue, if not enough free capacity.
Definition at line 363 of file process.cc.
References simlib3::Store::Enter().
void simlib3::Process::Interrupt | ( | ) |
test of WaitUntil list, allow running others
Interrupt process behavior - this ensures WaitUntil tests WARNING: use with care - it can run higher (or equal) priority processes before continuing.
Definition at line 308 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), and THREAD_INTERRUPT.
|
virtual |
insert process into queue
insert current process into queue The process can be at most in single queue.
Definition at line 380 of file process.cc.
References simlib3::Queue::Insert(), simlib3::Entity::Out(), simlib3::SIMLIB_warning(), and simlib3::Link::Where().
|
inlineprivate |
Definition at line 449 of file simlib.h.
Referenced by Activate(), Interrupt(), Passivate(), Terminate(), and Wait().
|
inlineprivate |
|
inlineprivate |
void simlib3::Process::Leave | ( | Store & | s, |
unsigned long | ReqCap = 1 |
||
) |
return some capacity
Leave - return cap capacity of store s and enter first waiting entity from queue, which can use free capacity.
Definition at line 372 of file process.cc.
References simlib3::Store::Leave().
|
overridevirtual |
name of object
Name of the process warning: uses static buffer for generic names TODO: use std::string.
Reimplemented from simlib3::SimObject.
Definition at line 294 of file process.cc.
References simlib3::Entity::_Ident, simlib3::SimObject::Name(), and simlib3::SIMLIB_create_tmp_name().
|
overridevirtual |
print object to default output
Reimplemented from simlib3::SimObject.
Definition at line 108 of file output2.cc.
References simlib3::SimObject::Name(), and simlib3::Print().
|
overridevirtual |
process deactivation (sleep)
Process deactivation To continue the behavior it should be activated again Warning: memory leak if not activated/deleted.
Reimplemented from simlib3::Entity.
Definition at line 393 of file process.cc.
References Dprintf, isCurrent(), simlib3::Entity::Passivate(), and THREAD_INTERRUPT.
void simlib3::Process::Release | ( | Facility & | f | ) |
release facility
Release facility f possibly activate first waiting entity in queue.
Definition at line 355 of file process.cc.
References simlib3::Facility::Release().
void simlib3::Process::Seize | ( | Facility & | f, |
ServicePriority_t | sp = 0 |
||
) |
seize facility
Seize facility f with optional priority of service sp possibly waiting in input queue, if it is busy.
Definition at line 347 of file process.cc.
References simlib3::Facility::Seize().
|
overridevirtual |
kill process
Terminate the process if called by current process, self-destruct free memory of the process.
Implements simlib3::Entity.
Definition at line 406 of file process.cc.
References simlib3::Entity::_Ident, _status, _TERMINATED, Dprintf, simlib3::SQS::Get(), simlib3::Entity::Idle(), simlib3::SimObject::isAllocated(), isCurrent(), simlib3::Entity::Out(), THREAD_EXIT, and simlib3::Link::Where().
|
virtual |
wait for dtime interval
Wait for dtime.
Definition at line 335 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), THREAD_INTERRUPT, and simlib3::Time.
|
friend |
|
private |
process context pointer
Definition at line 441 of file simlib.h.
Referenced by _Run(), Process(), and ~Process().
|
private |
Referenced by _Run(), Process(), Terminate(), and ~Process().
|
private |
Definition at line 454 of file simlib.h.
Referenced by Process(), and ~Process().