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 namespace sc_core {
36 
37 // ----------------------------------------------------------------------------
38 // CLASS : sc_semaphore
39 //
40 // The sc_semaphore primitive channel class.
41 // ----------------------------------------------------------------------------
42 
44 : public sc_semaphore_if,
45  public sc_object
46 {
47 public:
48 
49  // constructors
50 
51  explicit sc_semaphore( int init_value_ );
52  sc_semaphore( const char* name_, int init_value_ );
53 
54 
55  // interface methods
56 
57  // lock (take) the semaphore, block if not available
58  virtual int wait();
59 
60  // lock (take) the semaphore, return -1 if not available
61  virtual int trywait();
62 
63  // unlock (give) the semaphore
64  virtual int post();
65 
66  // get the value of the semaphore
67  virtual int get_value() const
68  { return m_value; }
69 
70  virtual const char* kind() const
71  { return "sc_semaphore"; }
72 
73 protected:
74 
75  // support methods
76 
77  bool in_use() const
78  { return ( m_value <= 0 ); }
79 
80 
81  // error reporting
82  void report_error( const char* id, const char* add_msg = 0 ) const;
83 
84 protected:
85 
86  sc_event m_free; // event to block on when m_value is negative
87  int m_value; // current value of the semaphore
88 
89 private:
90 
91  // disabled
92  sc_semaphore( const sc_semaphore& );
93  sc_semaphore& operator = ( const sc_semaphore& );
94 };
95 
96 } // namespace sc_core
97 
98 //$Log: sc_semaphore.h,v $
99 //Revision 1.4 2011/08/26 20:45:42 acg
100 // Andy Goodrich: moved the modification log to the end of the file to
101 // eliminate source line number skew when check-ins are done.
102 //
103 //Revision 1.3 2011/02/18 20:23:45 acg
104 // Andy Goodrich: Copyright update.
105 //
106 //Revision 1.2 2010/11/02 16:31:01 acg
107 // Andy Goodrich: changed object derivation to use sc_object rather than
108 // sc_prim_channel as the parent class.
109 //
110 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
111 //SystemC 2.3
112 //
113 //Revision 1.4 2006/11/28 20:30:49 acg
114 // Andy Goodrich: updated from 2.2 source. sc_event_queue constructors
115 // collapsed into a single constructor with an optional argument to get
116 // the sc_module_name stack done correctly. Class name prefixing added
117 // to sc_semaphore calls to wait() to keep gcc 4.x happy.
118 //
119 //Revision 1.2 2006/01/03 23:18:26 acg
120 //Changed copyright to include 2006.
121 //
122 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
123 //First check in of SystemC 2.1 into its own archive.
124 //
125 //Revision 1.9 2005/06/10 22:43:55 acg
126 //Added CVS change log annotation.
127 //
128 
129 #endif
130 
131 // Taf!
virtual int trywait()
virtual int wait()
bool in_use() const
Definition: sc_semaphore.h:77
virtual const char * kind() const
Definition: sc_semaphore.h:70
void report_error(const char *id, const char *add_msg=0) const
virtual int post()
sc_semaphore(int init_value_)
virtual int get_value() const
Definition: sc_semaphore.h:67