Flow-IPC 3.0.0
Flow-IPC project: Full implementation reference.
ez_rpc_kj_io.cpp
Go to the documentation of this file.
1/* Flow-IPC: Shared Memory
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
20
22{
23
24// Static initializers.
25
26thread_local boost::weak_ptr<Ez_rpc_kj_io> Ez_rpc_kj_io::s_this_thread_obj_observer; // Empty to start.
27
28// Implementations.
29
31 m_kj_io(kj::setupAsyncIo())
32{
33 // Yep.
34}
35
36Ez_rpc_kj_io::Ptr Ez_rpc_kj_io::this_thread_obj() // Static.
37{
38 auto this_thread_obj_ptr = s_this_thread_obj_observer.lock();
39 if (!this_thread_obj_ptr)
40 {
41 /* Either: (In this thread) We are being called for the first time ever; so the below Ez_rpc_kj_io ctor call has not
42 * been executed, and we've never returned a shared_ptr (Ptr) to it, hence observer is empty -- was not
43 * observing anything yet.
44 * Or: (In this thread) We are being called not the first time; and are observing a shared_ptr (Ptr)
45 * pointing to result of Ez_rpc_kj_io ctor call; but since we returned it, they let that shared_ptr group reach
46 * ref-count zero; so it was deleted.
47 * Either way: Time to make a new one and observe it (and return it). */
48 s_this_thread_obj_observer = this_thread_obj_ptr = Ptr{new Ez_rpc_kj_io}; // Private ctor; cannot use make_shared().
49 }
50 /* else { (In this thread) We are being called not the first time; and are observing a shared_ptr (Ptr)
51 * pointing to result of setupAsyncIo(); and since we returned it, they still have 1+ objects in that group
52 * around; so it exists still. So we can create (and return) a new member of that shared_ptr group. } */
53 return this_thread_obj_ptr;
54}
55
56} // namespace ipc::transport::struc::shm::rpc
Internal-use thread-local singleton-style access to a kj::AsyncIoContext which, for each given thread...
Ez_rpc_kj_io()
Private ctor that sets m_kj_io to its permanent value, kj::setupAsyncIo().
static Ptr this_thread_obj()
Returns a handle to a *this which shall contain a live AsyncIoContext m_kj_io; it will continue to be...
static thread_local boost::weak_ptr< Ez_rpc_kj_io > s_this_thread_obj_observer
Weak-pointer observer to the last-retured in this thread (via this_thread_obj()) Ptr; or null.
Provides Flow-IPC's integration with Cap'n Proto's Remote Procedure Call (RPC) layer,...