ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ZMQContext.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "io/rpc/ZMQContext.h"
9 
10 #include <mutex>
11 #include <zmq.hpp>
12 
13 namespace {
14 std::shared_ptr<zmq::context_t> context_ptr;
15 std::mutex context_ptr_mutex;
16 } // namespace
17 
18 namespace cloudViewer {
19 namespace io {
20 namespace rpc {
21 
22 std::shared_ptr<zmq::context_t> GetZMQContext() {
23  std::lock_guard<std::mutex> lock(context_ptr_mutex);
24  if (!context_ptr) {
25  context_ptr = std::make_shared<zmq::context_t>();
26  }
27  return context_ptr;
28 }
29 
31  std::lock_guard<std::mutex> lock(context_ptr_mutex);
32  context_ptr.reset();
33 }
34 
35 } // namespace rpc
36 } // namespace io
37 } // namespace cloudViewer
std::shared_ptr< zmq::context_t > GetZMQContext()
Returns the zeromq context for this process.
Definition: ZMQContext.cpp:22
Generic file read and write utility for python interface.