SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_mutex_if.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_mutex_if.h -- The sc_mutex_if interface 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_MUTEX_IF_H
28 #define SC_MUTEX_IF_H
29 
31 
32 namespace sc_core {
33 
34 /**************************************************************************/
41 : virtual public sc_interface
42 {
43 public:
44 
45  // the classical operations: lock(), trylock(), and unlock()
46 
47  // blocks until mutex could be locked
48 
53  // 08/19/2015 GL: modified for the OoO simulation
54  virtual int lock( int ) = 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 
76 /**************************************************************************/
83 //template< typename Lockable = sc_mutex_if >
85 {
86 public:
87  //typedef Lockable lockable_type;
89 
94  // 08/20/2015 GL.
95  explicit
97  : m_ref(mtx)
98  , m_active(true)
99  {
100  assert( 0 ); // 08/20/2015 GL: to support sc_scoped_lock in the future
101 
102  m_ref.lock( -4 ); // 08/20/2015 GL: fake segment ID
103  }
104 
105  bool release()
106  {
107  if( m_active )
108  {
109  m_ref.unlock();
110  m_active = false;
111  return true;
112  }
113  return false;
114  }
115 
117  {
118  release();
119  }
120 
121 private:
122  // disabled
123  sc_scoped_lock( const sc_scoped_lock& );
124  sc_scoped_lock& operator=( const sc_scoped_lock& );
125 
126  lockable_type& m_ref;
127  bool m_active;
128 };
129 
130 } // namespace sc_core
131 
132 //$Log: sc_mutex_if.h,v $
133 //Revision 1.4 2011/08/26 20:45:41 acg
134 // Andy Goodrich: moved the modification log to the end of the file to
135 // eliminate source line number skew when check-ins are done.
136 //
137 //Revision 1.3 2011/04/19 02:36:26 acg
138 // Philipp A. Hartmann: new aysnc_update and mutex support.
139 //
140 //Revision 1.2 2011/02/18 20:23:45 acg
141 // Andy Goodrich: Copyright update.
142 //
143 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
144 //SystemC 2.3
145 //
146 //Revision 1.2 2006/01/03 23:18:26 acg
147 //Changed copyright to include 2006.
148 //
149 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
150 //First check in of SystemC 2.1 into its own archive.
151 //
152 //Revision 1.8 2005/06/10 22:43:55 acg
153 //Added CVS change log annotation.
154 //
155 
156 #endif
157 
158 // Taf!
virtual int lock(int)=0
A new parameter segment ID is added for the out-of-order simulation.
sc_scoped_lock(lockable_type &mtx)
This constructor function is not supported by the out-of-order simulation in the current release...
Definition: sc_mutex_if.h:96
The sc_scoped_lock class to lock (and automatically release) a mutex.
Definition: sc_mutex_if.h:84
virtual int unlock()=0
virtual int trylock()=0
The sc_mutex_if interface class.
Definition: sc_mutex_if.h:40
sc_mutex_if lockable_type
Definition: sc_mutex_if.h:88
Abstract base class of all interface classes.
Definition: sc_interface.h:44