Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
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
Commits
59fb10d0
Commit
59fb10d0
authored
Oct 13, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add atomic swap and compare-and-swap
parent
1af9f7d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
0 deletions
+68
-0
include/vlc_atomic.h
include/vlc_atomic.h
+3
-0
src/libvlccore.sym
src/libvlccore.sym
+2
-0
src/misc/atomic.c
src/misc/atomic.c
+44
-0
src/win32/atomic.c
src/win32/atomic.c
+19
-0
No files found.
include/vlc_atomic.h
View file @
59fb10d0
...
...
@@ -47,4 +47,7 @@ static inline uintptr_t vlc_atomic_dec (vlc_atomic_t *atom)
return
vlc_atomic_sub
(
atom
,
1
);
}
VLC_EXPORT
(
uintptr_t
,
vlc_atomic_swap
,
(
vlc_atomic_t
*
,
uintptr_t
));
VLC_EXPORT
(
uintptr_t
,
vlc_atomic_compare_swap
,
(
vlc_atomic_t
*
,
uintptr_t
,
uintptr_t
));
#endif
src/libvlccore.sym
View file @
59fb10d0
...
...
@@ -503,6 +503,8 @@ VLC_Compiler
vlc_atomic_get
vlc_atomic_set
vlc_atomic_add
vlc_atomic_swap
vlc_atomic_compare_swap
vlc_cond_broadcast
vlc_cond_destroy
vlc_cond_init
...
...
src/misc/atomic.c
View file @
59fb10d0
...
...
@@ -46,6 +46,24 @@ uintptr_t vlc_atomic_add (vlc_atomic_t *atom, uintptr_t v)
return
__sync_add_and_fetch
(
&
atom
->
u
,
v
);
}
uintptr_t
vlc_atomic_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
v
)
{
/* grmbl, gcc does not provide an intrinsic for this! */
uintptr_t
u
;
do
u
=
vlc_atomic_get
(
atom
);
while
(
vlc_atomic_compare_swap
(
atom
,
u
,
v
)
!=
u
);
return
u
;
}
uintptr_t
vlc_atomic_compare_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
oldval
,
uintptr_t
newval
)
{
return
__sync_val_compare_and_swap
(
&
atom
->
u
,
oldval
,
newval
);
}
#else
/* Worst-case fallback implementation with a mutex */
...
...
@@ -78,4 +96,30 @@ uintptr_t vlc_atomic_add (vlc_atomic_t *atom, uintptr_t v)
return
v
;
}
uintptr_t
vlc_atomic_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
v
)
{
uintptr_t
u
;
vlc_mutex_lock
(
&
lock
);
u
=
atom
->
u
;
atom
->
u
=
v
;
vlc_mutex_unlock
(
&
lock
);
return
u
;
}
uintptr_t
vlc_atomic_compare_and_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
oldval
,
uintptr_t
newval
)
{
uintptr_t
u
;
vlc_mutex_lock
(
&
lock
);
u
=
atom
->
u
;
if
(
u
==
oldval
)
atom
->
u
=
newval
;
vlc_mutex_unlock
(
&
lock
);
return
u
;
}
#endif
src/win32/atomic.c
View file @
59fb10d0
...
...
@@ -50,3 +50,22 @@ uintptr_t vlc_atomic_add (vlc_atomic_t *atom, uintptr_t v)
return
InterlockedExchangeAdd
(
&
atom
->
s
,
v
)
+
v
;
#endif
}
uintptr_t
vlc_atomic_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
v
)
{
#if defined (WIN64)
return
InterlockedExchange64
(
&
atom
->
s
,
v
);
#else
return
InterlockedExchange
(
&
atom
->
s
,
v
);
#endif
}
uintptr_t
vlc_atomic_compare_swap
(
vlc_atomic_t
*
atom
,
uintptr_t
oldval
,
uintptr_t
newval
)
{
#if defined (WIN64)
return
InterlockedCompareExchange64
(
&
atom
->
s
,
newval
,
oldval
);
#else
return
InterlockedCompareExchange
(
&
atom
->
s
,
newval
,
oldval
);
#endif
}
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