Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
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-2-2
Commits
e5640463
Commit
e5640463
authored
Jun 28, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite GC code on top of atomic ops
(This saves one useless spin lock per GC object)
parent
34f3dfb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
53 deletions
+7
-53
include/vlc_common.h
include/vlc_common.h
+2
-2
src/libvlc.c
src/libvlc.c
+5
-51
No files found.
include/vlc_common.h
View file @
e5640463
...
...
@@ -558,10 +558,10 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
# define VLC_OBJECT( x ) ((vlc_object_t *)(x))
#endif
#include <vlc_atomic.h>
typedef
struct
gc_object_t
{
vlc_spinlock_t
spin
;
uintptr_t
refs
;
vlc_atomic_t
refs
;
void
(
*
pf_destructor
)
(
struct
gc_object_t
*
);
}
gc_object_t
;
...
...
src/libvlc.c
View file @
e5640463
...
...
@@ -80,6 +80,7 @@
#include <vlc_fs.h>
#include <vlc_cpu.h>
#include <vlc_url.h>
#include <vlc_atomic.h>
#include "libvlc.h"
...
...
@@ -118,18 +119,7 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
assert
(
pf_destruct
);
p_gc
->
pf_destructor
=
pf_destruct
;
p_gc
->
refs
=
1
;
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
__sync_synchronize
();
#elif defined (WIN32) && defined (__GNUC__)
#elif defined(__APPLE__)
OSMemoryBarrier
();
#else
/* Nobody else can possibly lock the spin - it's there as a barrier */
vlc_spin_init
(
&
p_gc
->
spin
);
vlc_spin_lock
(
&
p_gc
->
spin
);
vlc_spin_unlock
(
&
p_gc
->
spin
);
#endif
vlc_atomic_set
(
&
p_gc
->
refs
,
1
);
return
p_gc
;
}
...
...
@@ -141,22 +131,9 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
void
*
vlc_hold
(
gc_object_t
*
p_gc
)
{
uintptr_t
refs
;
assert
(
p_gc
);
assert
((((
uintptr_t
)
&
p_gc
->
refs
)
&
(
sizeof
(
void
*
)
-
1
))
==
0
);
/* alignment */
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
refs
=
__sync_add_and_fetch
(
&
p_gc
->
refs
,
1
);
#elif defined (WIN64)
refs
=
InterlockedIncrement64
(
&
p_gc
->
refs
);
#elif defined (WIN32)
refs
=
InterlockedIncrement
(
&
p_gc
->
refs
);
#elif defined(__APPLE__)
refs
=
OSAtomicIncrement32Barrier
((
int
*
)
&
p_gc
->
refs
);
#else
vlc_spin_lock
(
&
p_gc
->
spin
);
refs
=
++
p_gc
->
refs
;
vlc_spin_unlock
(
&
p_gc
->
spin
);
#endif
refs
=
vlc_atomic_inc
(
&
p_gc
->
refs
);
assert
(
refs
!=
1
);
/* there had to be a reference already */
return
p_gc
;
}
...
...
@@ -170,33 +147,10 @@ void vlc_release (gc_object_t *p_gc)
unsigned
refs
;
assert
(
p_gc
);
assert
((((
uintptr_t
)
&
p_gc
->
refs
)
&
(
sizeof
(
void
*
)
-
1
))
==
0
);
/* alignment */
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
refs
=
__sync_sub_and_fetch
(
&
p_gc
->
refs
,
1
);
#elif defined (WIN64)
refs
=
InterlockedDecrement64
(
&
p_gc
->
refs
);
#elif defined (WIN32)
refs
=
InterlockedDecrement
(
&
p_gc
->
refs
);
#elif defined(__APPLE__)
refs
=
OSAtomicDecrement32Barrier
((
int
*
)
&
p_gc
->
refs
);
#else
vlc_spin_lock
(
&
p_gc
->
spin
);
refs
=
--
p_gc
->
refs
;
vlc_spin_unlock
(
&
p_gc
->
spin
);
#endif
refs
=
vlc_atomic_dec
(
&
p_gc
->
refs
);
assert
(
refs
!=
(
uintptr_t
)(
-
1
));
/* reference underflow?! */
if
(
refs
==
0
)
{
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
#elif defined (WIN32) && defined (__GNUC__)
#elif defined(__APPLE__)
#else
vlc_spin_destroy
(
&
p_gc
->
spin
);
#endif
p_gc
->
pf_destructor
(
p_gc
);
}
}
/*****************************************************************************
...
...
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