Realm C++ SDK Version v2.2.0

scheduler.hpp

1
2//
3// Copyright 2022 Realm Inc.
4//
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
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
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.
16//
18
19#ifndef CPPREALM_SCHEDULER_HPP
20#define CPPREALM_SCHEDULER_HPP
21
22#include <functional>
23#include <future>
24#include <queue>
25
26namespace realm {
27 struct scheduler {
28 virtual ~scheduler() = default;
29
30 // Invoke the given function on the scheduler's thread.
31 //
32 // This function can be called from any thread.
33 virtual void invoke(std::function<void()> &&) = 0;
34
35 // Check if the caller is currently running on the scheduler's thread.
36 //
37 // This function can be called from any thread.
38 [[nodiscard]] virtual bool is_on_thread() const noexcept = 0;
39
40 // Checks if this scheduler instance wraps the same underlying instance.
41 // This is up to the platforms to define, but if this method returns true,
42 // caching may occur.
43 virtual bool is_same_as(const scheduler *other) const noexcept = 0;
44
45 // Check if this scheduler actually can support invoke(). Invoking may be
46 // either not implemented, not applicable to a scheduler type, or simply not
47 // be possible currently (e.g. if the associated event loop is not actually
48 // running).
49 //
50 // This function is not thread-safe.
51 [[nodiscard]] virtual bool can_invoke() const noexcept = 0;
52 };
53}
54#endif //CPPREALM_SCHEDULER_HPP
Definition: scheduler.hpp:27