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