Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/inc/azure_c_shared_utility/lock.h

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 /** @file lock.h
5 * @brief A minimalistic platform agnostic lock abstraction for thread
6 * synchronization.
7 * @details The Lock component is implemented in order to achieve thread
8 * synchronization, as we may have a requirement to consume locks
9 * across different platforms. This component exposes some generic
10 * APIs so that it can be extended for platform specific
11 * implementations.
12 */
13
14 #ifndef LOCK_H
15 #define LOCK_H
16
17 #include "azure_macro_utils/macro_utils.h"
18 #include "umock_c/umock_c_prod.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 typedef void* LOCK_HANDLE;
25
26 #define LOCK_RESULT_VALUES \
27 LOCK_OK, \
28 LOCK_ERROR \
29
30 /** @brief Enumeration specifying the lock status.
31 */
32 MU_DEFINE_ENUM(LOCK_RESULT, LOCK_RESULT_VALUES);
33
34 /**
35 * @brief This API creates and returns a valid lock handle.
36 *
37 * @return A valid @c LOCK_HANDLE when successful or @c NULL otherwise.
38 */
39 MOCKABLE_FUNCTION(, LOCK_HANDLE, Lock_Init);
40
41 /**
42 * @brief Acquires a lock on the given lock handle. Uses platform
43 * specific mutex primitives in its implementation.
44 *
45 * @param handle A valid handle to the lock.
46 *
47 * @return Returns @c LOCK_OK when a lock has been acquired and
48 * @c LOCK_ERROR when an error occurs.
49 */
50 MOCKABLE_FUNCTION(, LOCK_RESULT, Lock, LOCK_HANDLE, handle);
51
52 /**
53 * @brief Releases the lock on the given lock handle. Uses platform
54 * specific mutex primitives in its implementation.
55 *
56 * @param handle A valid handle to the lock.
57 *
58 * @return Returns @c LOCK_OK when the lock has been released and
59 * @c LOCK_ERROR when an error occurs.
60 */
61 MOCKABLE_FUNCTION(, LOCK_RESULT, Unlock, LOCK_HANDLE, handle);
62
63 /**
64 * @brief The lock instance is destroyed.
65 *
66 * @param handle A valid handle to the lock.
67 *
68 * @return Returns @c LOCK_OK when the lock object has been
69 * destroyed and @c LOCK_ERROR when an error occurs.
70 */
71 MOCKABLE_FUNCTION(, LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle);
72
73 #ifdef __cplusplus
74 }
75 #endif
76
77 #endif /* LOCK_H */