Debian Codegraph @

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

raw symbols SCIP
1 #ifndef AWS_COMMON_RW_LOCK_H
2 #define AWS_COMMON_RW_LOCK_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 AWSSRW_TO_WINDOWS(pCV) (PSRWLOCK) pCV
13 #else
14 # include <pthread.h>
15 #endif
16
17 AWS_PUSH_SANE_WARNING_LEVEL
18
19 struct aws_rw_lock {
20 #ifdef _WIN32
21 void *lock_handle;
22 #else
23 pthread_rwlock_t lock_handle;
24 #endif
25 };
26
27 #ifdef _WIN32
28 # define AWS_RW_LOCK_INIT {.lock_handle = NULL}
29 #else
30 # define AWS_RW_LOCK_INIT {.lock_handle = PTHREAD_RWLOCK_INITIALIZER}
31 #endif
32
33 AWS_EXTERN_C_BEGIN
34
35 /**
36 * Initializes a new platform instance of mutex.
37 */
38 AWS_COMMON_API int aws_rw_lock_init(struct aws_rw_lock *lock);
39
40 /**
41 * Cleans up internal resources.
42 */
43 AWS_COMMON_API void aws_rw_lock_clean_up(struct aws_rw_lock *lock);
44
45 /**
46 * Blocks until it acquires the lock. While on some platforms such as Windows,
47 * this may behave as a reentrant mutex, you should not treat it like one. On
48 * platforms it is possible for it to be non-reentrant, it will be.
49 */
50 AWS_COMMON_API int aws_rw_lock_rlock(struct aws_rw_lock *lock);
51 AWS_COMMON_API int aws_rw_lock_wlock(struct aws_rw_lock *lock);
52
53 /**
54 * Attempts to acquire the lock but returns immediately if it can not.
55 * While on some platforms such as Windows, this may behave as a reentrant mutex,
56 * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be.
57 * Note: For windows, minimum support server version is Windows Server 2008 R2 [desktop apps | UWP apps]
58 */
59 AWS_COMMON_API int aws_rw_lock_try_rlock(struct aws_rw_lock *lock);
60 AWS_COMMON_API int aws_rw_lock_try_wlock(struct aws_rw_lock *lock);
61
62 /**
63 * Releases the lock.
64 */
65 AWS_COMMON_API int aws_rw_lock_runlock(struct aws_rw_lock *lock);
66 AWS_COMMON_API int aws_rw_lock_wunlock(struct aws_rw_lock *lock);
67
68 AWS_EXTERN_C_END
69 AWS_POP_SANE_WARNING_LEVEL
70
71 #endif /* AWS_COMMON_RW_LOCK_H */