Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
53ffb224
Commit
53ffb224
authored
May 06, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Win32 R/W locks: fix/add comments, add asserts
parent
1b6caac9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
26 deletions
+44
-26
src/win32/thread.c
src/win32/thread.c
+44
-26
No files found.
src/win32/thread.c
View file @
53ffb224
...
...
@@ -392,13 +392,10 @@ void vlc_rwlock_init (vlc_rwlock_t *lock)
vlc_cond_init
(
&
lock
->
read_wait
);
vlc_cond_init
(
&
lock
->
write_wait
);
lock
->
readers
=
0
;
/* active readers */
lock
->
writers
=
0
;
/* waiting
or active
writers */
lock
->
writers
=
0
;
/* waiting writers */
lock
->
writer
=
0
;
/* ID of active writer */
}
/**
* Destroys an initialized unused read/write lock.
*/
void
vlc_rwlock_destroy
(
vlc_rwlock_t
*
lock
)
{
vlc_cond_destroy
(
&
lock
->
read_wait
);
...
...
@@ -406,57 +403,78 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock)
vlc_mutex_destroy
(
&
lock
->
mutex
);
}
/**
* Acquires a read/write lock for reading. Recursion is allowed.
*/
void
vlc_rwlock_rdlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
/* Recursive read-locking is allowed. With the infos available:
* - the loosest possible condition (no active writer) is:
* (lock->writer != 0)
* - the strictest possible condition is:
* (lock->writer != 0 || (lock->readers == 0 && lock->writers > 0))
* or (lock->readers == 0 && (lock->writer != 0 || lock->writers > 0))
*/
while
(
lock
->
writer
!=
0
)
{
assert
(
lock
->
readers
==
0
);
vlc_cond_wait
(
&
lock
->
read_wait
,
&
lock
->
mutex
);
if
(
lock
->
readers
==
ULONG_MAX
)
}
if
(
unlikely
(
lock
->
readers
==
ULONG_MAX
))
abort
();
lock
->
readers
++
;
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
/**
* Acquires a read/write lock for writing. Recursion is not allowed.
*/
static
void
vlc_rwlock_rdunlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
assert
(
lock
->
readers
>
0
);
/* If there are no readers left, wake up a writer. */
if
(
--
lock
->
readers
==
0
&&
lock
->
writers
>
0
)
vlc_cond_signal
(
&
lock
->
write_wait
);
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
void
vlc_rwlock_wrlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
if
(
lock
->
writers
==
ULONG_MAX
)
if
(
unlikely
(
lock
->
writers
==
ULONG_MAX
)
)
abort
();
lock
->
writers
++
;
/* Wait until nobody owns the lock in either way. */
while
((
lock
->
readers
>
0
)
||
(
lock
->
writer
!=
0
))
vlc_cond_wait
(
&
lock
->
write_wait
,
&
lock
->
mutex
);
lock
->
writers
--
;
assert
(
lock
->
writer
==
0
);
lock
->
writer
=
GetCurrentThreadId
();
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
/**
* Releases a read/write lock.
*/
void
vlc_rwlock_unlock
(
vlc_rwlock_t
*
lock
)
static
void
vlc_rwlock_wrunlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
if
(
lock
->
readers
>
0
)
lock
->
readers
--
;
/* Read unlock */
else
lock
->
writer
=
0
;
/* Write unlock */
assert
(
lock
->
writer
==
GetCurrentThreadId
());
assert
(
lock
->
readers
==
0
);
lock
->
writer
=
0
;
/* Write unlock */
/* Let reader and writer compete. Scheduler decides who wins. */
if
(
lock
->
writers
>
0
)
{
if
(
lock
->
readers
==
0
)
vlc_cond_signal
(
&
lock
->
write_wait
);
}
else
vlc_cond_broadcast
(
&
lock
->
read_wait
);
vlc_cond_signal
(
&
lock
->
write_wait
);
vlc_cond_broadcast
(
&
lock
->
read_wait
);
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
void
vlc_rwlock_unlock
(
vlc_rwlock_t
*
lock
)
{
/* Note: If the lock is held for reading, lock->writer is nul.
* If the lock is held for writing, only this thread can store a value to
* lock->writer. Either way, lock->writer is safe to fetch here. */
if
(
lock
->
writer
!=
0
)
vlc_rwlock_wrunlock
(
lock
);
else
vlc_rwlock_rdunlock
(
lock
);
}
/*** Thread-specific variables (TLS) ***/
struct
vlc_threadvar
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment