-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3140_concur.h
More file actions
116 lines (83 loc) · 3.37 KB
/
3140_concur.h
File metadata and controls
116 lines (83 loc) · 3.37 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
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
/*************************************************************************
*
* Copyright (c) 2015 Cornell University
* Computer Systems Laboratory
* Cornell University, Ithaca, NY 14853
* All Rights Reserved
*
* $Id$
*
**************************************************************************
*/
#ifndef __3140_CONCUR_H__
#define __3140_CONCUR_H__
#include <stdlib.h>
#include <MK64F12.h>
struct process_state;
typedef struct process_state process_t;
/* opaque definition of process type; you must provide this
implementation.
To do this, write code similar to the following in your process.c:
struct process_state {
int var1;
struct process_state* some_pointer;
};
*/
/*------------------------------------------------------------------------
THE FOLLOWING FUNCTIONS MUST BE CREATED IN process.c.
------------------------------------------------------------------------*/
/* ====== Concurrency ====== */
/* Called by the runtime system to select another process.
"cursp" = the stack pointer for the currently running process
cursp will be NULL when first starting the scheduler, and when a process terminates
Return the stack pointer for the new process to run, or NULL to exit the scheduler.
*/
extern unsigned int * process_select (unsigned int * cursp);
/* the currently running process. current_process must be NULL if no process is running,
otherwise it must point to the process_t of the currently running process
*/
extern process_t * current_process;
extern process_t * process_queue;
/* Starts up the concurrent execution */
void process_start (void);
/* Create a new process. Return -1 if creation failed */
int process_create (void (*f)(void), int n);
/*------------------------------------------------------------------------
You may use the following functions that we have provided
------------------------------------------------------------------------*/
/* This function can ONLY BE CALLED if interrupts are disabled.
This function switches execution to the next ready process, and is
also the entry point for the timer interrupt.
Implemented in 3140.s
*/
extern void process_blocked (void);
/*
This function is called by user code indirectly when the process
terminates. This is handled by stack manipulation.
You should not need to call this function yourself.
Implemented in 3140.s
Used in 3140_concur.c
*/
extern void process_terminated (void);
/* This function can ONLY BE CALLED if interrupts are disabled. It
does not modify interrupt flags.
Allocates a stack for a process, and sets up the stack's initial state
Implemented in 3140_concur.c
*/
unsigned int * process_stack_init (void (*f)(void), int n);
/* This function can ONLY BE CALLED if interrupts are disabled. It
does not modify interrupt flags.
Frees a stack allocated in process_init. Must be called with the same value
of n as process_init
Implemented in 3140_concur.c
*/
void process_stack_free (unsigned int *sp, int n);
/*
This function starts the concurrency by using the timer interrupt
context switch routine to call the first ready process.
The function also gracefully exits once the process_select()
function returns 0.
Implemented in 3140.s
*/
extern void process_begin (void);
#endif