-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy paththreadapi.h
More file actions
90 lines (76 loc) · 3.1 KB
/
threadapi.h
File metadata and controls
90 lines (76 loc) · 3.1 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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
/** @file threadapi.h
* @brief This module implements support for creating new threads,
* terminating threads and sleeping threads.
*/
#ifndef THREADAPI_H
#define THREADAPI_H
#include "azure_macro_utils/macro_utils.h"
#include "umock_c/umock_c_prod.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef int(*THREAD_START_FUNC)(void *);
#define THREADAPI_RESULT_VALUES \
THREADAPI_OK, \
THREADAPI_INVALID_ARG, \
THREADAPI_NO_MEMORY, \
THREADAPI_ERROR
/** @brief Enumeration specifying the possible return values for the APIs in
* this module.
*/
MU_DEFINE_ENUM(THREADAPI_RESULT, THREADAPI_RESULT_VALUES);
typedef void* THREAD_HANDLE;
/**
* @brief Creates a thread with the entry point specified by the @p func
* argument.
*
* @param threadHandle The handle to the new thread is returned in this
* pointer.
* @param func A function pointer that indicates the entry point
* to the new thread.
* @param arg A void pointer that must be passed to the function
* pointed to by @p func.
*
* @return @c THREADAPI_OK if the API call is successful or an error
* code in case it fails.
*/
MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Create, THREAD_HANDLE*, threadHandle, THREAD_START_FUNC, func, void*, arg);
/**
* @brief Blocks the calling thread by waiting on the thread identified by
* the @p threadHandle argument to complete.
*
* @param threadHandle The handle of the thread to wait for completion.
* @param res The result returned by the thread which is passed
* to the ::ThreadAPI_Exit function.
*
* When the @p threadHandle thread completes, all resources associated
* with the thread must be released and the thread handle will no
* longer be valid.
*
* @return @c THREADAPI_OK if the API call is successful or an error
* code in case it fails.
*/
MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Join, THREAD_HANDLE, threadHandle, int*, res);
/**
* @brief This function is called by a thread when the thread exits.
*
* @param res An integer that represents the exit status of the thread.
*
* This function is called by a thread when the thread exits in order
* to return a result value to the caller of the ::ThreadAPI_Join
* function. The @p res value must be copied into the @p res out
* argument passed to the ::ThreadAPI_Join function.
*/
MOCKABLE_FUNCTION(, void, ThreadAPI_Exit, int, res);
/**
* @brief Sleeps the current thread for the given number of milliseconds.
*
* @param milliseconds The number of milliseconds to sleep.
*/
MOCKABLE_FUNCTION(, void, ThreadAPI_Sleep, unsigned int, milliseconds);
#ifdef __cplusplus
}
#endif
#endif /* THREADAPI_H */