RWMutex.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //= llvm/Support/Unix/RWMutex.inc - Unix Reader/Writer Mutual Exclusion Lock =//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the Unix specific (non-pthread) RWMutex class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. //=== WARNING: Implementation here must contain only generic UNIX code that
  15. //=== is guaranteed to work on *all* UNIX variants.
  16. //===----------------------------------------------------------------------===//
  17. #include "llvm/Support/Mutex.h"
  18. namespace llvm {
  19. using namespace sys;
  20. // This naive implementation treats readers the same as writers. This
  21. // will therefore deadlock if a thread tries to acquire a read lock
  22. // multiple times.
  23. RWMutexImpl::RWMutexImpl() : data_(new MutexImpl(false)) { }
  24. RWMutexImpl::~RWMutexImpl() {
  25. delete static_cast<MutexImpl *>(data_);
  26. }
  27. bool RWMutexImpl::reader_acquire() {
  28. return static_cast<MutexImpl *>(data_)->acquire();
  29. }
  30. bool RWMutexImpl::reader_release() {
  31. return static_cast<MutexImpl *>(data_)->release();
  32. }
  33. bool RWMutexImpl::writer_acquire() {
  34. return static_cast<MutexImpl *>(data_)->acquire();
  35. }
  36. bool RWMutexImpl::writer_release() {
  37. return static_cast<MutexImpl *>(data_)->release();
  38. }
  39. }