1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2015 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
25 class RealmCoordinator;
27 class ExternalCommitHelper {
29 ExternalCommitHelper(RealmCoordinator& parent);
30 ~ExternalCommitHelper();
35 // A RAII holder for a file descriptor which automatically closes the wrapped
36 // fd when it's deallocated
40 ~FdHolder() { close(); }
41 operator int() const { return m_fd; }
43 FdHolder& operator=(int newFd) {
53 FdHolder& operator=(FdHolder const&) = delete;
54 FdHolder(FdHolder const&) = delete;
59 RealmCoordinator& m_parent;
61 // The listener thread
62 std::future<void> m_thread;
64 // Pipe which is waited on for changes and written to when there is a new
65 // commit to notify others of. When using a named pipe m_notify_fd is
66 // read-write and m_notify_fd_write is unused; when using an anonymous pipe
67 // (on tvOS) m_notify_fd is read-only and m_notify_fd_write is write-only.
69 FdHolder m_notify_fd_write;
71 // File descriptor for the kqueue
74 // The two ends of an anonymous pipe used to notify the kqueue() thread that
75 // it should be shut down.
76 FdHolder m_shutdown_read_fd;
77 FdHolder m_shutdown_write_fd;