Debian Codegraph @

crt/aws-c-common/include/aws/common/mutex.h

raw symbols SCIP
1 #ifndef AWS_COMMON_MUTEX_H
2 #define AWS_COMMON_MUTEX_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/common/common.h>
10 #ifdef _WIN32
11 /* NOTE: Do not use this macro before including windows.h */
12 # define AWSMUTEX_TO_WINDOWS(pMutex) (PSRWLOCK) & (pMutex)->mutex_handle
13 #else
14 # include <pthread.h>
15 #endif
16
17 AWS_PUSH_SANE_WARNING_LEVEL
18
19 struct aws_mutex {
20 #ifdef _WIN32
21 void *mutex_handle;
22 #else
23 pthread_mutex_t mutex_handle;
24 #endif
25 bool initialized;
26 };
27
28 #ifdef _WIN32
29 # define AWS_MUTEX_INIT {.mutex_handle = NULL, .initialized = true}
30 #else
31 # define AWS_MUTEX_INIT {.mutex_handle = PTHREAD_MUTEX_INITIALIZER, .initialized = true}
32 #endif
33
34 AWS_EXTERN_C_BEGIN
35
36 /**
37 * Initializes a new platform instance of mutex.
38 */
39 AWS_COMMON_API
40 int aws_mutex_init(struct aws_mutex *mutex);
41
42 /**
43 * Cleans up internal resources.
44 */
45 AWS_COMMON_API
46 void aws_mutex_clean_up(struct aws_mutex *mutex);
47
48 /**
49 * Blocks until it acquires the lock. While on some platforms such as Windows,
50 * this may behave as a reentrant mutex, you should not treat it like one. On
51 * platforms it is possible for it to be non-reentrant, it will be.
52 */
53 AWS_COMMON_API
54 int aws_mutex_lock(struct aws_mutex *mutex);
55
56 /**
57 * Attempts to acquire the lock but returns immediately if it can not.
58 * While on some platforms such as Windows, this may behave as a reentrant mutex,
59 * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be.
60 * Note: For windows, minimum support server version is Windows Server 2008 R2 [desktop apps | UWP apps]
61 */
62 AWS_COMMON_API
63 int aws_mutex_try_lock(struct aws_mutex *mutex);
64
65 /**
66 * Releases the lock.
67 */
68 AWS_COMMON_API
69 int aws_mutex_unlock(struct aws_mutex *mutex);
70
71 AWS_EXTERN_C_END
72 AWS_POP_SANE_WARNING_LEVEL
73
74 #endif /* AWS_COMMON_MUTEX_H */