gem5  v22.1.0.0
instance_specific_extensions.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*
21 Instance specific extensions, are extension that only a single instance of a
22 module may access. They are invisible to all other modules; they are private
23 to this instance so to speak.
24 
25 As they are only of value to a certain instance, this instance knows very
26 well when it needs them and when it does not need them any longer (usually
27 when a transaction passes through a module for the last time). It does not
28 have to care if anyone else in the system may still have a reference to the
29 transaction as this one is not able to access the extension anyway.
30 Therefore the instance is obliged to call set_extension when it wants to add a
31 private extension and clear_extension when it does not need it any more.
32 
33 To get access to an instance specifc extension the module must own a so called
34 instance_specific_extension_accessor that provides the exclusive access rights.
35 Assuming the instance_specific_extension_accessor of a given module is called
36 m_accessor and the transaction of which the private extension is about to be
37 accessed is called txn, then the calls have to be
38 
39 m_accessor(txn).set_extension(...);
40 or
41 m_accessor(txn).clear_extension(...);
42 
43 The owner of the private extension is responsible to allocate/deallocate
44 the extension before/after setting/clearing the extension.
45 */
46 
47 #ifndef __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_H__
48 #define __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_H__
49 
51 
52 namespace tlm_utils
53 {
54 
55 // The templated private extension. Similar to normal extension.
56 template <typename T>
58 {
59  public:
61  const static unsigned int priv_id;
62 };
63 
64 template <typename T>
65 const unsigned int instance_specific_extension<T>::priv_id =
67 
68 // ----------------------------------------------------------------------------
69 
70 // This is the class that actually sits in the extension array
71 // - We keep this small since that one gets allocated and deallocated all
72 // the times.
73 // - We keep the implementation in the header to avoid registration
74 // of the extension itself unless used in the model.
76  public tlm::tlm_extension<instance_specific_extension_carrier>
77 {
79  public:
81 
82  virtual tlm::tlm_extension_base *
83  clone() const
84  {
85  // We don't clone since private info is instance specific and
86  // associated to a given txn (the original) so the deep copied txn
87  // will be virgin in terms of private info.
88  return NULL;
89  }
90 
91  void copy_from(tlm::tlm_extension_base const &) { return; }
92  void free() { return; }
93 
94  private:
96 };
97 
98 // ----------------------------------------------------------------------------
99 
100 template <typename T>
103 {
104  instance_specific_extension_carrier *carrier = NULL;
105  txn.get_extension(carrier);
106  if (!carrier) {
107  carrier = new instance_specific_extension_carrier();
109  carrier->m_container->attach_carrier(
110  carrier, &txn, &release_carrier<T>);
111  txn.set_extension(carrier);
112  }
113  return *carrier->m_container->get_accessor(m_index);
114 }
115 
116 template <typename T>
117 void
119  instance_specific_extension_carrier *carrier, void *txn)
120 {
121  T *typed_txn = static_cast<T *>(txn);
122  typed_txn->clear_extension(carrier);
123  delete carrier;
124 }
125 
126 } // namespace tlm_utils
127 
128 #endif /* __SYSTEMC_EXT_TLM_UTILS_INSTANCE_SPECIFIC_EXTENSIONS_H__ */
instance_specific_extensions_per_accessor & operator()(T &txn)
static void release_carrier(instance_specific_extension_carrier *, void *txn)
virtual tlm::tlm_extension_base * clone() const
instance_specific_extension_container * m_container
void attach_carrier(instance_specific_extension_carrier *, void *txn, release_fn *)
instance_specific_extensions_per_accessor * get_accessor(unsigned int index)
static instance_specific_extension_container * create()
static unsigned int register_private_extension(const std::type_info &)

Generated on Wed Dec 21 2022 10:22:42 for gem5 by doxygen 1.9.1