-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThread.h
More file actions
44 lines (31 loc) · 1.22 KB
/
Thread.h
File metadata and controls
44 lines (31 loc) · 1.22 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
/*****************************************************************************
* Simplest kernel for iterative multithtreading *
* Autor: Vyacheslav Azarov <slavaza63@gmail.com> *
* Licensed by GNU GPL V3 from 29 June 2007 *
* ***************************************************************************/
#ifndef _THREAD_H_
#define _THREAD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
extern const void * MAIN; // dummy state pointer of main thread
extern void * thread; // pointer to current thread state
void spawn(void * state, void (*start)(void)); // creation new thread
// switching control
void hold(void); // disable thread switching and quantize
void schedule(void); // enable thread swithing by yield only
void quantize(void); // enable 1 ms quantizing and yield
// explicit swithing
void yield(void); // immediately switchng to next thread
// mutual exclussion
bool grab(void ** barrier, unsigned long timeout);
// returns true if the barrier is blocked or false if the
// timeout has expired
bool loose(void ** barrier);
// returns true if barrier unblocked
#ifdef __cplusplus
}
#endif
#endif