sc_mutex_if.h revision 12027
12SN/A/***************************************************************************** 21762SN/A 32SN/A Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 42SN/A more contributor license agreements. See the NOTICE file distributed 52SN/A with this work for additional information regarding copyright ownership. 62SN/A Accellera licenses this file to you under the Apache License, Version 2.0 72SN/A (the "License"); you may not use this file except in compliance with the 82SN/A License. You may obtain a copy of the License at 92SN/A 102SN/A http://www.apache.org/licenses/LICENSE-2.0 112SN/A 122SN/A Unless required by applicable law or agreed to in writing, software 132SN/A distributed under the License is distributed on an "AS IS" BASIS, 142SN/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 152SN/A implied. See the License for the specific language governing 162SN/A permissions and limitations under the License. 172SN/A 182SN/A *****************************************************************************/ 192SN/A 202SN/A/***************************************************************************** 212SN/A 222SN/A sc_mutex_if.h -- The sc_mutex_if interface class. 232SN/A 242SN/A Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 252SN/A 262SN/A CHANGE LOG IS AT THE END OF THE FILE 272665Ssaidi@eecs.umich.edu *****************************************************************************/ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#ifndef SC_MUTEX_IF_H 302SN/A#define SC_MUTEX_IF_H 312SN/A 3211793Sbrandon.potter@amd.com#include "sysc/communication/sc_interface.h" 3311793Sbrandon.potter@amd.com 344183Sgblack@eecs.umich.edunamespace sc_core { 3512334Sgabeblack@google.com 368229Snate@binkert.org// ---------------------------------------------------------------------------- 372680Sktlim@umich.edu// CLASS : sc_mutex_if 388232Snate@binkert.org// 398229Snate@binkert.org// The sc_mutex_if interface class. 408784Sgblack@eecs.umich.edu// ---------------------------------------------------------------------------- 414183Sgblack@eecs.umich.edu 422SN/Aclass sc_mutex_if 4310417Sandreas.hansson@arm.com: virtual public sc_interface 442201SN/A{ 458784Sgblack@eecs.umich.edupublic: 468589Sgblack@eecs.umich.edu 478589Sgblack@eecs.umich.edu // the classical operations: lock(), trylock(), and unlock() 488589Sgblack@eecs.umich.edu 498589Sgblack@eecs.umich.edu // blocks until mutex could be locked 502201SN/A virtual int lock() = 0; 512612SN/A 5210417Sandreas.hansson@arm.com // returns -1 if mutex could not be locked 532612SN/A virtual int trylock() = 0; 546815SLisa.Hsu@amd.com 552612SN/A // returns -1 if mutex was not locked by caller 565004Sgblack@eecs.umich.edu virtual int unlock() = 0; 5710417Sandreas.hansson@arm.com 588545Ssaidi@eecs.umich.eduprotected: 598545Ssaidi@eecs.umich.edu 608545Ssaidi@eecs.umich.edu // constructor 618545Ssaidi@eecs.umich.edu 6211877Sbrandon.potter@amd.com sc_mutex_if() 6311877Sbrandon.potter@amd.com {} 6411877Sbrandon.potter@amd.com 6511877Sbrandon.potter@amd.comprivate: 6611877Sbrandon.potter@amd.com 6710417Sandreas.hansson@arm.com // disabled 684183Sgblack@eecs.umich.edu sc_mutex_if( const sc_mutex_if& ); 698589Sgblack@eecs.umich.edu sc_mutex_if& operator = ( const sc_mutex_if& ); 708784Sgblack@eecs.umich.edu}; 718784Sgblack@eecs.umich.edu 728784Sgblack@eecs.umich.edu// ---------------------------------------------------------------------------- 738784Sgblack@eecs.umich.edu// CLASS : sc_scoped_lock 748589Sgblack@eecs.umich.edu// 754183Sgblack@eecs.umich.edu// The sc_scoped_lock class to lock (and automatically release) a mutex. 764434Ssaidi@eecs.umich.edu// ---------------------------------------------------------------------------- 774183Sgblack@eecs.umich.edu 785004Sgblack@eecs.umich.edu//template< typename Lockable = sc_mutex_if > 7910417Sandreas.hansson@arm.comclass sc_scoped_lock 805004Sgblack@eecs.umich.edu{ 815004Sgblack@eecs.umich.edupublic: 825004Sgblack@eecs.umich.edu //typedef Lockable lockable_type; 83 typedef sc_mutex_if lockable_type; 84 85 explicit 86 sc_scoped_lock( lockable_type& mtx ) 87 : m_ref(mtx) 88 , m_active(true) 89 { 90 m_ref.lock(); 91 } 92 93 bool release() 94 { 95 if( m_active ) 96 { 97 m_ref.unlock(); 98 m_active = false; 99 return true; 100 } 101 return false; 102 } 103 104 ~sc_scoped_lock() 105 { 106 release(); 107 } 108 109private: 110 // disabled 111 sc_scoped_lock( const sc_scoped_lock& ); 112 sc_scoped_lock& operator=( const sc_scoped_lock& ); 113 114 lockable_type& m_ref; 115 bool m_active; 116}; 117 118} // namespace sc_core 119 120//$Log: sc_mutex_if.h,v $ 121//Revision 1.4 2011/08/26 20:45:41 acg 122// Andy Goodrich: moved the modification log to the end of the file to 123// eliminate source line number skew when check-ins are done. 124// 125//Revision 1.3 2011/04/19 02:36:26 acg 126// Philipp A. Hartmann: new aysnc_update and mutex support. 127// 128//Revision 1.2 2011/02/18 20:23:45 acg 129// Andy Goodrich: Copyright update. 130// 131//Revision 1.1.1.1 2006/12/15 20:20:04 acg 132//SystemC 2.3 133// 134//Revision 1.2 2006/01/03 23:18:26 acg 135//Changed copyright to include 2006. 136// 137//Revision 1.1.1.1 2005/12/19 23:16:43 acg 138//First check in of SystemC 2.1 into its own archive. 139// 140//Revision 1.8 2005/06/10 22:43:55 acg 141//Added CVS change log annotation. 142// 143 144#endif 145 146// Taf! 147