blob: 343e8d5e3b6156d10b16d1954b22aba3d583531e (
plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#pragma once
#include "proc/spinlock.h"
#include "util/list.h"
/*===========
* Structures
*==========*/
/*
* Queue structure for kthreads
* Note that ktqueue functions are private - managing the queue
* should be done within sched.c, or using public functions
*/
typedef struct ktqueue
{
list_t tq_list;
size_t tq_size;
} ktqueue_t;
/*
* Macro to initialize a ktqueue. See sched_queue_init for how the
* queue should be initialized in your code.
*/
#define KTQUEUE_INITIALIZER(ktqueue) \
{ \
.tq_list = LIST_INITIALIZER((ktqueue).tq_list), \
}
/*
* kthread declaration to make function signatures happy
*/
struct kthread;
/*==========
* Functions
*=========*/
/**
* Runs a new thread from the run queue.
*
* @param queue the queue to place curthr on
*/
void sched_switch(ktqueue_t *queue);
/**
* Helps with context switching.
*/
void core_switch();
/**
* Yields the CPU to another runnable thread.
*/
void sched_yield();
/**
* Enables a thread to be selected by the scheduler to run.
*
* @param thr the thread to make runnable
*/
void sched_make_runnable(struct kthread *thr);
/**
* Causes the current thread to enter into an uncancellable sleep on
* the given queue.
*
* @param q the queue to sleep on
* @param lock optional lock for release in another context
*/
void sched_sleep_on(ktqueue_t *q);
/**
* Causes the current thread to enter into a cancellable sleep on the
* given queue.
*
* @param queue the queue to sleep on
* @param lock optional lock for release in another context
* @return -EINTR if the thread was cancelled and 0 otherwise
*/
long sched_cancellable_sleep_on(ktqueue_t *queue);
/**
* Wakes up a thread from q.
*
* @param q queue
* @param thrp if an address is provided, *thrp is set to the woken up thread
*
*/
void sched_wakeup_on(ktqueue_t *q, struct kthread **thrp);
/**
* Wake up all threads running on the queue.
*
* @param q the queue to wake up threads from
*/
void sched_broadcast_on(ktqueue_t *q);
/**
* Cancel the given thread from the queue it sleeps on.
*
* @param the thread to cancel sleep from
*/
void sched_cancel(struct kthread *thr);
/**
* Initializes a queue.
*
* @param queue the queue
*/
void sched_queue_init(ktqueue_t *queue);
/**
* Returns true if the queue is empty.
*
* @param queue the queue
* @return true if the queue is empty
*/
long sched_queue_empty(ktqueue_t *queue);
/**
* Functions for managing the current thread's preemption status.
*/
void preemption_disable();
void preemption_enable();
void preemption_reset();
long preemption_enabled();
|