|
SIMLIB/C++ 3.09
|
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. | |
| virtual | ~Process () |
| Process destructor Sets state to TERMINATED and removes process from queue/calendar/waituntil list. | |
| virtual void | Behavior ()=0 |
| behavior description | |
| virtual void | Output () const override |
| print object to default output | |
| virtual std::string | Name () const override |
| name of object | |
| virtual void | Activate (double t) override |
| activate at time t (schedule) | |
| virtual void | Passivate () override |
| process deactivation (sleep) | |
| virtual void | Wait (double dtime) |
| wait for dtime interval | |
| bool | _WaitUntil (bool test) |
| wait for condition (slow!) | |
| void | Interrupt () |
| test of WaitUntil list, allow running others | |
| virtual void | Terminate () override |
| kill process | |
| void | Seize (Facility &f, ServicePriority_t sp=0) |
| seize facility | |
| void | Release (Facility &f) |
| release facility | |
| void | Enter (Store &s, unsigned long ReqCap=1) |
| acquire some capacity | |
| void | Leave (Store &s, unsigned long ReqCap=1) |
| return some capacity | |
| virtual void | Into (Queue &q) |
| insert process into queue | |
| void | Activate () |
| activate now | |
| virtual void | Activate (double t) |
| activate at time t (schedule) | |
Public Member Functions inherited from simlib3::Entity | |
| unsigned long | id () const |
| Entity (Priority_t p=DEFAULT_PRIORITY) | |
| constructor | |
| virtual | ~Entity () |
| destructor | |
| operator Entity * () | |
| double | ActivationTime () |
| get activation time of entity - iff scheduled it is here, because Entity has no knowledge of calendar activation record structure | |
| void | Activate () |
| activate now | |
| virtual void | Activate (double t) |
| activate at time t (schedule) | |
| virtual void | Passivate () |
| deactivation | |
| virtual void | Terminate ()=0 |
| end Behavior() and remove entity | |
| bool | Idle () |
| entity activation is not scheduled in calendar | |
| void | Cancel () |
| end Behavior() and remove entity | |
| virtual void | Out () override |
| remove entity from queue | |
| EventNotice * | GetEventNotice () |
Public Member Functions inherited from simlib3::Link | |
| Link () | |
| virtual | ~Link () |
| virtual void | Into (List *l) |
| insert last | |
| virtual void | Out () |
| remove from list | |
| List * | Where () |
| where is linked | |
| virtual bool | isInQueue () |
| present in queue | |
Public Member Functions inherited from simlib3::SimObject | |
| bool | TestAndSetFlag (bool new_value, unsigned n) |
| internal method for flag manipulation is used for algebraic loop checking in continuous blocks | |
| SimObject () | |
| constructor | |
| virtual | ~SimObject () |
| virtual destructor | |
| void * | operator new (size_t size) |
| allocate object, set _flags | |
| void | operator delete (void *ptr) |
| deallocate object | |
| void * | operator new[] (size_t size)=delete |
| void | operator delete[] (void *ptr)=delete |
| bool | isAllocated () const |
| virtual std::string | Name () const |
| get object name | |
| bool | HasName () const |
| void | SetName (const std::string &name) |
| assign the name | |
| virtual void | Output () const |
| print object to default output | |
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. | |
| bool | isPrepared () const |
| bool | isCurrent () const |
| bool | isInterrupted () const |
| bool | isTerminated () const |
| void | _WaitUntilRemove () |
Private Attributes | |
| void * | _context |
| process context pointer | |
| enum simlib3::Process::ProcessStatus_t | _status |
| bool | _wait_until |
Friends | |
| class | WaitUntilList |
Additional Inherited Members | |
Public Types inherited from simlib3::Entity | |
| typedef EntityPriority_t | Priority_t |
Public Types inherited from simlib3::SimObject | |
| enum | _Flags { _CLEAR_ALL_FLAGS = 0 , _ALLOCATED_FLAG = 1<<0 , _EVAL_FLAG = 1<<1 , _HAS_NAME_FLAG = 1<<2 } |
Public Attributes inherited from simlib3::Entity | |
| Priority_t | Priority |
| priority of the entity (scheduling,queues) | |
Protected Member Functions inherited from simlib3::Link | |
| Link (Link *p, Link *s, List *h) | |
Protected Attributes inherited from simlib3::Entity | |
| unsigned long | _Ident |
| unique identification number of entity | |
| double | _MarkTime |
| union { | |
| double _RemainingTime | |
| unsigned long _RequiredCapacity | |
| }; | |
| ServicePriority_t | _SPrio |
| priority of service in Facility | |
Protected Attributes inherited from simlib3::SimObject | |
| unsigned | _flags |
| bool flags for internal use (TODO bitfield?) | |
Static Protected Attributes inherited from simlib3::Entity | |
| static unsigned long | _Number = 0L |
| current number of entities | |
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 a coroutine)
|
private |
| simlib3::Process::Process | ( | Priority_t | p = DEFAULT_PRIORITY | ) |
Process constructor sets state to PREPARED.
Definition at line 173 of file process.cc.
References _context, _PREPARED, _status, _wait_until, and Dprintf.
|
virtual |
Process destructor Sets state to TERMINATED and removes process from queue/calendar/waituntil list.
TODO: Warn if this==Current? (e.g. "delete this;" in Behavior())
Definition at line 185 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() method
IMPORTANT notes:
This function: 1) saves current context (position on stack and CPU registers) 2) calls Behavior() like any other function 3) interruption of Behavior() saves context+ and jumps back 4) to continue Behavior(), do 1) and move stack pointer away 5) copy saved stack content back to stack 6) do longjmp() to restore Behavior() execution
Implements simlib3::Entity.
Definition at line 412 of file process.cc.
References _context, simlib3::Entity::_Ident, _INTERRUPTED, _PREPARED, _RUNNING, _status, _TERMINATED, Behavior(), CANARY1, DBG_PROCESS, DEBUG, Dprintf, simlib3::SQS::Get(), simlib3::Entity::Idle(), simlib3::SimObject::isAllocated(), isTerminated(), simlib3::Entity::Out(), simlib3::P_Context, simlib3::P_DispatcherStatusBuffer, simlib3::P_StackBase, simlib3::P_StackBase2, simlib3::P_StackSize, ProcessNotInitialized, simlib3::restore_context(), simlib3::SIMLIB_error(), simlib3::P_Context_t::size, STACK_RESERVED, and simlib3::Link::Where().
| bool simlib3::Process::_WaitUntil | ( | bool | test | ) |
wait for condition (slow!)
Definition at line 123 of file waitunti.cc.
References _wait_until, Dprintf, simlib3::WaitUntilList::GetCurrent(), simlib3::WaitUntilList::InsertCurrent(), Passivate(), simlib3::SIMLIB_Current, and SIMLIB_internal_error.
|
private |
Definition at line 142 of file waitunti.cc.
References _wait_until, and simlib3::WaitUntilList::Remove().
Referenced by simlib3::WaitUntilList::clear(), and ~Process().
|
virtual |
|
overridevirtual |
activate at time t (schedule)
Activate process at time t.
Reimplemented from simlib3::Entity.
Definition at line 244 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), PROCESS_INTERRUPT, and t.
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 284 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 TODO: Works almost like Wait(0), used only with WaitUntil.
Definition at line 229 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), and PROCESS_INTERRUPT.
|
virtual |
insert process into queue
Insert current process into queue The process can be at most in single queue.
Moves if in other queue.
Definition at line 301 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.
References _RUNNING, and _status.
Referenced by Activate(), Interrupt(), Output(), Passivate(), Terminate(), and Wait().
|
inlineprivate |
Definition at line 450 of file simlib.h.
References _INTERRUPTED, and _status.
|
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 292 of file process.cc.
References simlib3::Store::Leave().
|
overridevirtual |
name of object
Name of the process Each process can be named, default is "Process#<number>".
Reimplemented from simlib3::SimObject.
Definition at line 214 of file process.cc.
References simlib3::Entity::_Ident, simlib3::SimObject::Name(), and simlib3::SIMLIB_create_tmp_name().
Referenced by Output().
|
overridevirtual |
print object to default output
Reimplemented from simlib3::SimObject.
Definition at line 108 of file output2.cc.
References isCurrent(), 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 explicitly (FIXME)
Reimplemented from simlib3::Entity.
Definition at line 314 of file process.cc.
References Dprintf, isCurrent(), simlib3::Entity::Passivate(), and PROCESS_INTERRUPT.
Referenced by _WaitUntil().
| void simlib3::Process::Release | ( | Facility & | f | ) |
release facility
Release facility f possibly activate first waiting entity in queue.
Definition at line 276 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 268 of file process.cc.
References simlib3::Facility::Seize().
|
overridevirtual |
kill process
Terminate the process If called by current process, self-destruct.
Remove from queue, unschedule from calendar. Automatically free the memory of the process.
Implements simlib3::Entity.
Definition at line 328 of file process.cc.
References simlib3::Entity::_Ident, _status, _TERMINATED, Dprintf, simlib3::SQS::Get(), simlib3::Entity::Idle(), simlib3::SimObject::isAllocated(), isCurrent(), simlib3::Entity::Out(), PROCESS_EXIT, and simlib3::Link::Where().
|
virtual |
wait for dtime interval
Wait for dtime The same as Activate(Time+dtime)
Definition at line 256 of file process.cc.
References simlib3::Entity::_Ident, simlib3::Entity::Activate(), Dprintf, isCurrent(), PROCESS_INTERRUPT, and simlib3::Time.
Referenced by TestProcess::Behavior().
|
friend |
|
private |
process context pointer
Definition at line 441 of file simlib.h.
Referenced by _Run(), Process(), and ~Process().
|
private |
Referenced by _Run(), isCurrent(), isInterrupted(), isPrepared(), isTerminated(), Process(), Terminate(), and ~Process().
|
private |
Definition at line 454 of file simlib.h.
Referenced by _WaitUntil(), _WaitUntilRemove(), Process(), and ~Process().