src/sysc/communication/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-2005 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 
00036 #ifndef SC_SEMAPHORE_H
00037 #define SC_SEMAPHORE_H
00038 
00039 
00040 #include "sysc/kernel/sc_event.h"
00041 #include "sysc/communication/sc_prim_channel.h"
00042 #include "sysc/communication/sc_semaphore_if.h"
00043 
00044 namespace sc_core {
00045 
00046 // ----------------------------------------------------------------------------
00047 //  CLASS : sc_semaphore
00048 //
00049 //  The sc_semaphore primitive channel class.
00050 // ----------------------------------------------------------------------------
00051 
00052 class sc_semaphore
00053 : public sc_semaphore_if,
00054   public sc_prim_channel
00055 {
00056 public:
00057 
00058     // constructors
00059 
00060     explicit sc_semaphore( int init_value_ );
00061     sc_semaphore( const char* name_, int init_value_ );
00062 
00063 
00064     // interface methods
00065 
00066     // lock (take) the semaphore, block if not available
00067     virtual int wait();
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         { return m_value; }
00078 
00079     virtual const char* kind() const
00080         { return "sc_semaphore"; }
00081 
00082 protected:
00083 
00084     // support methods
00085 
00086     bool in_use() const
00087         { return ( m_value <= 0 ); }
00088 
00089 
00090     // error reporting
00091     void report_error( const char* id, const char* add_msg = 0 ) const;
00092 
00093 protected:
00094 
00095     int      m_value;  // current value of the semaphore
00096     sc_event m_free;
00097 
00098 private:
00099 
00100     // disabled
00101     sc_semaphore( const sc_semaphore& );
00102     sc_semaphore& operator = ( const sc_semaphore& );
00103 };
00104 
00105 } // namespace sc_core
00106 
00107 #endif
00108 
00109 // Taf!

Generated on Wed Apr 25 13:53:25 2007 for SystemC by  doxygen 1.5.1