42static_assert(
sizeof(
void*) >= 4,
"not tested on <32bit systems");
85#define DEBUG_PROCESS(n) DEBUG_PROCESS_f(n)
92[[gnu::noinline]]
static void DEBUG_PROCESS_f(
int n) {
128#define DEBUG_PROCESS(n)
138#define PROCESS_INTERRUPT() \
141 this->_status = _INTERRUPTED; \
142 PROCESS_INTERRUPT_f(); \
143 this->_status = _RUNNING; \
144 this->_context = 0; \
148#define PROCESS_EXIT() \
149 longjmp(P_DispatcherStatusBuffer, 2)
159}
catch(std::bad_alloc&) {
174 Dprintf((
"Process::Process(%d)", p));
187 Dprintf((
"Process::~Process()"));
192 delete []
static_cast<char*
>(
_context);
316 Dprintf((
"Process#%lu.Passivate()",
id()));
352#define CANARY1 (reinterpret_cast<long>(this)-1)
358#define MAX_PROCESS_STACK_SIZE 1000000UL
360[[noreturn,gnu::noinline]]
static void restore_context2(
volatile char *)
noexcept;
415 static const char * status_strings[] = {
416 "unknown",
"PREPARED",
"RUNNING",
"INTERRUPTED",
"TERMINATED"
424 volatile long mylocal =
CANARY1;
445# define STACK_RESERVED 0x080
463 static char *P_StackBase0=0;
467 SIMLIB_error(
"Internal error: P_StackBase not constant");
481 SIMLIB_error(
"Process canary1 died after Behavior() return");
519 DEBUG(
DBG_PROCESS,(
"| --- Process::Behavior() INTERRUPT %p.context=%p, size=%d", \
525 Dprintf((
"%016p===Process#%lu._Run() RETURN status=%s",
this,
_Ident, status_strings[
_status]));
538#define CANARY2 0xDEADBEEFUL
564 volatile unsigned mylocal2 =
CANARY2;
abstract base class for active entities (Process, Event) instances of derived classes provide Behavio...
EntityPriority_t Priority_t
bool Idle()
entity activation is not scheduled in calendar
void Activate()
activate now
virtual void Out() override
remove entity from queue
virtual void Passivate()
deactivation
unsigned long _Ident
unique identification number of entity
(SOL-like) facility Facility with exclusive access and service priority
virtual void Seize(Entity *e, ServicePriority_t sp=DEFAULT_PRIORITY)
virtual void Release(Entity *e)
List * Where()
where is linked
void Leave(Store &s, unsigned long ReqCap=1)
return some capacity
virtual void Terminate() override
kill process
virtual void Wait(double dtime)
wait for dtime interval
void Release(Facility &f)
release facility
void Activate()
activate now
void Seize(Facility &f, ServicePriority_t sp=0)
seize facility
bool isTerminated() const
virtual void Into(Queue &q)
insert process into queue
virtual void Passivate() override
process deactivation (sleep)
virtual void _Run() noexcept override
Process dispatch method.
enum simlib3::Process::ProcessStatus_t _status
void Enter(Store &s, unsigned long ReqCap=1)
acquire some capacity
void * _context
process context pointer
Process(Priority_t p=DEFAULT_PRIORITY)
Process constructor sets state to PREPARED.
void Interrupt()
test of WaitUntil list, allow running others
virtual void Behavior()=0
behavior description
virtual std::string Name() const override
name of object
virtual ~Process()
Process destructor Sets state to TERMINATED and removes process from queue/calendar/waituntil list.
virtual void Insert(Entity *e)
virtual std::string Name() const
get object name
(SOL-like) store store capacity can be changed dynamically
virtual void Leave(unsigned long rcap)
deallocate capacity
virtual void Enter(Entity *e, unsigned long rcap)
allocate capacity
Internal header file for SIMLIB/C++.
void Get(Entity *e)
remove selected entity activation record from calendar
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
const double & Time
model time (is NOT the block)
static char *volatile P_StackBase
global start of stack area
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
static void restore_context2(volatile char *) noexcept
This function overwrites stack contents. It never returns, see longjmp.
static jmp_buf P_DispatcherStatusBuffer
setjmp() state before dispatch
static volatile size_t P_StackSize
temporary global stack size
std::string SIMLIB_create_tmp_name(const char *fmt,...)
printf-like function to create temporary name (the length of temporary names is limited) used only ...
static P_Context_t *volatile P_Context
temporary global process state
unsigned char ServicePriority_t
Service priority (see Facility::Seize)
static char *volatile P_StackBase2
used for checking only
static void ALLOC_CONTEXT(size_t sz) noexcept
static void FREE_CONTEXT() noexcept
deallocate saved process context
void SIMLIB_warning(const enum _ErrEnum N)
print warning message and continue
static void PROCESS_INTERRUPT_f()
Special function called from Process::Behavior() directly or indirectly.
static void restore_context(size_t data_size) noexcept
This elliminates the need for explicit stack pointer adjustment.
#define PROCESS_EXIT()
does not save context
#define MAX_PROCESS_STACK_SIZE
This is theoretical max stack size for single SIMLIB Process at time of interruption (should never be...
#define PROCESS_INTERRUPT()
interrupt process behavior execution, continue after return
Main SIMLIB/C++ interface.
internal structure for storing of Process::Behavior() context
size_t size
size of following array (allocated on heap)
jmp_buf status
stored SP, IP, and other registers
char stack[1]
saved stack contents