00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.accellera.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_mutex_if.h -- The sc_mutex_if interface class. 00021 00022 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 00023 00024 CHANGE LOG IS AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 #ifndef SC_MUTEX_IF_H 00028 #define SC_MUTEX_IF_H 00029 00030 #include "sysc/communication/sc_interface.h" 00031 00032 namespace sc_core { 00033 00034 /**************************************************************************/ 00040 class sc_mutex_if 00041 : virtual public sc_interface 00042 { 00043 public: 00044 00045 // the classical operations: lock(), trylock(), and unlock() 00046 00047 // blocks until mutex could be locked 00048 00053 // 08/19/2015 GL: modified for the OoO simulation 00054 virtual int lock( int ) = 0; 00055 00056 // returns -1 if mutex could not be locked 00057 virtual int trylock() = 0; 00058 00059 // returns -1 if mutex was not locked by caller 00060 virtual int unlock() = 0; 00061 00062 protected: 00063 00064 // constructor 00065 00066 sc_mutex_if() 00067 {} 00068 00069 private: 00070 00071 // disabled 00072 sc_mutex_if( const sc_mutex_if& ); 00073 sc_mutex_if& operator = ( const sc_mutex_if& ); 00074 }; 00075 00076 /**************************************************************************/ 00083 //template< typename Lockable = sc_mutex_if > 00084 class sc_scoped_lock 00085 { 00086 public: 00087 //typedef Lockable lockable_type; 00088 typedef sc_mutex_if lockable_type; 00089 00094 // 08/20/2015 GL. 00095 explicit 00096 sc_scoped_lock( lockable_type& mtx ) 00097 : m_ref(mtx) 00098 , m_active(true) 00099 { 00100 assert( 0 ); // 08/20/2015 GL: to support sc_scoped_lock in the future 00101 00102 m_ref.lock( -4 ); // 08/20/2015 GL: fake segment ID 00103 } 00104 00105 bool release() 00106 { 00107 if( m_active ) 00108 { 00109 m_ref.unlock(); 00110 m_active = false; 00111 return true; 00112 } 00113 return false; 00114 } 00115 00116 ~sc_scoped_lock() 00117 { 00118 release(); 00119 } 00120 00121 private: 00122 // disabled 00123 sc_scoped_lock( const sc_scoped_lock& ); 00124 sc_scoped_lock& operator=( const sc_scoped_lock& ); 00125 00126 lockable_type& m_ref; 00127 bool m_active; 00128 }; 00129 00130 } // namespace sc_core 00131 00132 //$Log: sc_mutex_if.h,v $ 00133 //Revision 1.4 2011/08/26 20:45:41 acg 00134 // Andy Goodrich: moved the modification log to the end of the file to 00135 // eliminate source line number skew when check-ins are done. 00136 // 00137 //Revision 1.3 2011/04/19 02:36:26 acg 00138 // Philipp A. Hartmann: new aysnc_update and mutex support. 00139 // 00140 //Revision 1.2 2011/02/18 20:23:45 acg 00141 // Andy Goodrich: Copyright update. 00142 // 00143 //Revision 1.1.1.1 2006/12/15 20:20:04 acg 00144 //SystemC 2.3 00145 // 00146 //Revision 1.2 2006/01/03 23:18:26 acg 00147 //Changed copyright to include 2006. 00148 // 00149 //Revision 1.1.1.1 2005/12/19 23:16:43 acg 00150 //First check in of SystemC 2.1 into its own archive. 00151 // 00152 //Revision 1.8 2005/06/10 22:43:55 acg 00153 //Added CVS change log annotation. 00154 // 00155 00156 #endif 00157 00158 // Taf!