mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
docs: interesting idea for fast rw locks
--
This commit is contained in:
parent
4eacc03558
commit
5aeb28aabd
1 changed files with 33 additions and 0 deletions
33
docs/random/wtay/rwlocks
Normal file
33
docs/random/wtay/rwlocks
Normal file
|
@ -0,0 +1,33 @@
|
|||
***********************************************
|
||||
|
||||
typedef struct {
|
||||
int pre_count;
|
||||
int post_count;
|
||||
Mutex *lock;
|
||||
} RWLock;
|
||||
|
||||
|
||||
reader:
|
||||
|
||||
retry:
|
||||
post = atomic_get (lock->post_count);
|
||||
|
||||
... do read ...
|
||||
|
||||
if (atomic_get (lock->pre_count) != post) {
|
||||
/* wait for writer to finish then retry */
|
||||
lock (lock->mutex);
|
||||
unlock (lock->mutex);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
|
||||
writer:
|
||||
|
||||
lock (lock->mutex);
|
||||
atomic_inc (lock->pre_count);
|
||||
|
||||
... update ...
|
||||
|
||||
atomic_inc (lock->post_count);
|
||||
unlock (lock->mutex);
|
Loading…
Reference in a new issue