upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/dev_status.h
diff options
context:
space:
mode:
authoraslan2142 <jan.trencansky@protonmail.com>2026-11-26 00:02:32 +0100
committerGitHub <noreply@github.com>2026-11-26 00:02:32 +0100
commitffcfe68f12891826a2b15e19f31149d8bb44e778 (patch)
tree6a26540f86309861de4b8c254bffd50e070cb4d1 /runtime/src/dev_status.h
parenta0723a9e9261705f3d6d6619ee88b172fd0fc90a (diff)
parentf6cb4aedfc01d8e8421122643ea668ae71a6abf5 (diff)
Merge pull request #2137 from Snooozs/dev-overlay
runtime: LEONIDA_DEV_OVERLAY shows what the runtime is doing over the title's window (RT-DEV-OVERLAY)
Diffstat (limited to 'runtime/src/dev_status.h')
-rw-r--r--runtime/src/dev_status.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/runtime/src/dev_status.h b/runtime/src/dev_status.h
new file mode 100644
index 000000000..3efc9bf4f
--- /dev/null
+++ b/runtime/src/dev_status.h
@@ -0,0 +1,51 @@
1#pragma once
2// What the runtime is building now, for the dev overlay (dev_overlay.h). Always on: two relaxed atomics a build, and a
3// short copy under a lock for the name.
4#include <algorithm>
5#include <atomic>
6#include <cstdint>
7#include <cstring>
8#include <mutex>
9#include <string>
10
11namespace leonida::dev_status {
12
13struct Builds {
14 std::atomic<unsigned> active{0};
15 std::atomic<std::uint64_t> done{0};
16
17 std::string last() {
18 std::lock_guard lock(mutex_);
19 return name_;
20 }
21 void name(const char* text) {
22 std::lock_guard lock(mutex_);
23 const std::size_t n = std::min(std::strlen(text), sizeof name_ - 1);
24 std::memcpy(name_, text, n);
25 name_[n] = 0;
26 }
27
28private:
29 std::mutex mutex_;
30 char name_[96]{};
31};
32inline Builds& builds() {
33 static Builds instance;
34 return instance;
35}
36
37// One pipeline build, from construction to destruction.
38struct Build {
39 explicit Build(const char* name) {
40 builds().name(name);
41 builds().active.fetch_add(1, std::memory_order_relaxed);
42 }
43 ~Build() {
44 builds().active.fetch_sub(1, std::memory_order_relaxed);
45 builds().done.fetch_add(1, std::memory_order_relaxed);
46 }
47 Build(const Build&) = delete;
48 Build& operator=(const Build&) = delete;
49};
50
51} // namespace leonida::dev_status