1 | /* |
---|---|
2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | * You may not use this file except in compliance with the License. |
6 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | |
16 | #include <aws/common/atomics.h> |
17 | #include <aws/common/rw_lock.h> |
18 | |
19 | #include <aws/common/posix/common.inl> |
20 | |
21 | int aws_rw_lock_init(struct aws_rw_lock *lock) { |
22 | |
23 | return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL)); |
24 | } |
25 | |
26 | void aws_rw_lock_clean_up(struct aws_rw_lock *lock) { |
27 | |
28 | pthread_rwlock_destroy(&lock->lock_handle); |
29 | } |
30 | |
31 | int aws_rw_lock_rlock(struct aws_rw_lock *lock) { |
32 | |
33 | return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle)); |
34 | } |
35 | |
36 | int aws_rw_lock_wlock(struct aws_rw_lock *lock) { |
37 | |
38 | return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle)); |
39 | } |
40 | |
41 | int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) { |
42 | |
43 | return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle)); |
44 | } |
45 | |
46 | int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) { |
47 | |
48 | return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle)); |
49 | } |
50 | |
51 | int aws_rw_lock_runlock(struct aws_rw_lock *lock) { |
52 | |
53 | return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); |
54 | } |
55 | |
56 | int aws_rw_lock_wunlock(struct aws_rw_lock *lock) { |
57 | |
58 | return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); |
59 | } |
60 |