diff options
author | Xiang, Haihao <haihao.xiang@intel.com> | 2011-05-13 15:45:22 +0800 |
---|---|---|
committer | Xiang, Haihao <haihao.xiang@intel.com> | 2011-05-16 11:57:39 +0800 |
commit | 1587cb7821d6e9f4ae52288c30d45e5b3a7ab7a1 (patch) | |
tree | 3e9fdd284dee443d53fd373b109a15c62a32d716 | |
parent | db1a88d199aa906b2aad1b5046e55151f6320dac (diff) |
i965_drv_vidoe: thread safety for rendering
-rw-r--r-- | i965_drv_video/Makefile.am | 6 | ||||
-rw-r--r-- | i965_drv_video/i965_drv_video.c | 7 | ||||
-rw-r--r-- | i965_drv_video/i965_drv_video.h | 3 | ||||
-rw-r--r-- | i965_drv_video/i965_mutext.h | 52 | ||||
-rw-r--r-- | i965_drv_video/intel_compiler.h | 15 | ||||
-rw-r--r-- | i965_drv_video/intel_driver.h | 6 |
6 files changed, 81 insertions, 8 deletions
diff --git a/i965_drv_video/Makefile.am b/i965_drv_video/Makefile.am index 3fdc835..18772b0 100644 --- a/i965_drv_video/Makefile.am +++ b/i965_drv_video/Makefile.am @@ -22,7 +22,7 @@ SUBDIRS = shaders -AM_CFLAGS = -Wall -I$(top_srcdir) -I$(top_srcdir)/va -I$(top_srcdir)/va/x11 @DRM_CFLAGS@ +AM_CFLAGS = -Wall -I$(top_srcdir) -I$(top_srcdir)/va -I$(top_srcdir)/va/x11 -DPTHREADS @DRM_CFLAGS@ i965_drv_video_la_LTLIBRARIES = i965_drv_video.la i965_drv_video_ladir = @LIBVA_DRIVERS_PATH@ @@ -69,4 +69,6 @@ noinst_HEADERS = \ gen6_mfd.h \ i965_encoder.h \ gen6_vme.h \ - gen6_mfc.h + gen6_mfc.h \ + intel_compiler.h \ + i965_mutext.h diff --git a/i965_drv_video/i965_drv_video.c b/i965_drv_video/i965_drv_video.c index a146e94..1a5e323 100644 --- a/i965_drv_video/i965_drv_video.c +++ b/i965_drv_video/i965_drv_video.c @@ -1649,6 +1649,7 @@ i965_Init(VADriverContextP ctx) if (i965_render_init(ctx) == False) return VA_STATUS_ERROR_UNKNOWN; + _i965InitMutex(&i965->render_mutex); i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER); return VA_STATUS_SUCCESS; @@ -2228,6 +2229,8 @@ i965_PutSurface(VADriverContextP ctx, if (!obj_surface || !obj_surface->bo) return VA_STATUS_SUCCESS; + _i965LockMutex(&i965->render_mutex); + dri_drawable = dri_get_drawable(ctx, (Drawable)draw); assert(dri_drawable); @@ -2295,6 +2298,8 @@ i965_PutSurface(VADriverContextP ctx, obj_surface->free_private_data(&obj_surface->private_data); } + _i965UnlockMutex(&i965->render_mutex); + return VA_STATUS_SUCCESS; } @@ -2306,6 +2311,8 @@ i965_Terminate(VADriverContextP ctx) if (i965->batch) intel_batchbuffer_free(i965->batch); + _i965DestroyMutex(&i965->render_mutex); + if (i965_render_terminate(ctx) == False) return VA_STATUS_ERROR_UNKNOWN; diff --git a/i965_drv_video/i965_drv_video.h b/i965_drv_video/i965_drv_video.h index 110109a..c0ff3d4 100644 --- a/i965_drv_video/i965_drv_video.h +++ b/i965_drv_video/i965_drv_video.h @@ -33,8 +33,8 @@ #include <va/va.h> #include <va/va_backend.h> +#include "i965_mutext.h" #include "object_heap.h" - #include "intel_driver.h" #define I965_MAX_PROFILES 11 @@ -217,6 +217,7 @@ struct i965_driver_data struct object_heap subpic_heap; struct hw_codec_info *codec_info; + _I965Mutex render_mutex; struct intel_batchbuffer *batch; struct i965_render_state render_state; void *pp_context; diff --git a/i965_drv_video/i965_mutext.h b/i965_drv_video/i965_mutext.h new file mode 100644 index 0000000..57d4372 --- /dev/null +++ b/i965_drv_video/i965_mutext.h @@ -0,0 +1,52 @@ +#ifndef _I965_MUTEX_H_ +#define _I965_MUTEX_H_ + +#include "intel_compiler.h" + +#if defined PTHREADS +#include <pthread.h> + +typedef pthread_mutex_t _I965Mutex; + +static INLINE void _i965InitMutex(_I965Mutex *m) +{ + pthread_mutex_init(m, NULL); +} + +static INLINE void +_i965DestroyMutex(_I965Mutex *m) +{ + pthread_mutex_destroy(m); +} + +static INLINE void +_i965LockMutex(_I965Mutex *m) +{ + pthread_mutex_lock(m); +} + +static INLINE void +_i965UnlockMutex(_I965Mutex *m) +{ + pthread_mutex_unlock(m); +} + +#define _I965_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +#define _I965_DECLARE_MUTEX(m) \ + _I965Mutex m = _I965_MUTEX_INITIALIZER + +#else + +typedef int _I965Mutex; +static INLINE void _i965InitMutex(_I965Mutex *m) { (void) m; } +static INLINE void _i965DestroyMutex(_I965Mutex *m) { (void) m; } +static INLINE void _i965LockMutex(_I965Mutex *m) { (void) m; } +static INLINE void _i965UnlockMutex(_I965Mutex *m) { (void) m; } + +#define _I965_MUTEX_INITIALIZER 0 +#define _I965_DECLARE_MUTEX(m) \ + _I965Mutex m = _I965_MUTEX_INITIALIZER + +#endif + +#endif /* _I965_MUTEX_H_ */ diff --git a/i965_drv_video/intel_compiler.h b/i965_drv_video/intel_compiler.h new file mode 100644 index 0000000..f1f24c8 --- /dev/null +++ b/i965_drv_video/intel_compiler.h @@ -0,0 +1,15 @@ +#ifndef _INTEL_COMPILER_H_ +#define _INTEL_COMPILER_H_ + +/** + * Function inlining + */ +#if defined(__GNUC__) +# define INLINE __inline__ +#elif (__STDC_VERSION__ >= 199901L) /* C99 */ +# define INLINE inline +#else +# define INLINE +#endif + +#endif /* _INTEL_COMPILER_H_ */ diff --git a/i965_drv_video/intel_driver.h b/i965_drv_video/intel_driver.h index 969767c..a1c97c4 100644 --- a/i965_drv_video/intel_driver.h +++ b/i965_drv_video/intel_driver.h @@ -11,11 +11,7 @@ #include <va/va_backend.h> -#if defined(__GNUC__) -#define INLINE __inline__ -#else -#define INLINE -#endif +#include "intel_compiler.h" #define BATCH_SIZE 0x80000 #define BATCH_RESERVED 0x10 |