i965_drv_vidoe: thread safety for rendering 84/784/1
authorXiang, Haihao <haihao.xiang@intel.com>
Fri, 13 May 2011 07:45:22 +0000 (15:45 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Mon, 16 May 2011 03:57:39 +0000 (11:57 +0800)
i965_drv_video/Makefile.am
i965_drv_video/i965_drv_video.c
i965_drv_video/i965_drv_video.h
i965_drv_video/i965_mutext.h [new file with mode: 0644]
i965_drv_video/intel_compiler.h [new file with mode: 0644]
i965_drv_video/intel_driver.h

index 3fdc835..18772b0 100644 (file)
@@ -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
index a146e94..1a5e323 100644 (file)
@@ -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;
 
index 110109a..c0ff3d4 100644 (file)
@@ -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 (file)
index 0000000..57d4372
--- /dev/null
@@ -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 (file)
index 0000000..f1f24c8
--- /dev/null
@@ -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_ */
index 969767c..a1c97c4 100644 (file)
 
 #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