00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0: 00002 /* 00003 * Copyright (C) 2007, Technical Computer Science Group, 00004 * University of Bonn 00005 * 00006 * This file is part of the ReChannel library. 00007 * 00008 * The ReChannel library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License as 00010 * published by the Free Software Foundation; either version 2 of the 00011 * License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be 00014 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this library; see the file COPYING. If not, write to the 00020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00021 * Boston, MA 02110-1301, USA. 00022 * 00023 * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke. 00024 * {raabe, felke}@cs.uni-bonn.de 00025 */ 00037 #ifndef RC_SEMAPHORE_FILTER_H_ 00038 #define RC_SEMAPHORE_FILTER_H_ 00039 00040 #include "ReChannel/communication/filters/rc_abstract_filter.h" 00041 00042 namespace ReChannel { 00043 00047 class rc_semaphore_filter 00048 : public rc_abstract_filter<sc_semaphore_if> 00049 { 00050 00051 private: 00052 typedef rc_abstract_filter<sc_semaphore_if> base_type; 00053 typedef rc_semaphore_filter this_type; 00054 00055 public: 00056 rc_semaphore_filter( 00057 rc_transaction_counter& tc, bool tc_zero_saturated=true) 00058 : m_tc(tc), m_post_count(0), m_zero_saturated(tc_zero_saturated) 00059 { } 00060 00061 virtual int wait() 00062 { 00063 this->rc_forward(&sc_semaphore_if::wait); 00064 ++m_post_count; 00065 if (m_post_count > 0 || !m_zero_saturated) { 00066 ++m_tc; 00067 } 00068 return 0; 00069 } 00070 00071 virtual int trywait() 00072 { 00073 const int ret = base_type::trywait(); 00074 if (ret == 0) { 00075 ++m_post_count; 00076 if (m_post_count > 0 || !m_zero_saturated) { 00077 ++m_tc; 00078 } 00079 } 00080 return ret; 00081 } 00082 00083 virtual int post() 00084 { 00085 base_type::post(); 00086 if (m_post_count > 0 || !m_zero_saturated) { 00087 --m_tc; 00088 } 00089 --m_post_count; 00090 return 0; 00091 } 00092 00093 virtual int get_value() const 00094 { 00095 return base_type::get_value(); 00096 } 00097 00098 protected: 00099 00100 rc_transaction_counter& m_tc; 00101 int m_post_count; 00102 bool m_zero_saturated; 00103 00104 private: 00105 // disabled 00106 rc_semaphore_filter(const this_type& other_); 00107 this_type& operator=(const this_type& other_); 00108 }; 00109 00110 } // namespace ReChannel 00111 00112 #endif // RC_SEMAPHORE_FILTER_H_ 00113 00114 // 00115 // $Id: rc_semaphore_filter.h,v 1.4 2007/12/06 11:42:43 felke Exp $ 00116 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/filters/rc_semaphore_filter.h,v $ 00117 //