Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
abstract_state.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_ABSTRACT_STATE_H_
20#define HEDGEHOG_ABSTRACT_STATE_H_
21
22#include <shared_mutex>
23
24#include "../../tools/traits.h"
25#include "../../behavior/cleanable.h"
26#include "../../behavior/multi_execute.h"
27#include "../../behavior/input_output/state_multi_senders.h"
28#include "../../core/nodes/core_state_manager.h"
29
30#include "../memory_manager/manager/abstract_memory_manager.h"
31
33namespace hh {
34
40template<size_t Separator, class ...AllTypes>
42 : public behavior::Cleanable,
43 public tool::BehaviorMultiExecuteTypeDeducer_t<tool::Inputs<Separator, AllTypes...>>,
44 public tool::BehaviorStateMultiSendersTypeDeducer_t<tool::Outputs<Separator, AllTypes...>> {
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
47 friend core::CoreStateManager<Separator, AllTypes...>;
48#endif //DOXYGEN_SHOULD_SKIP_THIS
49 private:
50 mutable std::unique_ptr<std::shared_mutex> mutex_ = nullptr;
51 StateManager<Separator, AllTypes...> *stateManager_ = nullptr;
52 public:
54 AbstractState() : mutex_(std::make_unique<std::shared_mutex>()) {}
56 ~AbstractState() override = default;
57
60 std::shared_ptr<ManagedMemory> getManagedMemory() { return stateManager_->getManagedMemory(); }
61
63 void lock() { mutex_->lock(); }
64
66 void unlock() { mutex_->unlock(); }
67
68 private:
73};
74}
75#endif //HEDGEHOG_ABSTRACT_STATE_H_
Hedgehog main namespace.
Hedgehog AbstractState.
std::shared_ptr< ManagedMemory > getManagedMemory()
Accessor to the managed memory if a memory manager has been attached to a StateManager.
void unlock()
Unlock the state.
~AbstractState() override=default
Default state destructor.
StateManager< Separator, AllTypes... > * stateManager_
AbstractState manager currently using the state.
AbstractState()
Default state constructor.
void lock()
Lock the state.
void stateManager(StateManager< Separator, AllTypes... > *stateManager)
AbstractState manager setter.
std::unique_ptr< std::shared_mutex > mutex_
Mutex to protect the state.
AbstractState manager.
Definition: state_manager.h:66
Cleanable interface.
Definition: cleanable.h:29
std::shared_ptr< ManagedMemory > getManagedMemory()
Get a managed memory for the memory manager attached to the task, can block if none are available at ...
Definition: task_node.h:63
AbstractState manager core.