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_semaphore.h -- The sc_semaphore primitive channel 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_SEMAPHORE_H 00028 #define SC_SEMAPHORE_H 00029 00030 00031 #include "sysc/kernel/sc_event.h" 00032 #include "sysc/kernel/sc_object.h" 00033 #include "sysc/communication/sc_semaphore_if.h" 00034 00035 // 02/24/2015 GL: to include the struct chnl_scoped_lock 00036 #include "sysc/communication/sc_prim_channel.h" 00037 00038 namespace sc_core { 00039 00040 /**************************************************************************/ 00046 class sc_semaphore 00047 : public sc_semaphore_if, 00048 public sc_object 00049 { 00050 public: 00051 00052 // constructors 00053 00054 explicit sc_semaphore( int init_value_ ); 00055 sc_semaphore( const char* name_, int init_value_ ); 00056 00057 00058 // interface methods 00059 00060 // lock (take) the semaphore, block if not available 00061 00066 // 08/19/2015 GL: modified for the OoO simulation 00067 virtual int wait( int ); 00068 00069 // lock (take) the semaphore, return -1 if not available 00070 virtual int trywait(); 00071 00072 // unlock (give) the semaphore 00073 virtual int post(); 00074 00075 // get the value of the semaphore 00076 virtual int get_value() const 00077 { 00078 int value; 00079 CHNL_MTX_LOCK_( m_mutex ); // 02/11/2015 GL: acquire the channel lock 00080 value = m_value; 00081 CHNL_MTX_UNLOCK_( m_mutex ); // 02/11/2015 GL: release the channel lock 00082 return value; 00083 } 00084 00085 virtual const char* kind() const 00086 { return "sc_semaphore"; } 00087 00088 protected: 00089 00090 // support methods 00091 00092 bool in_use() const 00093 { return ( m_value <= 0 ); } 00094 00095 00096 // error reporting 00097 void report_error( const char* id, const char* add_msg = 0 ) const; 00098 00099 protected: 00100 00101 sc_event m_free; // event to block on when m_value is negative 00102 int m_value; // current value of the semaphore 00103 00107 // 02/10/2015 GL. 00108 mutable CHNL_MTX_TYPE_ m_mutex; 00109 00110 private: 00111 00112 // disabled 00113 sc_semaphore( const sc_semaphore& ); 00114 sc_semaphore& operator = ( const sc_semaphore& ); 00115 }; 00116 00117 } // namespace sc_core 00118 00119 //$Log: sc_semaphore.h,v $ 00120 //Revision 1.4 2011/08/26 20:45:42 acg 00121 // Andy Goodrich: moved the modification log to the end of the file to 00122 // eliminate source line number skew when check-ins are done. 00123 // 00124 //Revision 1.3 2011/02/18 20:23:45 acg 00125 // Andy Goodrich: Copyright update. 00126 // 00127 //Revision 1.2 2010/11/02 16:31:01 acg 00128 // Andy Goodrich: changed object derivation to use sc_object rather than 00129 // sc_prim_channel as the parent class. 00130 // 00131 //Revision 1.1.1.1 2006/12/15 20:20:04 acg 00132 //SystemC 2.3 00133 // 00134 //Revision 1.4 2006/11/28 20:30:49 acg 00135 // Andy Goodrich: updated from 2.2 source. sc_event_queue constructors 00136 // collapsed into a single constructor with an optional argument to get 00137 // the sc_module_name stack done correctly. Class name prefixing added 00138 // to sc_semaphore calls to wait() to keep gcc 4.x happy. 00139 // 00140 //Revision 1.2 2006/01/03 23:18:26 acg 00141 //Changed copyright to include 2006. 00142 // 00143 //Revision 1.1.1.1 2005/12/19 23:16:43 acg 00144 //First check in of SystemC 2.1 into its own archive. 00145 // 00146 //Revision 1.9 2005/06/10 22:43:55 acg 00147 //Added CVS change log annotation. 00148 // 00149 00150 #endif 00151 00152 // Taf!