scc  2022.4.0
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 More...
 
 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 More...
 
int wait (unsigned priority)
 
int trywait () override
 lock (take) the semaphore, return -1 if not available More...
 
int post () override
 unlock (give) the semaphore More...
 
unsigned get_capacity ()
 retrieve the initial capacity of the semaphore
 
void set_capacity (unsigned capacity)
 change the capacity More...
 
int get_value () const override
 get the value of the semaphore More...
 
const char * kind () const override
 kind of this SastemC object More...
 
void trace (sc_core::sc_trace_file *tf) const override
 adds internal variables to trace More...
 
bool is_trace_enabled () const override
 returns of this component shall be traced More...
 

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::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 44 of file ordered_semaphore.h.

Constructor & Destructor Documentation

◆ ordered_semaphore()

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 62 of file ordered_semaphore.cpp.

Member Function Documentation

◆ get_value()

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

get the value of the semaphore

Returns
current value

Definition at line 115 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 136 of file ordered_semaphore.h.

◆ kind()

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

kind of this SastemC object

Returns

Definition at line 122 of file ordered_semaphore.h.

◆ post()

int scc::ordered_semaphore::post ( )
override

unlock (give) the semaphore

Returns
value after posting

Definition at line 103 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()

int 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 93 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 74 of file ordered_semaphore.h.


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