SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_semaphore.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_semaphore.h -- The sc_semaphore primitive channel class.
23 */
33 #ifndef SC_SEMAPHORE_H
34 #define SC_SEMAPHORE_H
35 
36 
37 #include "sysc/kernel/sc_event.h"
38 #include "sysc/kernel/sc_object.h"
40 
41 namespace sc_core {
42 
50 : public sc_semaphore_if,
51  public sc_object
52 {
53 public:
54 
55  // constructors
56 
57  explicit sc_semaphore( int init_value_ );
58  sc_semaphore( const char* name_, int init_value_ );
59 
60 
61  // interface methods
62 
63  // lock (take) the semaphore, block if not available
64  virtual int wait();
65 
66  // lock (take) the semaphore, return -1 if not available
67  virtual int trywait();
68 
69  // unlock (give) the semaphore
70  virtual int post();
71 
72  // get the value of the semaphore
73  virtual int get_value() const
74  { return m_value; }
75 
76  virtual const char* kind() const
77  { return "sc_semaphore"; }
78 
79 protected:
80 
81  // support methods
82 
83  bool in_use() const
84  { return ( m_value <= 0 ); }
85 
86 
87  // error reporting
88  void report_error( const char* id, const char* add_msg = 0 ) const;
89 
90 protected:
91 
92  sc_event m_free; // event to block on when m_value is negative
93  int m_value; // current value of the semaphore
94 
95 private:
96 
97  // disabled
98  sc_semaphore( const sc_semaphore& );
99  sc_semaphore& operator = ( const sc_semaphore& );
100 };
101 
102 } // namespace sc_core
103 
104 //$Log: sc_semaphore.h,v $
105 //Revision 1.4 2011/08/26 20:45:42 acg
106 // Andy Goodrich: moved the modification log to the end of the file to
107 // eliminate source line number skew when check-ins are done.
108 //
109 //Revision 1.3 2011/02/18 20:23:45 acg
110 // Andy Goodrich: Copyright update.
111 //
112 //Revision 1.2 2010/11/02 16:31:01 acg
113 // Andy Goodrich: changed object derivation to use sc_object rather than
114 // sc_prim_channel as the parent class.
115 //
116 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
117 //SystemC 2.3
118 //
119 //Revision 1.4 2006/11/28 20:30:49 acg
120 // Andy Goodrich: updated from 2.2 source. sc_event_queue constructors
121 // collapsed into a single constructor with an optional argument to get
122 // the sc_module_name stack done correctly. Class name prefixing added
123 // to sc_semaphore calls to wait() to keep gcc 4.x happy.
124 //
125 //Revision 1.2 2006/01/03 23:18:26 acg
126 //Changed copyright to include 2006.
127 //
128 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
129 //First check in of SystemC 2.1 into its own archive.
130 //
131 //Revision 1.9 2005/06/10 22:43:55 acg
132 //Added CVS change log annotation.
133 //
134 
135 #endif
136 
137 // Taf!
bool in_use() const
Definition: sc_semaphore.h:83
The sc_semaphore_if interface class.
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:61
The sc_semaphore primitive channel class.
Definition: sc_semaphore.h:49
The event class.
Definition: sc_event.h:256
The sc_semaphore_if interface class.
Abstract base class of all SystemC `simulation&#39; objects.
virtual int get_value() const
Definition: sc_semaphore.h:73
virtual const char * kind() const
Definition: sc_semaphore.h:76
#define SC_API
Definition: sc_cmnhdr.h:168
Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21.
void SC_API wait(int, sc_simcontext *)