summaryrefslogtreecommitdiff
path: root/src/user/knob/quit.c
blob: a2ef5aaee955392a8bb0cac6e914a6e9b822d42b (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
#include <pland/syscall.h>
#include <knob/heap.h>

struct quit_list_node {
  struct quit_list_node *prev;
  void (*f)();
};

static struct quit_list_node head = {
  .f = &_exit_task
};

static struct quit_list_node *last = &head;

void on_quit(void (*run_f)()) {
  struct quit_list_node *new = get_block(sizeof(struct quit_list_node));
  new->prev = last;
  new->f = run_f;
  last = new;
}

__attribute__ ((noreturn))
void quit() {
  struct quit_list_node *node = last;
  while (1) {
    node->f();
    node = node->prev;
  }
}