sc_semaphore.h

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-2006 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.4 (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_semaphore.h -- The sc_semaphore 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 //$Log: sc_semaphore.h,v $
00036 //Revision 1.1.1.1  2006/12/15 20:31:35  acg
00037 //SystemC 2.2
00038 //
00039 //Revision 1.2  2006/01/03 23:18:26  acg
00040 //Changed copyright to include 2006.
00041 //
00042 //Revision 1.1.1.1  2005/12/19 23:16:43  acg
00043 //First check in of SystemC 2.1 into its own archive.
00044 //
00045 //Revision 1.9  2005/06/10 22:43:55  acg
00046 //Added CVS change log annotation.
00047 //
00048 
00049 #ifndef SC_SEMAPHORE_H
00050 #define SC_SEMAPHORE_H
00051 
00052 
00053 #include "sysc/kernel/sc_event.h"
00054 #include "sysc/communication/sc_prim_channel.h"
00055 #include "sysc/communication/sc_semaphore_if.h"
00056 
00057 namespace sc_core {
00058 
00059 // ----------------------------------------------------------------------------
00060 //  CLASS : sc_semaphore
00061 //
00062 //  The sc_semaphore primitive channel class.
00063 // ----------------------------------------------------------------------------
00064 
00065 class sc_semaphore
00066 : public sc_semaphore_if,
00067   public sc_prim_channel
00068 {
00069 public:
00070 
00071     // constructors
00072 
00073     explicit sc_semaphore( int init_value_ );
00074     sc_semaphore( const char* name_, int init_value_ );
00075 
00076 
00077     // interface methods
00078 
00079     // lock (take) the semaphore, block if not available
00080     virtual int wait();
00081 
00082     // lock (take) the semaphore, return -1 if not available
00083     virtual int trywait();
00084 
00085     // unlock (give) the semaphore
00086     virtual int post();
00087 
00088     // get the value of the semaphore
00089     virtual int get_value() const
00090     { return m_value; }
00091 
00092     virtual const char* kind() const
00093         { return "sc_semaphore"; }
00094 
00095 protected:
00096 
00097     // support methods
00098 
00099     bool in_use() const
00100     { return ( m_value <= 0 ); }
00101 
00102 
00103     // error reporting
00104     void report_error( const char* id, const char* add_msg = 0 ) const;
00105 
00106 protected:
00107 
00108     sc_event m_free;        // event to block on when m_value is negative
00109     int      m_value;       // current value of the semaphore
00110 
00111 private:
00112 
00113     // disabled
00114     sc_semaphore( const sc_semaphore& );
00115     sc_semaphore& operator = ( const sc_semaphore& );
00116 };
00117 
00118 } // namespace sc_core
00119 
00120 #endif
00121 
00122 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5