-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e06a73c
commit 9f0dc47
Showing
18 changed files
with
434 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
include/cpprealm/internal/scheduler/realm_core_scheduler.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef CPPREALM_REALM_CORE_SCHEDULER_HPP | ||
#define CPPREALM_REALM_CORE_SCHEDULER_HPP | ||
|
||
#include <cpprealm/scheduler.hpp> | ||
|
||
namespace realm { | ||
namespace util { | ||
class Scheduler; | ||
} | ||
} | ||
namespace realm::internal { | ||
|
||
/** | ||
* A type erased scheduler used for wrapping default scheduler implementations from RealmCore. | ||
*/ | ||
struct realm_core_scheduler final : public scheduler { | ||
/** | ||
* Invoke the given function on the scheduler's thread. | ||
* This function can be called from any thread. | ||
*/ | ||
void invoke(std::function<void()> &&fn) final; | ||
|
||
/** | ||
* Check if the caller is currently running on the scheduler's thread. | ||
* This function can be called from any thread. | ||
*/ | ||
[[nodiscard]] bool is_on_thread() const noexcept final; | ||
|
||
/** | ||
* Checks if this scheduler instance wraps the same underlying instance. | ||
* This is up to the platforms to define, but if this method returns true, | ||
* caching may occur. | ||
*/ | ||
bool is_same_as(const scheduler *other) const noexcept final; | ||
|
||
/** | ||
* Check if this scheduler actually can support invoke(). Invoking may be | ||
* either not implemented, not applicable to a scheduler type, or simply not | ||
* be possible currently (e.g. if the associated event loop is not actually | ||
* running). | ||
* | ||
* This function is not thread-safe. | ||
*/ | ||
[[nodiscard]] bool can_invoke() const noexcept final; | ||
~realm_core_scheduler() final = default; | ||
realm_core_scheduler() = delete; | ||
explicit realm_core_scheduler(std::shared_ptr<util::Scheduler> s) : s(std::move(s)) {} | ||
operator std::shared_ptr<util::Scheduler>(); | ||
private: | ||
std::shared_ptr<util::Scheduler> s; | ||
}; | ||
|
||
std::shared_ptr<util::Scheduler> create_scheduler_shim(const std::shared_ptr<scheduler>& s); | ||
} // namespace realm::internal | ||
|
||
#endif//CPPREALM_REALM_CORE_SCHEDULER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2024 Realm Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the >License>); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an >AS IS> BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef CPPREALM_DEFAULT_SCHEDULERS_HPP | ||
#define CPPREALM_DEFAULT_SCHEDULERS_HPP | ||
|
||
#include <cpprealm/scheduler.hpp> | ||
|
||
#if __has_include(<cpprealm/util/config.h>) | ||
#include <cpprealm/util/config.h> | ||
#endif | ||
|
||
#if defined(REALM_HAVE_UV) && REALM_HAVE_UV | ||
typedef struct uv_loop_s uv_loop_t; | ||
#endif | ||
|
||
namespace realm::default_scheduler { | ||
/** | ||
* Tries to choose a built in scheduler as default for the platform | ||
* Current options are: | ||
* - CFRunLoop for Apple platforms | ||
* - UV for Linux and Windows | ||
* - ALooper for Android | ||
* If no suitable scheduler is available a generic scheduler will be provided. | ||
*/ | ||
std::shared_ptr<scheduler> make_platform_default(); | ||
|
||
/** | ||
* Register a factory function which can produce custom schedulers when | ||
* `scheduler::make_default()` is called. This function is not thread-safe | ||
* and must be called before any schedulers are created. | ||
*/ | ||
void set_default_factory(std::function<std::shared_ptr<scheduler>()>&& factory_fn); | ||
|
||
/** | ||
* Create a new instance of the scheduler type returned by the default | ||
* scheduler factory. By default, the factory function is | ||
* `scheduler::make_platform_default()`. | ||
*/ | ||
std::shared_ptr<scheduler> make_default(); | ||
} // namespace realm | ||
|
||
#endif//CPPREALM_DEFAULT_SCHEDULERS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.