#include <grpc/support/port_platform.h>
#ifdef GRPC_USE_EVENT_ENGINE
-#include "src/core/lib/iomgr/event_engine/iomgr.h"
-
#include <grpc/event_engine/event_engine.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/closure.h"
-#include "src/core/lib/iomgr/event_engine/promise.h"
+#include "src/core/lib/iomgr/event_engine/iomgr.h"
#include "src/core/lib/iomgr/iomgr_internal.h"
#include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/iomgr/tcp_server.h"
using ::grpc_event_engine::experimental::DefaultEventEngineFactory;
using ::grpc_event_engine::experimental::EventEngine;
-using ::grpc_event_engine::experimental::Promise;
-// Note: This is a pointer to a shared_ptr, so it's trivially destructible.
-std::shared_ptr<EventEngine>* g_event_engine;
+EventEngine* g_event_engine = nullptr;
-void iomgr_platform_init(void) {
- g_event_engine =
- new std::shared_ptr<EventEngine>(DefaultEventEngineFactory());
-}
+// TODO(nnoble): Instantiate the default EventEngine if none have been provided.
+void iomgr_platform_init(void) { GPR_ASSERT(g_event_engine != nullptr); }
void iomgr_platform_flush(void) {}
void iomgr_platform_shutdown(void) {
- Promise<absl::Status> shutdown_status_promise;
- (*g_event_engine)->Shutdown([&shutdown_status_promise](absl::Status status) {
- shutdown_status_promise.Set(std::move(status));
- });
- auto shutdown_status = shutdown_status_promise.Get();
- GPR_ASSERT(shutdown_status.ok());
delete g_event_engine;
g_event_engine = nullptr;
}
void iomgr_platform_shutdown_background_closure(void) {}
bool iomgr_platform_is_any_background_poller_thread(void) {
- return (*g_event_engine)->IsWorkerThread();
+ return g_event_engine->IsWorkerThread();
}
bool iomgr_platform_add_closure_to_background_poller(
bool grpc_iomgr_run_in_background() { return false; }
grpc_event_engine::experimental::EventEngine* grpc_iomgr_event_engine() {
- return g_event_engine->get();
+ return g_event_engine;
}
+namespace grpc_core {
+
+void SetDefaultEventEngine(
+ std::unique_ptr<grpc_event_engine::experimental::EventEngine>
+ event_engine) {
+ GPR_ASSERT(g_event_engine == nullptr);
+ g_event_engine = event_engine.release();
+}
+
+} // namespace grpc_core
+
#endif // GRPC_USE_EVENT_ENGINE