scc 2025.09
SystemC components library
scc::ordered_semaphore Class Reference

The ordered_semaphore primitive channel class. More...

#include <ordered_semaphore.h>

Inheritance diagram for scc::ordered_semaphore:
Collaboration diagram for scc::ordered_semaphore:

Classes

struct  lock
 a lock for the semaphore More...

Public Member Functions

 ordered_semaphore (unsigned init_value=1)
 constructor of an un-named semaphore
 ordered_semaphore (const char *name, unsigned init_value=1, bool value_traceable=false)
 ordered_semaphore (const ordered_semaphore &)=delete
ordered_semaphoreoperator= (const ordered_semaphore &)=delete
int wait () override
 lock (take) the semaphore, block if not available
int wait (unsigned priority)
int trywait () override
 lock (take) the semaphore, return -1 if not available
int post () override
 unlock (give) the semaphore
unsigned get_capacity ()
 retrieve the initial capacity of the semaphore
void set_capacity (unsigned capacity)
 change the capacity
int get_value () const override
 get the value of the semaphore
const char * kind () const override
 kind of this SastemC object
void trace (sc_core::sc_trace_file *tf) const override
 adds internal variables to trace
bool is_trace_enabled () const override
 returns of this component shall be traced

Protected Member Functions

bool in_use ()
void report_error (const char *id, const char *add_msg=0) const

Protected Attributes

sc_core::sc_event free_evt
int value
unsigned capacity
bool value_traceable = false
std::unique_ptr< scc::sc_ref_variable< int > > value_ref
std::array< std::deque< sc_core::sc_process_handle >, 2 > queue

Detailed Description

The ordered_semaphore primitive channel class.

The ordered semaphore acts like an ordinary semaphore. It gives the guarantee that access is granted in the order of arrival (FCFS)

Definition at line 45 of file ordered_semaphore.h.

Constructor & Destructor Documentation

◆ ordered_semaphore() [1/2]

scc::ordered_semaphore::ordered_semaphore ( unsigned init_value = 1)
explicit

constructor of an un-named semaphore

If the initial value is 0 the semaphore has an unlimited capacity but is initially empty

Parameters
init_valueinitial capacity of the semaphore

Definition at line 65 of file ordered_semaphore.cpp.

◆ ordered_semaphore() [2/2]

scc::ordered_semaphore::ordered_semaphore ( const char * name,
unsigned init_value = 1,
bool value_traceable = false )

Definition at line 75 of file ordered_semaphore.cpp.

Member Function Documentation

◆ get_capacity()

unsigned scc::ordered_semaphore::get_capacity ( )
inline

retrieve the initial capacity of the semaphore

Definition at line 102 of file ordered_semaphore.h.

◆ get_value()

int scc::ordered_semaphore::get_value ( ) const
inlineoverride

get the value of the semaphore

Returns
current value

Definition at line 116 of file ordered_semaphore.h.

◆ in_use()

bool scc::ordered_semaphore::in_use ( )
inlineprotected

Definition at line 184 of file ordered_semaphore.h.

◆ is_trace_enabled()

bool scc::ordered_semaphore::is_trace_enabled ( ) const
inlineoverridevirtual

returns of this component shall be traced

Returns
true if this component shall be traced

Reimplemented from scc::traceable.

Definition at line 137 of file ordered_semaphore.h.

◆ kind()

const char * scc::ordered_semaphore::kind ( ) const
inlineoverride

kind of this SastemC object

Returns

Definition at line 123 of file ordered_semaphore.h.

◆ post()

auto scc::ordered_semaphore::post ( )
override

unlock (give) the semaphore

Returns
value after posting

Definition at line 116 of file ordered_semaphore.cpp.

◆ report_error()

void scc::ordered_semaphore::report_error ( const char * id,
const char * add_msg = 0 ) const
protected

Definition at line 59 of file ordered_semaphore.cpp.

◆ set_capacity()

void scc::ordered_semaphore::set_capacity ( unsigned capacity)

change the capacity

Parameters
capacitythe new capacity

Definition at line 41 of file ordered_semaphore.cpp.

◆ trace()

void scc::ordered_semaphore::trace ( sc_core::sc_trace_file * tf) const
override

adds internal variables to trace

Parameters
tfthe trace file to register with

Definition at line 53 of file ordered_semaphore.cpp.

◆ trywait()

auto scc::ordered_semaphore::trywait ( )
override

lock (take) the semaphore, return -1 if not available

Returns
value after locking or -1 if the semaphore could not be locked

Definition at line 104 of file ordered_semaphore.cpp.

◆ wait()

int scc::ordered_semaphore::wait ( )
inlineoverride

lock (take) the semaphore, block if not available

Returns
value after locking

Definition at line 75 of file ordered_semaphore.h.

Member Data Documentation

◆ capacity

unsigned scc::ordered_semaphore::capacity
protected

Definition at line 207 of file ordered_semaphore.h.

◆ free_evt

sc_core::sc_event scc::ordered_semaphore::free_evt
protected

Definition at line 205 of file ordered_semaphore.h.

◆ queue

std::array<std::deque<sc_core::sc_process_handle>, 2> scc::ordered_semaphore::queue
protected

Definition at line 210 of file ordered_semaphore.h.

◆ value

int scc::ordered_semaphore::value
protected

Definition at line 206 of file ordered_semaphore.h.

◆ value_ref

std::unique_ptr<scc::sc_ref_variable<int> > scc::ordered_semaphore::value_ref
protected

Definition at line 209 of file ordered_semaphore.h.

◆ value_traceable

bool scc::ordered_semaphore::value_traceable = false
protected

Definition at line 208 of file ordered_semaphore.h.


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