SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_buffer.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_buffer.h -- The sc_buffer<T> primitive channel class.
21  Like sc_signal<T>, but *every* write causes an event.
22 
23  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
24 
25  CHANGE LOG IS AT THE END OF THE FILE
26  *****************************************************************************/
27 
28 #ifndef SC_BUFFER_H
29 #define SC_BUFFER_H
30 
31 
33 
34 namespace sc_core {
35 
36 /**************************************************************************/
42 template< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY >
43 class sc_buffer
44 : public sc_signal<T,POL>
45 {
46 public:
47 
48  // typedefs
49 
52 
53 public:
54 
55  // constructors
56 
58  : base_type( sc_gen_unique_name( "buffer" ) )
59  {}
60 
61  explicit sc_buffer( const char* name_ )
62  : base_type( name_ )
63  {}
64 
65  sc_buffer( const char* name_, const T& initial_value_ )
66  : base_type( name_, initial_value_ )
67  {}
68 
69  // interface methods
70 
71  // write the new value
72  virtual void write( const T& );
73 
74 
75  // other methods
76 
77  this_type& operator = ( const T& a )
78  { write( a ); return *this; }
79 
81  { write( a.read() ); return *this; }
82 
84  { write( a.read() ); return *this; }
85 
86  virtual const char* kind() const
87  { return "sc_buffer"; }
88 
89 protected:
90 
91  virtual void update();
92 
93 private:
94 
95  // disabled
96  sc_buffer( const this_type& );
97 };
98 
99 
100 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
101 
102 // write the new value
103 
104 template< typename T, sc_writer_policy POL >
105 inline
106 void
107 sc_buffer<T,POL>::write( const T& value_ )
108 {
109  // 02/23/2015 GL: acquire a lock to protect concurrent communication,
110  // but sc_signal should have a single write port?!
111  // 02/24/2015 GL: the reason to add "this->" before m_mutex:
112  // http://www.parashift.com/c++-faq-lite/nondependent-name-lookup-members.html
113  chnl_scoped_lock lock( this->m_mutex );
114 
115  if( !base_type::policy_type::check_write(this,true) )
116  return;
117 
118  this->m_new_val = value_;
119  this->request_update();
120  // 02/23/2015 GL: return releases the lock
121 }
122 
123 
124 template< typename T, sc_writer_policy POL >
125 inline
126 void
128 {
129  base_type::policy_type::update();
130  base_type::do_update();
131 }
132 
133 } // namespace sc_core
134 
135 #endif
136 
137 //$Log: sc_buffer.h,v $
138 //Revision 1.7 2011/08/26 20:45:39 acg
139 // Andy Goodrich: moved the modification log to the end of the file to
140 // eliminate source line number skew when check-ins are done.
141 //
142 //Revision 1.6 2011/04/08 18:22:45 acg
143 // Philipp A. Hartmann: use the context of the primitive channel to get
144 // the change stamp value.
145 //
146 //Revision 1.5 2011/04/05 20:48:09 acg
147 // Andy Goodrich: changes to make sure that event(), posedge() and negedge()
148 // only return true if the clock has not moved.
149 //
150 //Revision 1.4 2011/04/05 06:15:18 acg
151 // Philipp A. Hartmann: sc_writer_policy: ignore no-ops in delta check.
152 //
153 //Revision 1.3 2011/02/18 20:23:45 acg
154 // Andy Goodrich: Copyright update.
155 //
156 //Revision 1.2 2010/12/07 19:50:36 acg
157 // Andy Goodrich: addition of writer policies, courtesy of Philipp Hartmann.
158 //
159 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
160 //SystemC 2.3
161 //
162 //Revision 1.8 2006/03/13 20:19:43 acg
163 // Andy Goodrich: changed sc_event instances into pointers to sc_event instances
164 // that are allocated as needed. This saves considerable storage for large
165 // numbers of signals, etc.
166 //
167 //Revision 1.7 2006/01/26 21:00:49 acg
168 // Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of
169 // sc_event::notify_delayed()
170 //
171 //Revision 1.6 2006/01/24 20:46:31 acg
172 //Andy Goodrich: changes to eliminate use of deprecated features. For instance,
173 //using notify(SC_ZERO_TIME) in place of notify_delayed().
174 //
175 //Revision 1.5 2006/01/19 19:18:25 acg
176 //Andy Goodrich: eliminated check_writer in favor of inline code within the
177 //write() method since we always execute the check_writer code even when
178 //check writing is turned off.
179 //
180 //Revision 1.4 2006/01/19 00:30:57 acg
181 //Andy Goodrich: Yet another implementation for disabling write checks on
182 //signals. This version uses an environment variable, SC_SIGNAL_WRITE_CHECK,
183 //that when set to DISABLE will turn off write checking.
184 //
185 //Revision 1.3 2006/01/13 18:47:20 acg
186 //Reversed sense of multiwriter signal check. It now defaults to ON unless the
187 //user defines SC_NO_WRITE_CHEK before inclusion of the file.
188 //
189 //Revision 1.2 2006/01/03 23:18:26 acg
190 //Changed copyright to include 2006.
191 //
192 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
193 //First check in of SystemC 2.1 into its own archive.
194 //
195 //Revision 1.9 2005/06/10 22:43:55 acg
196 //Added CVS change log annotation.
197 //
198 
199 // Taf!
this_type & operator=(const T &a)
Definition: sc_buffer.h:77
virtual void write(const T &)
Definition: sc_buffer.h:107
sc_buffer(const char *name_)
Definition: sc_buffer.h:61
sc_buffer(const char *name_, const T &initial_value_)
Definition: sc_buffer.h:65
virtual void update()
The update method (does nothing by default).
Definition: sc_buffer.h:127
const char * sc_gen_unique_name(const char *, bool preserve_first)
The sc_signal&lt;T&gt; input interface class.
Definition: sc_signal_ifs.h:43
virtual const char * kind() const
Definition: sc_buffer.h:86
virtual const T & read() const
Definition: sc_signal.h:134
sc_signal< T, POL > base_type
Definition: sc_buffer.h:51
sc_buffer< T, POL > this_type
Definition: sc_buffer.h:50
The chnl_scoped_lock class to lock (and automatically release) a mutex.