File: rw_lock.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (73 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download
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
#ifndef AWS_COMMON_RW_LOCK_H
#define AWS_COMMON_RW_LOCK_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/common.h>
#ifdef _WIN32
/* NOTE: Do not use this macro before including windows.h */
#    define AWSSRW_TO_WINDOWS(pCV) (PSRWLOCK) pCV
#else
#    include <pthread.h>
#endif

AWS_PUSH_SANE_WARNING_LEVEL

struct aws_rw_lock {
#ifdef _WIN32
    void *lock_handle;
#else
    pthread_rwlock_t lock_handle;
#endif
};

#ifdef _WIN32
#    define AWS_RW_LOCK_INIT                                                                                           \
        { .lock_handle = NULL }
#else
#    define AWS_RW_LOCK_INIT                                                                                           \
        { .lock_handle = PTHREAD_RWLOCK_INITIALIZER }
#endif

AWS_EXTERN_C_BEGIN

/**
 * Initializes a new platform instance of mutex.
 */
AWS_COMMON_API int aws_rw_lock_init(struct aws_rw_lock *lock);

/**
 * Cleans up internal resources.
 */
AWS_COMMON_API void aws_rw_lock_clean_up(struct aws_rw_lock *lock);

/**
 * Blocks until it acquires the lock. While on some platforms such as Windows,
 * this may behave as a reentrant mutex, you should not treat it like one. On
 * platforms it is possible for it to be non-reentrant, it will be.
 */
AWS_COMMON_API int aws_rw_lock_rlock(struct aws_rw_lock *lock);
AWS_COMMON_API int aws_rw_lock_wlock(struct aws_rw_lock *lock);

/**
 * Attempts to acquire the lock but returns immediately if it can not.
 * While on some platforms such as Windows, this may behave as a reentrant mutex,
 * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be.
 * Note: For windows, minimum support server version is Windows Server 2008 R2 [desktop apps | UWP apps]
 */
AWS_COMMON_API int aws_rw_lock_try_rlock(struct aws_rw_lock *lock);
AWS_COMMON_API int aws_rw_lock_try_wlock(struct aws_rw_lock *lock);

/**
 * Releases the lock.
 */
AWS_COMMON_API int aws_rw_lock_runlock(struct aws_rw_lock *lock);
AWS_COMMON_API int aws_rw_lock_wunlock(struct aws_rw_lock *lock);

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_RW_LOCK_H */