1
/*
2
* \brief Thread facility
3
* \author Christian Helmuth
4
* \date 2008-10-20
5
*/
6
7
/*
8
* Copyright (C) 2008-2013 Genode Labs GmbH
9
*
10
* This file is part of the Genode OS framework, which is distributed
11
* under the terms of the GNU General Public License version 2.
12
*/
13
14
#
ifndef _INCLUDE__DDE_KIT__THREAD_H_
15
#
define _INCLUDE__DDE_KIT__THREAD_H_
16
17
#
include <dde_kit/lock.h>
18
19
struct
dde_kit_thread;
20
21
/**
22
* Create thread
23
*
24
* \param fun thread function
25
* \param arg argument to thread function, set to NULL if not needed
26
* \param name thread name
27
*
28
* \return thread handle
29
*
30
* Create a new thread running the specified function with argument arg. The
31
* thread is assigned the given name.
32
*
33
* All DDE kit threads support thread-local storage where one data pointer may
34
* be stored and retrieved.
35
*/
36
struct
dde_kit_thread *
dde_kit_thread_create(
void (
*
fun)
(
void *
)
,
void *
arg,
const
char *
name)
;
37
38
/**
39
* Adopt calling as DDE kit thread
40
*
41
* \param name thread name
42
*
43
* \return thread handle
44
*/
45
struct
dde_kit_thread *
dde_kit_thread_adopt_myself(
const
char *
name)
;
46
47
/**
48
* Get handle of current thread
49
*
50
* \return thread handle
51
*/
52
struct
dde_kit_thread *
dde_kit_thread_myself(
void)
;
53
54
/**
55
* Get thread-local data of a specific thread
56
*
57
* \param thread thread handle
58
*
59
* \return thread-local data of this thread
60
*/
61
void *
dde_kit_thread_get_data(
struct
dde_kit_thread *
thread
)
;
62
63
/**
64
* Get thread-local data of current thread
65
*
66
* \return thread-local data of current thread
67
*/
68
void *
dde_kit_thread_get_my_data(
void)
;
69
70
/**
71
* Set thread-local data of specific thread
72
*
73
* \param thread thread handle
74
* \param data thread-local data pointer
75
*/
76
void
dde_kit_thread_set_data(
struct
dde_kit_thread *
thread
,
void *
data
)
;
77
78
/**
79
* Set thread-local data of current thread
80
*
81
* \param data thread-local data pointer
82
*/
83
void
dde_kit_thread_set_my_data(
void *
data
)
;
84
85
/**
86
* Sleep (milliseconds)
87
*
88
* \param msecs time to sleep in milliseconds
89
*/
90
void
dde_kit_thread_msleep(
unsigned
long
msecs
)
;
91
92
/**
93
* Sleep (microseconds)
94
*
95
* \param usecs time to sleep in microseconds
96
*/
97
void
dde_kit_thread_usleep(
unsigned
long
usecs
)
;
98
99
/**
100
* Sleep (nanoseconds)
101
*
102
* \param nsecs time to sleep in nanoseconds
103
*/
104
void
dde_kit_thread_nsleep(
unsigned
long
nsecs
)
;
105
106
/**
107
* Exit current thread
108
*/
109
void
dde_kit_thread_exit(
void)
;
110
111
/**
112
* Get thread name
113
*
114
* \param thread thread handle
115
*/
116
const
char *
dde_kit_thread_get_name(
struct
dde_kit_thread *
thread
)
;
117
118
/**
119
* Get unique ID
120
*
121
* \param thread thread handle
122
* \return artificial thread ID
123
*
124
* DDE kit does not allow direct access to the thread data structure, since
125
* this struct contains platform-specific data types. However, applications
126
* might want to get some kind of ID related to a dde_kit_thread, for instance
127
* to use it as a Linux-like PID.
128
*
129
* XXX This function may be removed.
130
*/
131
int
dde_kit_thread_get_id(
struct
dde_kit_thread *
thread
)
;
132
133
/**
134
* Hint that this thread is done and may be scheduled somehow
135
*/
136
void
dde_kit_thread_schedule(
void)
;
137
138
#
endif /* _INCLUDE__DDE_KIT__THREAD_H_ */