SystemC  Recoding Infrastructure for SystemC v0.6.3 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_semaphore.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_semaphore.h -- The sc_semaphore primitive channel class.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
23 
24  CHANGE LOG IS AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 #ifndef SC_SEMAPHORE_H
28 #define SC_SEMAPHORE_H
29 
30 
31 #include "sysc/kernel/sc_event.h"
32 #include "sysc/kernel/sc_object.h"
34 
35 // 02/24/2015 GL: to include the struct chnl_scoped_lock
37 
38 namespace sc_core {
39 
40 /**************************************************************************/
47 : public sc_semaphore_if,
48  public sc_object
49 {
50 public:
51 
52  // constructors
53 
54  explicit sc_semaphore( int init_value_ );
55  sc_semaphore( const char* name_, int init_value_ );
56 
57 
58  // interface methods
59 
60  // lock (take) the semaphore, block if not available
61 
66  // 08/19/2015 GL: modified for the OoO simulation
67  virtual int wait( int );
68 
69  // lock (take) the semaphore, return -1 if not available
70  virtual int trywait();
71 
72  // unlock (give) the semaphore
73  virtual int post();
74 
75  // get the value of the semaphore
76  virtual int get_value() const
77  {
78  int value;
79  CHNL_MTX_LOCK_( m_mutex ); // 02/11/2015 GL: acquire the channel lock
80  value = m_value;
81  CHNL_MTX_UNLOCK_( m_mutex ); // 02/11/2015 GL: release the channel lock
82  return value;
83  }
84 
85  virtual const char* kind() const
86  { return "sc_semaphore"; }
87 
88 protected:
89 
90  // support methods
91 
92  bool in_use() const
93  { return ( m_value <= 0 ); }
94 
95 
96  // error reporting
97  void report_error( const char* id, const char* add_msg = 0 ) const;
98 
99 protected:
100 
101  sc_event m_free; // event to block on when m_value is negative
102  int m_value; // current value of the semaphore
103 
107  // 02/10/2015 GL.
109 
110 private:
111 
112  // disabled
113  sc_semaphore( const sc_semaphore& );
114  sc_semaphore& operator = ( const sc_semaphore& );
115 };
116 
117 } // namespace sc_core
118 
119 //$Log: sc_semaphore.h,v $
120 //Revision 1.4 2011/08/26 20:45:42 acg
121 // Andy Goodrich: moved the modification log to the end of the file to
122 // eliminate source line number skew when check-ins are done.
123 //
124 //Revision 1.3 2011/02/18 20:23:45 acg
125 // Andy Goodrich: Copyright update.
126 //
127 //Revision 1.2 2010/11/02 16:31:01 acg
128 // Andy Goodrich: changed object derivation to use sc_object rather than
129 // sc_prim_channel as the parent class.
130 //
131 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
132 //SystemC 2.3
133 //
134 //Revision 1.4 2006/11/28 20:30:49 acg
135 // Andy Goodrich: updated from 2.2 source. sc_event_queue constructors
136 // collapsed into a single constructor with an optional argument to get
137 // the sc_module_name stack done correctly. Class name prefixing added
138 // to sc_semaphore calls to wait() to keep gcc 4.x happy.
139 //
140 //Revision 1.2 2006/01/03 23:18:26 acg
141 //Changed copyright to include 2006.
142 //
143 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
144 //First check in of SystemC 2.1 into its own archive.
145 //
146 //Revision 1.9 2005/06/10 22:43:55 acg
147 //Added CVS change log annotation.
148 //
149 
150 #endif
151 
152 // Taf!
virtual int get_value() const
Definition: sc_semaphore.h:76
#define CHNL_MTX_TYPE_
Definition: sc_process.h:66
virtual int post()
CHNL_MTX_TYPE_ m_mutex
A lock to protect concurrent communication through sc_semaphore.
Definition: sc_semaphore.h:108
virtual int wait(int)
A new parameter segment ID is added for the out-of-order simulation.
#define CHNL_MTX_LOCK_(Mutex)
Definition: sc_process.h:76
The sc_semaphore_if interface class.
bool in_use() const
Definition: sc_semaphore.h:92
virtual int trywait()
virtual const char * kind() const
Definition: sc_semaphore.h:85
The event class.
Definition: sc_event.h:260
sc_semaphore(int init_value_)
The sc_semaphore primitive channel class.
Definition: sc_semaphore.h:46
void report_error(const char *id, const char *add_msg=0) const
#define CHNL_MTX_UNLOCK_(Mutex)
Definition: sc_process.h:78
sc_clock period is zero sc_clock low time is zero sc_fifo< T > cannot have more than one writer bind interface to port failed complete binding failed remove port failed insert primitive channel failed sc_signal< T > cannot have more than one driver resolved port not bound to resolved signal sc_semaphore requires an initial value
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51