Embedded Multicore Building Blocks V1.0.0
thread.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_BASE_C_THREAD_H_
28 #define EMBB_BASE_C_THREAD_H_
29 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #include <embb/base/c/internal/platform.h>
48 #include <embb/base/c/time.h>
49 #include <embb/base/c/core_set.h>
50 #include <embb/base/c/errors.h>
51 
52 #ifdef DOXYGEN
53 
56 typedef opaque_type embb_thread_t;
57 #endif /* DOXYGEN */
58 
62 typedef enum {
63  EMBB_THREAD_PRIORITY_IDLE,
64  EMBB_THREAD_PRIORITY_LOWEST,
65  EMBB_THREAD_PRIORITY_BELOW_NORMAL,
66  EMBB_THREAD_PRIORITY_NORMAL,
67  EMBB_THREAD_PRIORITY_ABOVE_NORMAL,
68  EMBB_THREAD_PRIORITY_HIGHEST,
69  EMBB_THREAD_PRIORITY_TIME_CRITICAL
71 
78 typedef int(*embb_thread_start_t)(void*);
79 
98 unsigned int embb_thread_get_max_count();
99 
110  unsigned int max
112  );
113 
123 embb_thread_t embb_thread_current();
124 
133 void embb_thread_yield();
134 
151  embb_thread_t* thread,
153  const embb_core_set_t* core_set,
156  embb_thread_start_t function,
159  void* arg
161  );
162 
179  embb_thread_t* thread,
181  const embb_core_set_t* core_set,
184  embb_thread_priority_t priority,
186  embb_thread_start_t function,
189  void* arg
191  );
192 
205 int embb_thread_join(
206  embb_thread_t* thread,
208  int* result_code
210  );
211 
220  const embb_thread_t* lhs,
222  const embb_thread_t* rhs
224  );
225 
226 #ifdef __cplusplus
227 } /* Close extern "C" { */
228 #endif
229 
234 #endif /* EMBB_BASE_C_THREAD_H_ */
int embb_thread_create(embb_thread_t *thread, const embb_core_set_t *core_set, embb_thread_start_t function, void *arg)
Creates and runs a thread.
opaque_type embb_core_set_t
Opaque type representing a set of processor cores.
Definition: core_set.h:59
int embb_thread_equal(const embb_thread_t *lhs, const embb_thread_t *rhs)
Compares two threads represented by their handles for equality.
int embb_thread_join(embb_thread_t *thread, int *result_code)
Waits until the given thread has finished execution.
void embb_thread_set_max_count(unsigned int max)
Sets maximum number of threads handled by EMBB.
embb_thread_t embb_thread_current()
Returns the calling thread (that is, this thread).
int embb_thread_create_with_priority(embb_thread_t *thread, const embb_core_set_t *core_set, embb_thread_priority_t priority, embb_thread_start_t function, void *arg)
Creates and runs a thread.
opaque_type embb_thread_t
Opaque type representing a thread of execution.
Definition: thread.h:56
embb_thread_priority_t
Thread priority type.
Definition: thread.h:62
void embb_thread_yield()
Reschedule the current thread for later execution.
int(* embb_thread_start_t)(void *)
Thread start function pointer type.
Definition: thread.h:78
unsigned int embb_thread_get_max_count()
Returns the maximum number of threads handled by EMB2.