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
257fdd4a
Commit
257fdd4a
authored
Aug 27, 2007
by
Pierre d'Herbemont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
control/event.c: Locking for libvlc event.
parent
00749a2f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
7 deletions
+45
-7
src/control/event.c
src/control/event.c
+43
-5
src/control/libvlc_internal.h
src/control/libvlc_internal.h
+2
-2
No files found.
src/control/event.c
View file @
257fdd4a
...
@@ -76,6 +76,7 @@ libvlc_event_manager_new( void * p_obj, libvlc_instance_t * p_libvlc_inst,
...
@@ -76,6 +76,7 @@ libvlc_event_manager_new( void * p_obj, libvlc_instance_t * p_libvlc_inst,
p_em
->
p_obj
=
p_obj
;
p_em
->
p_obj
=
p_obj
;
p_em
->
p_libvlc_instance
=
p_libvlc_inst
;
p_em
->
p_libvlc_instance
=
p_libvlc_inst
;
ARRAY_INIT
(
p_em
->
listeners_groups
);
ARRAY_INIT
(
p_em
->
listeners_groups
);
vlc_mutex_init
(
p_libvlc_inst
->
p_libvlc_int
,
&
p_em
->
object_lock
);
return
p_em
;
return
p_em
;
}
}
...
@@ -90,6 +91,8 @@ void libvlc_event_manager_release( libvlc_event_manager_t * p_em )
...
@@ -90,6 +91,8 @@ void libvlc_event_manager_release( libvlc_event_manager_t * p_em )
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listener_t
*
listener
;
libvlc_event_listener_t
*
listener
;
vlc_mutex_destroy
(
&
p_em
->
object_lock
);
FOREACH_ARRAY
(
listeners_group
,
p_em
->
listeners_groups
)
FOREACH_ARRAY
(
listeners_group
,
p_em
->
listeners_groups
)
FOREACH_ARRAY
(
listener
,
listeners_group
->
listeners
)
FOREACH_ARRAY
(
listener
,
listeners_group
->
listeners
)
free
(
listener
);
free
(
listener
);
...
@@ -120,7 +123,9 @@ void libvlc_event_manager_register_event_type(
...
@@ -120,7 +123,9 @@ void libvlc_event_manager_register_event_type(
listeners_group
->
event_type
=
event_type
;
listeners_group
->
event_type
=
event_type
;
ARRAY_INIT
(
listeners_group
->
listeners
);
ARRAY_INIT
(
listeners_group
->
listeners
);
vlc_mutex_lock
(
&
p_em
->
object_lock
);
ARRAY_APPEND
(
p_em
->
listeners_groups
,
listeners_group
);
ARRAY_APPEND
(
p_em
->
listeners_groups
,
listeners_group
);
vlc_mutex_unlock
(
&
p_em
->
object_lock
);
}
}
/**************************************************************************
/**************************************************************************
...
@@ -132,20 +137,47 @@ void libvlc_event_send( libvlc_event_manager_t * p_em,
...
@@ -132,20 +137,47 @@ void libvlc_event_send( libvlc_event_manager_t * p_em,
libvlc_event_t
*
p_event
)
libvlc_event_t
*
p_event
)
{
{
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listener_t
*
listener_cached
;
libvlc_event_listener_t
*
listener
;
libvlc_event_listener_t
*
listener
;
libvlc_event_listener_t
*
array_listeners_cached
=
NULL
;
int
i
,
i_cached_listeners
=
0
;
/* Fill event with the sending object now */
/* Fill event with the sending object now */
p_event
->
p_obj
=
p_em
->
p_obj
;
p_event
->
p_obj
=
p_em
->
p_obj
;
vlc_mutex_lock
(
&
p_em
->
object_lock
);
FOREACH_ARRAY
(
listeners_group
,
p_em
->
listeners_groups
)
FOREACH_ARRAY
(
listeners_group
,
p_em
->
listeners_groups
)
if
(
listeners_group
->
event_type
==
p_event
->
type
)
if
(
listeners_group
->
event_type
==
p_event
->
type
)
{
{
/* We found the group, now send every one the event */
if
(
listeners_group
->
listeners
.
i_size
<=
0
)
break
;
/* Cache a copy of the listener to avoid locking issues */
i_cached_listeners
=
listeners_group
->
listeners
.
i_size
;
array_listeners_cached
=
malloc
(
sizeof
(
libvlc_event_listener_t
)
*
(
i_cached_listeners
));
if
(
!
array_listeners_cached
)
{
printf
(
"Can't alloc memory in libvlc_event_send"
);
break
;
}
listener_cached
=
array_listeners_cached
;
FOREACH_ARRAY
(
listener
,
listeners_group
->
listeners
)
FOREACH_ARRAY
(
listener
,
listeners_group
->
listeners
)
listener
->
pf_callback
(
p_event
,
listener
->
p_user_data
);
memcpy
(
listener_cached
,
listener
,
sizeof
(
libvlc_event_listener_t
));
listener_cached
+=
sizeof
(
libvlc_event_listener_t
)
;
FOREACH_END
()
FOREACH_END
()
break
;
break
;
}
}
FOREACH_END
()
FOREACH_END
()
vlc_mutex_unlock
(
&
p_em
->
object_lock
);
listener_cached
=
array_listeners_cached
;
for
(
i
=
0
;
i
<
i_cached_listeners
;
i
++
)
{
listener_cached
->
pf_callback
(
p_event
,
listener_cached
->
p_user_data
);
listener_cached
+=
sizeof
(
libvlc_event_listener_t
)
;
}
free
(
array_listeners_cached
);
}
}
/*
/*
...
@@ -176,13 +208,16 @@ void libvlc_event_attach( libvlc_event_manager_t * p_event_manager,
...
@@ -176,13 +208,16 @@ void libvlc_event_attach( libvlc_event_manager_t * p_event_manager,
listener
->
p_user_data
=
p_user_data
;
listener
->
p_user_data
=
p_user_data
;
listener
->
pf_callback
=
pf_callback
;
listener
->
pf_callback
=
pf_callback
;
vlc_mutex_lock
(
&
p_event_manager
->
object_lock
);
FOREACH_ARRAY
(
listeners_group
,
p_event_manager
->
listeners_groups
)
FOREACH_ARRAY
(
listeners_group
,
p_event_manager
->
listeners_groups
)
if
(
listeners_group
->
event_type
==
listener
->
event_type
)
if
(
listeners_group
->
event_type
==
listener
->
event_type
)
{
{
ARRAY_APPEND
(
listeners_group
->
listeners
,
listener
);
ARRAY_APPEND
(
listeners_group
->
listeners
,
listener
);
vlc_mutex_unlock
(
&
p_event_manager
->
object_lock
);
return
;
return
;
}
}
FOREACH_END
()
FOREACH_END
()
vlc_mutex_unlock
(
&
p_event_manager
->
object_lock
);
free
(
listener
);
free
(
listener
);
libvlc_exception_raise
(
p_e
,
libvlc_exception_raise
(
p_e
,
...
@@ -203,6 +238,8 @@ void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
...
@@ -203,6 +238,8 @@ void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
{
{
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listeners_group_t
*
listeners_group
;
libvlc_event_listener_t
*
listener
;
libvlc_event_listener_t
*
listener
;
vlc_mutex_lock
(
&
p_event_manager
->
object_lock
);
FOREACH_ARRAY
(
listeners_group
,
p_event_manager
->
listeners_groups
)
FOREACH_ARRAY
(
listeners_group
,
p_event_manager
->
listeners_groups
)
if
(
listeners_group
->
event_type
==
event_type
)
if
(
listeners_group
->
event_type
==
event_type
)
{
{
...
@@ -216,14 +253,15 @@ void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
...
@@ -216,14 +253,15 @@ void libvlc_event_detach( libvlc_event_manager_t *p_event_manager,
ARRAY_REMOVE
(
listeners_group
->
listeners
,
ARRAY_REMOVE
(
listeners_group
->
listeners
,
fe_idx
/* This comes from the macro (and that's why
fe_idx
/* This comes from the macro (and that's why
I hate macro) */
);
I hate macro) */
);
vlc_mutex_unlock
(
&
p_event_manager
->
object_lock
);
return
;
return
;
}
}
FOREACH_END
()
FOREACH_END
()
}
}
FOREACH_END
()
FOREACH_END
()
vlc_mutex_unlock
(
&
p_event_manager
->
object_lock
);
libvlc_exception_raise
(
p_e
,
libvlc_exception_raise
(
p_e
,
"This object event manager doesn't know about '%i,%p,%p' event observer"
,
"This object event manager doesn't know about '%i,%p,%p' event observer"
,
event_type
,
pf_callback
,
p_user_data
);
event_type
,
pf_callback
,
p_user_data
);
}
}
src/control/libvlc_internal.h
View file @
257fdd4a
...
@@ -223,6 +223,7 @@ typedef struct libvlc_event_manager_t
...
@@ -223,6 +223,7 @@ typedef struct libvlc_event_manager_t
void
*
p_obj
;
void
*
p_obj
;
struct
libvlc_instance_t
*
p_libvlc_instance
;
struct
libvlc_instance_t
*
p_libvlc_instance
;
DECL_ARRAY
(
libvlc_event_listeners_group_t
*
)
listeners_groups
;
DECL_ARRAY
(
libvlc_event_listeners_group_t
*
)
listeners_groups
;
vlc_mutex_t
object_lock
;
}
libvlc_event_sender_t
;
}
libvlc_event_sender_t
;
...
@@ -247,8 +248,7 @@ VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
...
@@ -247,8 +248,7 @@ VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
(
libvlc_media_descriptor_t
*
)
);
(
libvlc_media_descriptor_t
*
)
);
/* Media List */
/* Media List */
VLC_EXPORT
(
void
,
libvlc_media_list_flat_media_list_release
,
VLC_EXPORT
(
void
,
libvlc_media_list_flat_media_list_release
,
(
libvlc_media_list_t
*
)
);
(
libvlc_media_list_t
*
)
);
/* Events */
/* Events */
VLC_EXPORT
(
void
,
libvlc_event_init
,
(
libvlc_instance_t
*
p_instance
,
libvlc_exception_t
*
p_e
)
);
VLC_EXPORT
(
void
,
libvlc_event_init
,
(
libvlc_instance_t
*
p_instance
,
libvlc_exception_t
*
p_e
)
);
...
...
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