SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_mutex_if.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_mutex_if.h -- The sc_mutex_if interface class.
23 */
33 #ifndef SC_MUTEX_IF_H
34 #define SC_MUTEX_IF_H
35 
37 
38 namespace sc_core {
39 
47 : virtual public sc_interface
48 {
49 public:
50 
51  // the classical operations: lock(), trylock(), and unlock()
52 
53  // blocks until mutex could be locked
54  virtual int lock() = 0;
55 
56  // returns -1 if mutex could not be locked
57  virtual int trylock() = 0;
58 
59  // returns -1 if mutex was not locked by caller
60  virtual int unlock() = 0;
61 
62 protected:
63 
64  // constructor
65 
67  {}
68 
69 private:
70 
71  // disabled
72  sc_mutex_if( const sc_mutex_if& );
73  sc_mutex_if& operator = ( const sc_mutex_if& );
74 };
75 
82 //template< typename Lockable = sc_mutex_if >
84 {
85 public:
86  //typedef Lockable lockable_type;
88 
89  explicit
90  sc_scoped_lock( lockable_type& mtx )
91  : m_ref(mtx)
92  , m_active(true)
93  {
94  m_ref.lock();
95  }
96 
97  bool release()
98  {
99  if( m_active )
100  {
101  m_ref.unlock();
102  m_active = false;
103  return true;
104  }
105  return false;
106  }
107 
109  {
110  release();
111  }
112 
113 private:
114  // disabled
115  sc_scoped_lock( const sc_scoped_lock& );
116  sc_scoped_lock& operator=( const sc_scoped_lock& );
117 
118  lockable_type& m_ref;
119  bool m_active;
120 };
121 
122 } // namespace sc_core
123 
124 //$Log: sc_mutex_if.h,v $
125 //Revision 1.4 2011/08/26 20:45:41 acg
126 // Andy Goodrich: moved the modification log to the end of the file to
127 // eliminate source line number skew when check-ins are done.
128 //
129 //Revision 1.3 2011/04/19 02:36:26 acg
130 // Philipp A. Hartmann: new aysnc_update and mutex support.
131 //
132 //Revision 1.2 2011/02/18 20:23:45 acg
133 // Andy Goodrich: Copyright update.
134 //
135 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
136 //SystemC 2.3
137 //
138 //Revision 1.2 2006/01/03 23:18:26 acg
139 //Changed copyright to include 2006.
140 //
141 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
142 //First check in of SystemC 2.1 into its own archive.
143 //
144 //Revision 1.8 2005/06/10 22:43:55 acg
145 //Added CVS change log annotation.
146 //
147 
148 #endif
149 
150 // Taf!
sc_scoped_lock(lockable_type &mtx)
Definition: sc_mutex_if.h:90
The sc_mutex_if interface class.
Definition: sc_mutex_if.h:46
sc_mutex_if lockable_type
Definition: sc_mutex_if.h:87
Abstract base class of all interface classes.
Abstract base class of all interface classes.
Definition: sc_interface.h:51
The sc_scoped_lock class to lock (and automatically release) a mutex.
Definition: sc_mutex_if.h:83
#define SC_API
Definition: sc_cmnhdr.h:168