morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
io_loop.hpp File Reference
#include <cassert>
#include <core/async/ExecutorContext.hpp>
#include <core/net/EventLoop.hpp>
#include <core/net/PlatformLoop.hpp>
#include <cstdint>
#include <exception>
#include <future>
#include <memory>
#include <type_traits>
#include <utility>
#include "executor.hpp"
#include "logger.hpp"
#include "profiler.hpp"
#include <thread>

Go to the source code of this file.

Classes

class  morph::exec::IoLoop
 Owns a core::net::PlatformLoop and, for IoLoopDriver::OwnThread natively, the one thread that runs it. More...
class  morph::exec::IoLoop::Weak
 A non-owning handle that posts to the loop only while it exists. More...

Enumerations

enum class  morph::exec::IoLoopDriver : std::uint8_t { OwnThread , Caller }
 Who turns an IoLoop. More...

Detailed Description

IoLoop — the one I/O loop an application runs, and the owner of every socket, timer and probe built on it.

morph::net::SocketBackend, morph::net::SocketServer, TimeoutScheduler and offline::NetworkMonitor own no thread. Each keeps its state on a core::net::PlatformLoop and touches it only in tasks that loop runs; its public verbs post to the loop and return. An application constructs one IoLoop and hands it to every one of them, so one thread carries every connection, every deadline and the connectivity probe.

Who turns the loop
  • IoLoopDriver::OwnThread (native default): the IoLoop owns one thread that runs the loop until the IoLoop is destroyed.
  • IoLoopDriver::Caller: no thread is started. The constructing thread is the loop's and turns it — loop().runOnce(), loop().runUntilIdle() or a blockOn() — so a terminal UI and its sockets, timers and bridge callbacks share that one thread. No other thread may turn it.
  • Single-threaded WebAssembly (__EMSCRIPTEN__ without __EMSCRIPTEN_PTHREADS__): there is no thread to start whichever driver is asked for. The loop is host-driven — the browser's timer pumps it — and the one thread there is is always the loop's, so a verb runs its body inline.

Definition in file io_loop.hpp.

Enumeration Type Documentation

◆ IoLoopDriver

enum class morph::exec::IoLoopDriver : std::uint8_t
strong

Who turns an IoLoop.

Enumerator
OwnThread 

The IoLoop starts one thread that runs the loop until it is destroyed.

Caller 

No thread is started: the constructing thread turns the loop, and is the loop's between turns as well as inside them. No other thread may turn it; a debug build asserts when a task posted to it runs on another.

Definition at line 52 of file io_loop.hpp.