helics  3.5.2
ZmqContextManager.h
1 /*
2 Copyright (c) 2017-2024,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 /*
9  * LLNS Copyright Start
10  * Copyright (c) 2017, Lawrence Livermore National Security
11  * This work was performed under the auspices of the U.S. Department
12  * of Energy by Lawrence Livermore National Laboratory in part under
13  * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
14  * Produced at the Lawrence Livermore National Laboratory.
15  * All rights reserved.
16  * For details, see the LICENSE file.
17  * LLNS Copyright End
18  */
19 #pragma once
20 
21 #include <atomic>
22 #include <map>
23 #include <memory>
24 #include <string>
25 namespace zmq {
26 class context_t;
27 } // namespace zmq
28 
33  private:
34  static std::map<std::string, std::shared_ptr<ZmqContextManager>>
35  contexts;
36  std::string name;
37  std::unique_ptr<zmq::context_t> zcontext;
38  std::atomic<bool> leakOnDelete{true};
40 
42  explicit ZmqContextManager(const std::string& contextName);
43 
44  public:
46  static std::shared_ptr<ZmqContextManager>
47  getContextPointer(const std::string& contextName = std::string{});
49  static zmq::context_t& getContext(const std::string& contextName = std::string{});
51  static void startContext(const std::string& contextName = std::string{});
53  static void closeContext(const std::string& contextName = std::string{});
64  static bool setContextToLeakOnDelete(const std::string& contextName = std::string{});
66  static bool setContextToNotLeakOnDelete(const std::string& contextName = std::string{});
70  const std::string& getName() const { return name; }
72  zmq::context_t& getBaseContext() const { return *zcontext; }
73 };
Definition: ZmqContextManager.h:32
static bool setContextToNotLeakOnDelete(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:87
static void closeContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:68
const std::string & getName() const
Definition: ZmqContextManager.h:70
~ZmqContextManager()
Definition: ZmqContextManager.cpp:96
static bool setContextToLeakOnDelete(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:77
static zmq::context_t & getContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:53
zmq::context_t & getBaseContext() const
Definition: ZmqContextManager.h:72
static std::shared_ptr< ZmqContextManager > getContextPointer(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:37
static void startContext(const std::string &contextName=std::string{})
Definition: ZmqContextManager.cpp:58