summaryrefslogtreecommitdiff
path: root/django/utils/synch.py
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
committerChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
commitae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch)
treec37fc631e99a7e4d909d6b6d236f495003731ea7 /django/utils/synch.py
parent0cf7bc439129c66df8d64601e885f83b256b4f25 (diff)
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/synch.py')
-rw-r--r--django/utils/synch.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/django/utils/synch.py b/django/utils/synch.py
index 6fcd81390e..2e808c1e01 100644
--- a/django/utils/synch.py
+++ b/django/utils/synch.py
@@ -1,6 +1,6 @@
"""
Synchronization primitives:
-
+
- reader-writer lock (preference to writers)
(Contributed to Django by eugene@lazutkin.com)
@@ -14,17 +14,16 @@ except ImportError:
class RWLock:
"""
Classic implementation of reader-writer lock with preference to writers.
-
+
Readers can access a resource simultaneously.
Writers get an exclusive access.
-
+
API is self-descriptive:
reader_enters()
reader_leaves()
writer_enters()
writer_leaves()
"""
-
def __init__(self):
self.mutex = threading.RLock()
self.can_read = threading.Semaphore(0)
@@ -33,7 +32,7 @@ class RWLock:
self.active_writers = 0
self.waiting_readers = 0
self.waiting_writers = 0
-
+
def reader_enters(self):
self.mutex.acquire()
try:
@@ -45,7 +44,7 @@ class RWLock:
finally:
self.mutex.release()
self.can_read.acquire()
-
+
def reader_leaves(self):
self.mutex.acquire()
try:
@@ -56,7 +55,7 @@ class RWLock:
self.can_write.release()
finally:
self.mutex.release()
-
+
def writer_enters(self):
self.mutex.acquire()
try:
@@ -68,7 +67,7 @@ class RWLock:
finally:
self.mutex.release()
self.can_write.acquire()
-
+
def writer_leaves(self):
self.mutex.acquire()
try: