aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/vm/RuntimeFiber.cpp
blob: 838f9daef72d2d98e376323f9b0c7735a6c53457 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "RuntimeFiber.hpp"

#include <cassert>
#include <optional>

#include "RuntimeProcess.hpp" // IWYU pragma: keep
#include "Stacktrace.hpp"
#include <lauf/runtime/process.h>
#include <lauf/runtime/stacktrace.h>

using namespace OpenVic::Vm;

const lauf_runtime_value* RuntimeFiberRef::get_vstack_base() const {
   assert(is_valid());
   return lauf_runtime_get_vstack_base(_handle);
}

RuntimeFiber::~RuntimeFiber() {
   destroy();
}

std::optional<Stacktrace> RuntimeFiber::get_stacktrace() const {
   assert(is_valid());
   auto result = lauf_runtime_get_stacktrace(*_process, _handle);
   if (result == nullptr) {
      return std::nullopt;
   }
   return std::make_optional<Stacktrace>(result);
}

std::optional<RuntimeFiberRef> RuntimeFiber::get_parent() {
   assert(is_valid());
   auto result = lauf_runtime_get_fiber_parent(*_process, _handle);
   if (result == nullptr) {
      return std::nullopt;
   }
   return result;
}

const lauf_runtime_value* RuntimeFiber::get_vstack_ptr() const {
   assert(is_valid());
   return lauf_runtime_get_vstack_ptr(*_process, _handle);
}

bool RuntimeFiber::resume(
   const lauf_runtime_value* input, size_t input_count, lauf_runtime_value* output, size_t output_count
) {
   assert(is_valid());
   return lauf_runtime_resume(*_process, _handle, input, input_count, output, output_count);
}

bool RuntimeFiber::resume_until_completion(
   const lauf_runtime_value* input, size_t input_count, lauf_runtime_value* output, size_t output_count
) {
   assert(is_valid());
   return lauf_runtime_resume_until_completion(*_process, _handle, input, input_count, output, output_count);
}

void RuntimeFiber::destroy() {
   if (!is_valid()) {
      return;
   }
   lauf_runtime_destroy_fiber(*_process, _handle);
   _handle = nullptr;
}