EE445M RTOS
Taken at the University of Texas Spring 2015
thread_structures.h
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 4; -*- */
2 /* Created by Hershal Bhave and Eric Crosson 2015-03-08 */
3 /* Revision history: Look in Git FGT */
4 #ifndef __thread_structrues__
5 #define __thread_structrues__
6 
7 #include "libstd/defines.h"
8 
17 typedef uint32_t tick_t;
18 
20 #define SEMAPHORE_DEFAULT_VALUE 0
21 
23 typedef int8_t semaphore_t;
24 
26 #define spinlock_until(blocker) \
27  while (!(*blocker))
28 
30 #define sem_init_(sem, initial_value) \
31  semaphore_t sem; \
32  sem = initial_value
33 
36 #define sem_guard(sem) \
37  if(!semaphore_blocked(sem))
38 
41 #define sem_take(sem) \
42  atomic ( \
43  --sem; \
44  /* TODO: wake thread */ \
45  )
46 
47 /* TODO: define */
48 #define sem_check(sem)
49 
51 #define sem_init(sem) \
52  sem_init_(sem, SEMAPHORE_DEFAULT_VALUE)
53 
56 #define sem_signal(sem) \
57  sem_post(sem)
58 
64 #define sem_post(sem) \
65  atomic ( \
66  ++sem; \
67  /* TODO: wake thread */ \
68  )
69 
73 #define sem_wait(sem) \
74  while (semaphore_blocked(sem)) { \
75  os_surrender_context(); \
76  } \
77  atomic ( \
78  --sem; \
79  )
80 
83 #define semaphore_blocked(sem) \
84  (sem <= 0)
85 
88 #define thread_blocked(tcb_t) \
89  (tcb_t->sem != NULL)
90 
91 
93 typedef uint8_t priority_t;
94 
95 typedef int32_t deadline_t;
96 typedef int32_t microseconds_t; /* smallest divisible task time */
97 
98 typedef enum {
101 } DEADLINE_TYPE;
102 
104 typedef struct tcb_t {
105 
107  int32_t *sp;
108 
110  struct tcb_t *next;
112  struct tcb_t *prev;
113 
115  immutable int32_t id;
116 
118 
123 
124  /* Semaphore value of this thread.
125  * sem == NULL :: unblocked
126  * sem contains a pointer's address :: blocked
127  */
129 
131  /* int32_t sleep_timer;
132 
134  /* int8_t priority; */
135 } tcb_t;
136 
137 typedef struct sched_task {
142 
143  void* pool;
144 
145  /* For use by utlist library */
146  struct sched_task *next;
147  struct sched_task *prev;
150  int id;
151 } sched_task;
152 
153 typedef struct sched_task_pool {
156 
157  /* allow this structure to be hashable */
158  /* UT_hash_handle hh; */
159  /* Allow this structure to be linked-list-able */
161  int id;
163 
164 #endif
165 
166 /* End Doxygen group
167  * @}
168  */
struct sched_task * pri_prev
int32_t deadline_t
immutable int32_t id
DEADLINE_TYPE
#define immutable
Definition: nexus.h:9
DEADLINE_TYPE seriousness
void(* task_t)()
Definition: defines.h:21
int8_t semaphore_t
struct sched_task * prev
struct sched_task sched_task
struct sched_task_pool sched_task_pool
int32_t microseconds_t
struct tcb_t * prev
frequency_t deadline
struct tcb_t tcb_t
priority_t priority
struct sched_task * pri_next
struct sched_task_pool * next
uint32_t tick_t
int32_t * sp
uint8_t priority_t
sched_task * queue
task_t entry_point
struct sched_task * next
struct tcb_t * next
int32_t frequency_t
Definition: defines.h:24
tick_t absolute_deadline
semaphore_t * sem
struct sched_task_pool * prev