uvco 0.1
Loading...
Searching...
No Matches
loop.h
Go to the documentation of this file.
1// uvco (c) 2024 Lewin Bormann. See LICENSE for specific terms.
2
3#pragma once
4
5#include <uv.h>
6
8
9#include <coroutine>
10#include <memory>
11
12namespace uvco {
13
16
26class Loop {
27public:
28 // Don't use this constructor. Use `runMain()` instead.
30
31 Loop(const Loop &) = delete;
32 Loop(Loop &&) = delete;
33 Loop &operator=(const Loop &) = delete;
34 Loop &operator=(Loop &&) = delete;
35 ~Loop();
36
38 [[nodiscard]] uv_loop_t *uvloop() const;
39
40 // Retrieve the currently active global scheduler associated with the default
41 // loop.
42 static void enqueue(std::coroutine_handle<> handle);
43
44private:
45 // The default loop is the only loop that can be created. It is set/unset by
46 // the constructor/destructor.
49
50 friend void runLoop(Loop &);
53 void run();
54 // Run a single turn of the loop.
55 void runOne();
56
57 // Loop and scheduler should be kept at the same
58 // place in memory.
59 std::unique_ptr<uv_loop_t> loop_;
60 std::unique_ptr<Scheduler> scheduler_;
61};
62
64
65} // namespace uvco
Definition loop.h:26
void runOne()
Definition loop.cc:52
static Scheduler & currentScheduler()
Definition loop.cc:66
Loop & operator=(const Loop &)=delete
Loop(Loop &&)=delete
uv_loop_t * uvloop() const
Get a non-owned pointer to the loop.
Definition loop.cc:62
std::unique_ptr< uv_loop_t > loop_
Definition loop.h:59
~Loop()
Definition loop.cc:32
Loop(const Loop &)=delete
std::unique_ptr< Scheduler > scheduler_
Definition loop.h:60
Loop & operator=(Loop &&)=delete
static Loop * defaultLoop
Definition loop.h:47
Loop(Scheduler::RunMode mode=Scheduler::RunMode::Deferred)
Definition loop.cc:17
friend void runLoop(Loop &)
Definition run.cc:32
static void enqueue(std::coroutine_handle<> handle)
Definition loop.cc:73
void run()
Definition loop.cc:54
Definition scheduler.h:43
RunMode
Definition scheduler.h:45
Definition async_work.cc:17