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
db273325
Commit
db273325
authored
Jul 17, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pthread_frame: use a thread-safe way for signalling threads to die
Current code uses a plain int in a racy way, which is UB.
parent
8385ba53
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
pthread_frame.c
libavcodec/pthread_frame.c
+11
-9
No files found.
libavcodec/pthread_frame.c
View file @
db273325
...
...
@@ -90,6 +90,8 @@ typedef struct PerThreadContext {
AVFrame
*
requested_frame
;
///< AVFrame the codec passed to get_buffer()
int
requested_flags
;
///< flags passed to get_buffer() for requested_frame
int
die
;
///< Set when the thread should exit.
}
PerThreadContext
;
/**
...
...
@@ -108,8 +110,6 @@ typedef struct FrameThreadContext {
* Set for the first N packets, where N is the number of threads.
* While it is set, ff_thread_en/decode_frame won't return any results.
*/
int
die
;
///< Set when threads should exit.
}
FrameThreadContext
;
/**
...
...
@@ -122,20 +122,22 @@ typedef struct FrameThreadContext {
static
attribute_align_arg
void
*
frame_worker_thread
(
void
*
arg
)
{
PerThreadContext
*
p
=
arg
;
FrameThreadContext
*
fctx
=
p
->
parent
;
AVCodecContext
*
avctx
=
p
->
avctx
;
const
AVCodec
*
codec
=
avctx
->
codec
;
while
(
1
)
{
if
(
p
->
state
==
STATE_INPUT_READY
&&
!
fctx
->
die
)
{
if
(
p
->
state
==
STATE_INPUT_READY
)
{
pthread_mutex_lock
(
&
p
->
mutex
);
while
(
p
->
state
==
STATE_INPUT_READY
&&
!
fctx
->
die
)
while
(
p
->
state
==
STATE_INPUT_READY
)
{
if
(
p
->
die
)
{
pthread_mutex_unlock
(
&
p
->
mutex
);
goto
die
;
}
pthread_cond_wait
(
&
p
->
input_cond
,
&
p
->
mutex
);
}
pthread_mutex_unlock
(
&
p
->
mutex
);
}
if
(
fctx
->
die
)
break
;
if
(
!
codec
->
update_thread_context
&&
avctx
->
thread_safe_callbacks
)
ff_thread_finish_setup
(
avctx
);
...
...
@@ -161,6 +163,7 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
pthread_mutex_unlock
(
&
p
->
mutex
);
}
die:
return
NULL
;
}
...
...
@@ -504,12 +507,11 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
if
(
fctx
->
prev_thread
&&
fctx
->
prev_thread
!=
fctx
->
threads
)
update_context_from_thread
(
fctx
->
threads
->
avctx
,
fctx
->
prev_thread
->
avctx
,
0
);
fctx
->
die
=
1
;
for
(
i
=
0
;
i
<
thread_count
;
i
++
)
{
PerThreadContext
*
p
=
&
fctx
->
threads
[
i
];
pthread_mutex_lock
(
&
p
->
mutex
);
p
->
die
=
1
;
pthread_cond_signal
(
&
p
->
input_cond
);
pthread_mutex_unlock
(
&
p
->
mutex
);
...
...
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