rwmutex.go 790 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package sync
  2. import "sync"
  3. // This RWMutex's RLock and RUnlock methods don't allow shared reading because
  4. // there's no way to determine what goroutine has stopped holding the read
  5. // lock when RUnlock is called. So for debugging purposes when the package is
  6. // Enable()d, it's just like Mutex.
  7. type RWMutex struct {
  8. ins Mutex // Instrumented
  9. rw sync.RWMutex // Real McCoy
  10. }
  11. func (me *RWMutex) Lock() {
  12. if noSharedLocking {
  13. me.ins.Lock()
  14. } else {
  15. me.rw.Lock()
  16. }
  17. }
  18. func (me *RWMutex) Unlock() {
  19. if noSharedLocking {
  20. me.ins.Unlock()
  21. } else {
  22. me.rw.Unlock()
  23. }
  24. }
  25. func (me *RWMutex) RLock() {
  26. if noSharedLocking {
  27. me.ins.Lock()
  28. } else {
  29. me.rw.RLock()
  30. }
  31. }
  32. func (me *RWMutex) RUnlock() {
  33. if noSharedLocking {
  34. me.ins.Unlock()
  35. } else {
  36. me.rw.RUnlock()
  37. }
  38. }