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