Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC
Manage
Activity
Members
Labels
Plan
Issues
4k
Issue boards
Milestones
Code
Merge requests
440
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC
Commits
96bbc7a9
Commit
96bbc7a9
authored
3 years ago
by
Rémi Denis-Courmont
Browse files
Options
Downloads
Patches
Plain Diff
threads: remove no longer used vlc_rwlock_t
parent
76b3ad36
Branches
master
No related tags found
1 merge request
!967
Remove read/write locks
Pipeline
#164572
passed with stage
in 41 minutes and 28 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/vlc_threads.h
+0
-58
0 additions, 58 deletions
include/vlc_threads.h
src/libvlccore.sym
+0
-4
0 additions, 4 deletions
src/libvlccore.sym
src/misc/threads.c
+0
-65
0 additions, 65 deletions
src/misc/threads.c
with
0 additions
and
127 deletions
include/vlc_threads.h
+
0
−
58
View file @
96bbc7a9
...
...
@@ -511,64 +511,6 @@ VLC_API int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline) VLC_USED;
/** @} */
/**
* \defgroup rwlock Read/write locks
*
* Read/write locks are a type of thread synchronization primitive meant to
* protect access to data that is mostly read, and rarely written.
* As long as no threads tries to acquire the lock for "writing", any number of
* threads can acquire the lock for "reading".
*
* See also POSIX @c pthread_rwlock_t .
*
* @{
*/
/**
* Read/write lock.
*
* Storage space for a slim reader/writer lock.
*/
typedef
struct
vlc_rwlock
{
vlc_mutex_t
mutex
;
vlc_cond_t
wait
;
long
state
;
}
vlc_rwlock_t
;
/**
* Static initializer for (static) read/write lock.
*/
#define VLC_STATIC_RWLOCK { VLC_STATIC_MUTEX, VLC_STATIC_COND, 0 }
/**
* Initializes a read/write lock.
*/
VLC_API
void
vlc_rwlock_init
(
vlc_rwlock_t
*
);
/**
* Acquires a read/write lock for reading.
*
* \note Recursion is allowed.
*/
VLC_API
void
vlc_rwlock_rdlock
(
vlc_rwlock_t
*
);
/**
* Acquires a read/write lock for writing. Recursion is not allowed.
*/
VLC_API
void
vlc_rwlock_wrlock
(
vlc_rwlock_t
*
);
/**
* Releases a read/write lock.
*
* The calling thread must hold the lock. Otherwise behaviour is undefined.
*
* \note This function is not a cancellation point.
*/
VLC_API
void
vlc_rwlock_unlock
(
vlc_rwlock_t
*
);
/** @} */
#ifndef __cplusplus
/**
* One-time initialization.
...
...
This diff is collapsed.
Click to expand it.
src/libvlccore.sym
+
0
−
4
View file @
96bbc7a9
...
...
@@ -657,10 +657,6 @@ vlc_lrand48
vlc_mrand48
vlc_qsort
vlc_restorecancel
vlc_rwlock_init
vlc_rwlock_rdlock
vlc_rwlock_unlock
vlc_rwlock_wrlock
vlc_savecancel
vlc_sd_Create
vlc_sd_Destroy
...
...
This diff is collapsed.
Click to expand it.
src/misc/threads.c
+
0
−
65
View file @
96bbc7a9
...
...
@@ -320,71 +320,6 @@ int vlc_cond_timedwait_daytime(vlc_cond_t *cond, vlc_mutex_t *mutex,
return
ret
;
}
/*** Generic read/write locks ***/
/* NOTE:
* lock->state is a signed long integer:
* - The sign bit is set when the lock is held for writing.
* - The other bits code the number of times the lock is held for reading.
* Consequently:
* - The value is negative if and only if the lock is held for writing.
* - The value is zero if and only if the lock is not held at all.
*/
#define READER_MASK LONG_MAX
#define WRITER_BIT LONG_MIN
void
vlc_rwlock_init
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_init
(
&
lock
->
mutex
);
vlc_cond_init
(
&
lock
->
wait
);
lock
->
state
=
0
;
}
void
vlc_rwlock_rdlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
/* Recursive read-locking is allowed.
* Ensure that there is no active writer. */
while
(
lock
->
state
<
0
)
{
assert
(
lock
->
state
==
WRITER_BIT
);
vlc_cond_wait
(
&
lock
->
wait
,
&
lock
->
mutex
);
}
if
(
unlikely
(
lock
->
state
>=
READER_MASK
))
abort
();
/* An overflow is certainly a recursion bug. */
lock
->
state
++
;
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
void
vlc_rwlock_wrlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
/* Wait until nobody owns the lock in any way. */
while
(
lock
->
state
!=
0
)
vlc_cond_wait
(
&
lock
->
wait
,
&
lock
->
mutex
);
lock
->
state
=
WRITER_BIT
;
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
void
vlc_rwlock_unlock
(
vlc_rwlock_t
*
lock
)
{
vlc_mutex_lock
(
&
lock
->
mutex
);
if
(
lock
->
state
<
0
)
{
/* Write unlock */
assert
(
lock
->
state
==
WRITER_BIT
);
/* Let reader and writer compete. OS scheduler decides who wins. */
lock
->
state
=
0
;
vlc_cond_broadcast
(
&
lock
->
wait
);
}
else
{
/* Read unlock */
assert
(
lock
->
state
>
0
);
/* If there are no readers left, wake up one pending writer. */
if
(
--
lock
->
state
==
0
)
vlc_cond_signal
(
&
lock
->
wait
);
}
vlc_mutex_unlock
(
&
lock
->
mutex
);
}
/*** Generic semaphores ***/
void
vlc_sem_init
(
vlc_sem_t
*
sem
,
unsigned
value
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment