GetLockPointer.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 #include "Parallel/NodeLock.hpp"
9 #include "Utilities/Gsl.hpp"
10 #include "Utilities/PrettyType.hpp"
11 #include "Utilities/TMPL.hpp"
12 
13 namespace observers::Actions {
14 
15 /// Local synchronous action for retrieving a pointer to the `NodeLock` with tag
16 /// `LockTag` on the component.
17 ///
18 /// \warning The retrieved pointer to a lock must only be treated as 'good'
19 /// during the execution of the action from which this synchronous action is
20 /// called. This is because we can only trust that charm will not migrate the
21 /// component on which the action is running until after the action has
22 /// completed, and it will not migrate the Nodegroup to which the lock points
23 /// until a checkpoint.
24 template <typename LockTag>
27 
28  template <typename ParallelComponent, typename DbTagList>
29  static return_type apply(
30  db::DataBox<DbTagList>& box,
31  const gsl::not_null<Parallel::NodeLock*> node_lock) noexcept {
32  if constexpr (tmpl::list_contains_v<DbTagList, LockTag>) {
33  Parallel::NodeLock* result_lock;
34  node_lock->lock();
35  db::mutate<LockTag>(
36  make_not_null(&box),
37  [&result_lock](
38  const gsl::not_null<Parallel::NodeLock*> lock) noexcept {
39  result_lock = lock;
40  });
41  node_lock->unlock();
42  return result_lock;
43  } else {
44  // silence 'unused variable' warnings
45  (void)node_lock;
46  ERROR("Could not find required tag " << pretty_type::get_name<LockTag>()
47  << " in the databox");
48  }
49  }
50 };
51 } // namespace observers::Actions
Error.hpp
PrettyType.hpp
Parallel::NodeLock
A typesafe wrapper for a lock for synchronization of shared resources on a given node,...
Definition: NodeLock.hpp:25
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:37
DataBox.hpp
Gsl.hpp
observers::Actions::GetLockPointer
Local synchronous action for retrieving a pointer to the NodeLock with tag LockTag on the component.
Definition: GetLockPointer.hpp:25
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
observers::Actions
Actions used by the observer parallel component
Definition: GetLockPointer.hpp:13
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13