rw_lock.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/atomics.h>
  6. #include <aws/common/rw_lock.h>
  7. #include <aws/common/posix/common.inl>
  8. int aws_rw_lock_init(struct aws_rw_lock *lock) {
  9. return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL));
  10. }
  11. void aws_rw_lock_clean_up(struct aws_rw_lock *lock) {
  12. pthread_rwlock_destroy(&lock->lock_handle);
  13. }
  14. int aws_rw_lock_rlock(struct aws_rw_lock *lock) {
  15. return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle));
  16. }
  17. int aws_rw_lock_wlock(struct aws_rw_lock *lock) {
  18. return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle));
  19. }
  20. int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) {
  21. return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle));
  22. }
  23. int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) {
  24. return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle));
  25. }
  26. int aws_rw_lock_runlock(struct aws_rw_lock *lock) {
  27. return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
  28. }
  29. int aws_rw_lock_wunlock(struct aws_rw_lock *lock) {
  30. return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle));
  31. }