SIMLIB/C++  3.07
Classes | Namespaces | Macros | Functions | Variables
process.cc File Reference

Implementation of quasiparallel processes (coroutines) More...

#include "simlib.h"
#include "internal.h"
#include <csetjmp>
#include <cstring>
Include dependency graph for process.cc:

Go to the source code of this file.

Classes

struct  simlib3::P_Context_t
 internal structure for storing of process context More...
 

Namespaces

 simlib3
 Implementation of class CalendarList
interface is static - using global functions in SQS namespace.
 

Macros

#define EXTRA_DEBUG   0
 
#define THREAD_DEBUG(n)
 
#define THREAD_INTERRUPT()
 interrupt process behavior execution, continue after return More...
 
#define THREAD_EXIT()   longjmp(P_DispatcherStatusBuffer, 2)
 does not save context More...
 
#define ALLOC_CONTEXT(sz)
 allocate memory for process context, sz = size of stack area to save More...
 
#define CANARY1   (reinterpret_cast<long>(this)+1)
 
#define STACK_RESERVED   0x080
 
#define CANARY2   0xDEADBEEFUL
 

Functions

static void simlib3::THREAD_INTERRUPT_f () __attribute__((noinline))
 Special function called from Process::Behavior() directly or indirectly. More...
 
static void simlib3::FREE_CONTEXT () __attribute__((noinline))
 non-inline function for deallocating saved process context More...
 

Variables

static jmp_buf simlib3::P_DispatcherStatusBuffer
 setjmp() state before dispatch More...
 
static char *volatile simlib3::P_StackBase = 0
 global start of stack area More...
 
static char *volatile simlib3::P_StackBase2 = 0
 for checking start of stack More...
 
static P_Context_t *volatile simlib3::P_Context = 0
 temporary global process state More...
 
static volatile size_t simlib3::P_StackSize = 0
 temporary global stack size More...
 

Detailed Description

Implementation of quasiparallel processes (coroutines)

This module contains implementation of cooperative multitasking processes for discrete simulation

Definition in file process.cc.

Macro Definition Documentation

◆ ALLOC_CONTEXT

#define ALLOC_CONTEXT (   sz)
Value:
P_Context = (P_Context_t *) new char[sizeof(P_Context_t) + sz]; \
P_Context->size = sz;
size_t size
size of following array (allocated on heap)
Definition: process.cc:122
internal structure for storing of process context
Definition: process.cc:120
static P_Context_t *volatile P_Context
temporary global process state
Definition: process.cc:132

allocate memory for process context, sz = size of stack area to save

Definition at line 226 of file process.cc.

Referenced by simlib3::THREAD_INTERRUPT_f().

◆ CANARY1

#define CANARY1   (reinterpret_cast<long>(this)+1)

Definition at line 430 of file process.cc.

Referenced by simlib3::Process::_Run().

◆ CANARY2

#define CANARY2   0xDEADBEEFUL

Definition at line 582 of file process.cc.

Referenced by simlib3::THREAD_INTERRUPT_f().

◆ EXTRA_DEBUG

#define EXTRA_DEBUG   0

Definition at line 139 of file process.cc.

◆ STACK_RESERVED

#define STACK_RESERVED   0x080

Referenced by simlib3::Process::_Run().

◆ THREAD_DEBUG

#define THREAD_DEBUG (   n)

Definition at line 199 of file process.cc.

Referenced by simlib3::Process::_Run(), and simlib3::THREAD_INTERRUPT_f().

◆ THREAD_EXIT

#define THREAD_EXIT ( )    longjmp(P_DispatcherStatusBuffer, 2)

does not save context

Definition at line 219 of file process.cc.

Referenced by simlib3::Process::Terminate().

◆ THREAD_INTERRUPT

#define THREAD_INTERRUPT ( )
Value:
{ /* This should be MACRO */ \
/* if(!isCurrent()) SIMLIB_error("Can't interrupt..."); */ \
this->_status = _INTERRUPTED; \
THREAD_INTERRUPT_f(); \
this->_status = _RUNNING; \
this->_context = 0; \
}

interrupt process behavior execution, continue after return

Definition at line 209 of file process.cc.

Referenced by simlib3::Process::Activate(), simlib3::Process::Interrupt(), simlib3::Process::Passivate(), and simlib3::Process::Wait().