Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
f98abe0e
Commit
f98abe0e
authored
Nov 30, 2015
by
Clément Bœsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avutil/threadmessage: add av_thread_message_flush()
parent
6596c6fc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
threadmessage.c
libavutil/threadmessage.c
+31
-0
threadmessage.h
libavutil/threadmessage.h
+16
-0
No files found.
libavutil/threadmessage.c
View file @
f98abe0e
...
@@ -40,6 +40,7 @@ struct AVThreadMessageQueue {
...
@@ -40,6 +40,7 @@ struct AVThreadMessageQueue {
int
err_send
;
int
err_send
;
int
err_recv
;
int
err_recv
;
unsigned
elsize
;
unsigned
elsize
;
void
(
*
free_func
)(
void
*
msg
);
#else
#else
int
dummy
;
int
dummy
;
#endif
#endif
...
@@ -81,10 +82,17 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
...
@@ -81,10 +82,17 @@ int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
#endif
/* HAVE_THREADS */
#endif
/* HAVE_THREADS */
}
}
void
av_thread_message_queue_set_free_func
(
AVThreadMessageQueue
*
mq
,
void
(
*
free_func
)(
void
*
msg
))
{
mq
->
free_func
=
free_func
;
}
void
av_thread_message_queue_free
(
AVThreadMessageQueue
**
mq
)
void
av_thread_message_queue_free
(
AVThreadMessageQueue
**
mq
)
{
{
#if HAVE_THREADS
#if HAVE_THREADS
if
(
*
mq
)
{
if
(
*
mq
)
{
av_thread_message_flush
(
*
mq
);
av_fifo_freep
(
&
(
*
mq
)
->
fifo
);
av_fifo_freep
(
&
(
*
mq
)
->
fifo
);
pthread_cond_destroy
(
&
(
*
mq
)
->
cond
);
pthread_cond_destroy
(
&
(
*
mq
)
->
cond
);
pthread_mutex_destroy
(
&
(
*
mq
)
->
lock
);
pthread_mutex_destroy
(
&
(
*
mq
)
->
lock
);
...
@@ -182,3 +190,26 @@ void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
...
@@ -182,3 +190,26 @@ void av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
pthread_mutex_unlock
(
&
mq
->
lock
);
pthread_mutex_unlock
(
&
mq
->
lock
);
#endif
/* HAVE_THREADS */
#endif
/* HAVE_THREADS */
}
}
static
void
free_func_wrap
(
void
*
arg
,
void
*
msg
,
int
size
)
{
AVThreadMessageQueue
*
mq
=
arg
;
mq
->
free_func
(
msg
);
}
void
av_thread_message_flush
(
AVThreadMessageQueue
*
mq
)
{
#if HAVE_THREADS
int
used
,
off
;
void
*
free_func
=
mq
->
free_func
;
pthread_mutex_lock
(
&
mq
->
lock
);
used
=
av_fifo_size
(
mq
->
fifo
);
if
(
free_func
)
for
(
off
=
0
;
off
<
used
;
off
+=
mq
->
elsize
)
av_fifo_generic_peek_at
(
mq
->
fifo
,
mq
,
off
,
mq
->
elsize
,
free_func_wrap
);
av_fifo_drain
(
mq
->
fifo
,
used
);
pthread_cond_broadcast
(
&
mq
->
cond
);
pthread_mutex_unlock
(
&
mq
->
lock
);
#endif
/* HAVE_THREADS */
}
libavutil/threadmessage.h
View file @
f98abe0e
...
@@ -88,4 +88,20 @@ void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq,
...
@@ -88,4 +88,20 @@ void av_thread_message_queue_set_err_send(AVThreadMessageQueue *mq,
void
av_thread_message_queue_set_err_recv
(
AVThreadMessageQueue
*
mq
,
void
av_thread_message_queue_set_err_recv
(
AVThreadMessageQueue
*
mq
,
int
err
);
int
err
);
/**
* Set the optional free message callback function which will be called if an
* operation is removing messages from the queue.
*/
void
av_thread_message_queue_set_free_func
(
AVThreadMessageQueue
*
mq
,
void
(
*
free_func
)(
void
*
msg
));
/**
* Flush the message queue
*
* This function is mostly equivalent to reading and free-ing every message
* except that it will be done in a single operation (no lock/unlock between
* reads).
*/
void
av_thread_message_flush
(
AVThreadMessageQueue
*
mq
);
#endif
/* AVUTIL_THREADMESSAGE_H */
#endif
/* AVUTIL_THREADMESSAGE_H */
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