mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
34 lines
531 B
Text
34 lines
531 B
Text
|
***********************************************
|
||
|
|
||
|
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);
|