Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_mutex.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2004 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 Version 2.3 (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.systemc.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.cpp -- The sc_mutex primitive channel class.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033     
00034  *****************************************************************************/
00035 
00036 
00037 #include "systemc/communication/sc_mutex.h"
00038 #include "systemc/kernel/sc_simcontext.h"
00039 
00040 
00041 // ----------------------------------------------------------------------------
00042 //  CLASS : sc_mutex
00043 //
00044 //  The sc_mutex primitive channel class.
00045 // ----------------------------------------------------------------------------
00046 
00047 // constructors
00048 
00049 sc_mutex::sc_mutex()
00050 : sc_prim_channel( sc_gen_unique_name( "mutex" ) ),
00051   m_owner( 0 )
00052 {}
00053 
00054 sc_mutex::sc_mutex( const char* name_ )
00055 : sc_prim_channel( name_ ),
00056   m_owner( 0 )
00057 {}
00058 
00059 
00060 // interface methods
00061 
00062 // blocks until mutex could be locked
00063 
00064 int
00065 sc_mutex::lock()
00066 {
00067     while( in_use() ) {
00068   wait( m_free );
00069     }
00070     m_owner = sc_get_curr_process_handle();
00071     return 0;
00072 }
00073 
00074 
00075 // returns -1 if mutex could not be locked
00076 
00077 int
00078 sc_mutex::trylock()
00079 {
00080     if( in_use() ) {
00081   return -1;
00082     }
00083     m_owner = sc_get_curr_process_handle();
00084     return 0;
00085 }
00086 
00087 
00088 // returns -1 if mutex was not locked by caller
00089 
00090 int
00091 sc_mutex::unlock()
00092 {
00093     if( m_owner != sc_get_curr_process_handle() ) {
00094   return -1;
00095     }
00096     m_owner = 0;
00097     m_free.notify();
00098     return 0;
00099 }
00100 
00101 
00102 // Taf!

Generated on Fri Jan 14 08:29:03 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18