-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathworker_thread.c
More file actions
78 lines (63 loc) · 2.24 KB
/
Copy pathworker_thread.c
File metadata and controls
78 lines (63 loc) · 2.24 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <stdlib.h>
#include <threads.h>
#include "current_sandbox.h"
#include "local_cleanup_queue.h"
#include "local_runqueue.h"
#include "local_runqueue_list.h"
#include "local_runqueue_minheap.h"
#include "panic.h"
#include "priority_queue.h"
#include "runtime.h"
#include "scheduler.h"
#include "tenant_functions.h"
#include "worker_thread.h"
/***************************
* Worker Thread State *
**************************/
/* context of the runtime thread before running sandboxes or to resume its "main". */
thread_local struct arch_context worker_thread_base_context;
/* Used to index into global arguments and deadlines arrays */
thread_local int worker_thread_idx;
/* Used to track tenants' timeouts */
thread_local struct priority_queue *worker_thread_timeout_queue;
/***********************
* Worker Thread Logic *
**********************/
/**
* The entry function for sandbox worker threads
* Initializes thread-local state, unmasks signals, sets up epoll loop and
* @param argument - argument provided by pthread API. We set to -1 on error
*/
void *
worker_thread_main(void *argument)
{
/* Set base context as running */
worker_thread_base_context.variant = ARCH_CONTEXT_VARIANT_RUNNING;
/* Index was passed via argument */
worker_thread_idx = *(int *)argument;
/* Set my priority */
// runtime_set_pthread_prio(pthread_self(), 2);
pthread_setschedprio(pthread_self(), -20);
scheduler_runqueue_initialize();
/* Initialize Cleanup Queue */
local_cleanup_queue_initialize();
if (scheduler == SCHEDULER_MTDS) {
worker_thread_timeout_queue = priority_queue_initialize(RUNTIME_MAX_TENANT_COUNT, false,
tenant_timeout_get_priority,
tenant_timeout_get_index_ptr);
}
software_interrupt_unmask_signal(SIGFPE);
software_interrupt_unmask_signal(SIGSEGV);
/* Unmask signals, unless the runtime has disabled preemption */
if (runtime_preemption_enabled) {
software_interrupt_unmask_signal(SIGALRM);
software_interrupt_unmask_signal(SIGUSR1);
}
scheduler_idle_loop();
panic("Worker Thread unexpectedly completed idle loop.");
}