|
1 | 1 | #include "config.h" |
2 | 2 | #include <wtf/RunLoop.h> |
3 | 3 |
|
| 4 | + |
4 | 5 | namespace WTF { |
5 | 6 |
|
| 7 | +// Functions exported by Timer.zig |
| 8 | +extern "C" __attribute__((weak)) RunLoop::TimerBase::Bun__WTFTimer* WTFTimer__create(RunLoop::TimerBase*); |
| 9 | +extern "C" __attribute__((weak)) void WTFTimer__update(RunLoop::TimerBase::Bun__WTFTimer*, double seconds, bool repeat); |
| 10 | +extern "C" __attribute__((weak)) void WTFTimer__deinit(RunLoop::TimerBase::Bun__WTFTimer*); |
| 11 | +extern "C" __attribute__((weak)) bool WTFTimer__isActive(const RunLoop::TimerBase::Bun__WTFTimer*); |
| 12 | +extern "C" __attribute__((weak)) double WTFTimer__secondsUntilTimer(const RunLoop::TimerBase::Bun__WTFTimer*); |
| 13 | +extern "C" __attribute__((weak)) void WTFTimer__cancel(RunLoop::TimerBase::Bun__WTFTimer*); |
| 14 | + |
6 | 15 | RunLoop::TimerBase::TimerBase(Ref<RunLoop>&& loop) |
7 | 16 | : m_runLoop(WTFMove(loop)) |
| 17 | + // check if the zig function is actually available (it won't be in JSC shell, since that doesn't |
| 18 | + // link Bun's zig code) |
| 19 | + , m_zigTimer(&WTFTimer__create ? WTFTimer__create(this) : nullptr) |
8 | 20 | { |
9 | 21 | } |
10 | 22 |
|
11 | 23 | RunLoop::TimerBase::~TimerBase() |
12 | 24 | { |
| 25 | + if (&WTFTimer__deinit) { |
| 26 | + ASSERT(m_zigTimer); |
| 27 | + WTFTimer__deinit(m_zigTimer); |
| 28 | + } |
13 | 29 | } |
14 | 30 |
|
15 | | -void RunLoop::TimerBase::stop() {} |
| 31 | +void RunLoop::TimerBase::stop() { |
| 32 | + if (&WTFTimer__cancel) { |
| 33 | + ASSERT(m_zigTimer); |
| 34 | + WTFTimer__cancel(m_zigTimer); |
| 35 | + } |
| 36 | +} |
16 | 37 |
|
17 | | -bool RunLoop::TimerBase::isActive() const {} |
| 38 | +bool RunLoop::TimerBase::isActive() const { |
| 39 | + if (&WTFTimer__isActive) { |
| 40 | + ASSERT(m_zigTimer); |
| 41 | + return WTFTimer__isActive(m_zigTimer); |
| 42 | + } |
| 43 | + return false; |
| 44 | +} |
18 | 45 |
|
19 | | -Seconds RunLoop::TimerBase::secondsUntilFire() const {} |
| 46 | +Seconds RunLoop::TimerBase::secondsUntilFire() const { |
| 47 | + if (&WTFTimer__secondsUntilTimer) { |
| 48 | + ASSERT(m_zigTimer); |
| 49 | + return Seconds(WTFTimer__secondsUntilTimer(m_zigTimer)); |
| 50 | + } |
| 51 | + return -1.0_s; |
| 52 | +} |
| 53 | + |
| 54 | +void RunLoop::TimerBase::start(Seconds interval, bool repeat) { |
| 55 | + if (&WTFTimer__update) { |
| 56 | + ASSERT(m_zigTimer); |
| 57 | + WTFTimer__update(m_zigTimer, interval.value(), repeat); |
| 58 | + } |
| 59 | +} |
20 | 60 |
|
21 | | -void RunLoop::TimerBase::start(Seconds interval, bool repeat) {} |
| 61 | +extern "C" void WTFTimer__fire(RunLoop::TimerBase* timer) { |
| 62 | + timer->fired(); |
| 63 | +} |
22 | 64 |
|
23 | 65 | // probably more Bun-specific TimerBase methods |
24 | 66 |
|
25 | 67 | RunLoop::RunLoop() |
26 | 68 | { |
27 | 69 | } |
28 | 70 |
|
29 | | -RunLoop::~RunLoop() {} |
| 71 | +RunLoop::~RunLoop() |
| 72 | +{ |
| 73 | +} |
30 | 74 |
|
31 | | -void RunLoop::run() {} |
| 75 | +void RunLoop::run() { |
| 76 | + ASSERT_NOT_REACHED(); |
| 77 | +} |
32 | 78 |
|
33 | | -void RunLoop::stop() {} |
| 79 | +void RunLoop::stop() { |
| 80 | + ASSERT_NOT_REACHED(); |
| 81 | +} |
34 | 82 |
|
35 | | -void RunLoop::wakeUp() {} |
| 83 | +void RunLoop::wakeUp() { |
| 84 | + ASSERT_NOT_REACHED(); |
| 85 | +} |
36 | 86 |
|
37 | | -RunLoop::CycleResult RunLoop::cycle(RunLoopMode mode) {} |
| 87 | +RunLoop::CycleResult RunLoop::cycle(RunLoopMode mode) { |
| 88 | + (void) mode; |
| 89 | + ASSERT_NOT_REACHED(); |
| 90 | + return RunLoop::CycleResult::Stop; |
| 91 | +} |
38 | 92 |
|
39 | 93 | } // namespace WTF |
0 commit comments