Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
5b9bb4d9
Commit
5b9bb4d9
authored
May 01, 2014
by
Matt Oliver
Committed by
Michael Niedermayer
May 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opencl: add support for non-pthread locking
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
be098f62
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
opencl.c
libavutil/opencl.c
+41
-9
opencl.h
libavutil/opencl.h
+1
-0
No files found.
libavutil/opencl.c
View file @
5b9bb4d9
...
@@ -27,15 +27,20 @@
...
@@ -27,15 +27,20 @@
#include "avassert.h"
#include "avassert.h"
#include "opt.h"
#include "opt.h"
#if HAVE_THREADS
#if HAVE_PTHREADS
#if HAVE_PTHREADS
#include <pthread.h>
#include <pthread.h>
static
pthread_mutex_t
atomic_opencl_lock
=
PTHREAD_MUTEX_INITIALIZER
;
#elif HAVE_W32THREADS
#include "compat/w32pthreads.h"
#define LOCK_OPENCL pthread_mutex_lock(&atomic_opencl_lock)
#elif HAVE_OS2THREADS
#define UNLOCK_OPENCL pthread_mutex_unlock(&atomic_opencl_lock)
#include "compat/os2threads.h"
#endif
#include "atomic.h"
#elif !HAVE_THREADS
static
pthread_mutex_t
*
atomic_opencl_lock
=
NULL
;
#define LOCK_OPENCL pthread_mutex_lock(atomic_opencl_lock)
#define UNLOCK_OPENCL pthread_mutex_unlock(atomic_opencl_lock)
#else
#define LOCK_OPENCL
#define LOCK_OPENCL
#define UNLOCK_OPENCL
#define UNLOCK_OPENCL
#endif
#endif
...
@@ -321,9 +326,32 @@ void av_opencl_free_device_list(AVOpenCLDeviceList **device_list)
...
@@ -321,9 +326,32 @@ void av_opencl_free_device_list(AVOpenCLDeviceList **device_list)
av_freep
(
device_list
);
av_freep
(
device_list
);
}
}
inline
int
init_opencl_mtx
(
void
)
{
#if HAVE_THREADS
if
(
!
atomic_opencl_lock
)
{
int
err
;
pthread_mutex_t
*
tmp
=
av_malloc
(
sizeof
(
pthread_mutex_t
));
if
(
!
tmp
)
return
AVERROR
(
ENOMEM
);
if
((
err
=
pthread_mutex_init
(
tmp
,
NULL
)))
{
av_free
(
tmp
);
return
AVERROR
(
err
);
}
if
(
avpriv_atomic_ptr_cas
(
&
atomic_opencl_lock
,
NULL
,
tmp
))
{
pthread_mutex_destroy
(
tmp
);
av_free
(
tmp
);
}
}
#endif
return
0
;
}
int
av_opencl_set_option
(
const
char
*
key
,
const
char
*
val
)
int
av_opencl_set_option
(
const
char
*
key
,
const
char
*
val
)
{
{
int
ret
=
0
;
int
ret
=
init_opencl_mtx
(
);
if
(
ret
<
0
)
return
ret
;
LOCK_OPENCL
;
LOCK_OPENCL
;
if
(
!
opencl_ctx
.
opt_init_flag
)
{
if
(
!
opencl_ctx
.
opt_init_flag
)
{
av_opt_set_defaults
(
&
opencl_ctx
);
av_opt_set_defaults
(
&
opencl_ctx
);
...
@@ -368,7 +396,9 @@ void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env)
...
@@ -368,7 +396,9 @@ void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env)
int
av_opencl_register_kernel_code
(
const
char
*
kernel_code
)
int
av_opencl_register_kernel_code
(
const
char
*
kernel_code
)
{
{
int
i
,
ret
=
0
;
int
i
,
ret
=
init_opencl_mtx
(
);
if
(
ret
<
0
)
return
ret
;
LOCK_OPENCL
;
LOCK_OPENCL
;
if
(
opencl_ctx
.
kernel_code_count
>=
MAX_KERNEL_CODE_NUM
)
{
if
(
opencl_ctx
.
kernel_code_count
>=
MAX_KERNEL_CODE_NUM
)
{
av_log
(
&
opencl_ctx
,
AV_LOG_ERROR
,
av_log
(
&
opencl_ctx
,
AV_LOG_ERROR
,
...
@@ -553,7 +583,9 @@ static int init_opencl_env(OpenclContext *opencl_ctx, AVOpenCLExternalEnv *ext_o
...
@@ -553,7 +583,9 @@ static int init_opencl_env(OpenclContext *opencl_ctx, AVOpenCLExternalEnv *ext_o
int
av_opencl_init
(
AVOpenCLExternalEnv
*
ext_opencl_env
)
int
av_opencl_init
(
AVOpenCLExternalEnv
*
ext_opencl_env
)
{
{
int
ret
=
0
;
int
ret
=
init_opencl_mtx
(
);
if
(
ret
<
0
)
return
ret
;
LOCK_OPENCL
;
LOCK_OPENCL
;
if
(
!
opencl_ctx
.
init_count
)
{
if
(
!
opencl_ctx
.
init_count
)
{
if
(
!
opencl_ctx
.
opt_init_flag
)
{
if
(
!
opencl_ctx
.
opt_init_flag
)
{
...
...
libavutil/opencl.h
View file @
5b9bb4d9
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#else
#else
#include <OpenCL/cl.h>
#include <OpenCL/cl.h>
#endif
#endif
#include <stdint.h>
#include "dict.h"
#include "dict.h"
#include "libavutil/version.h"
#include "libavutil/version.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