summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBuddy Liong2015-05-05 14:24:39 -0500
committerBuddy Liong2015-05-05 14:24:39 -0500
commitfc0bd63ab3728743b0374a9696dd837f1012e913 (patch)
treeb3c8c9dfbc3bee9d6edab165a593b85d58b5a803
parent5146b13160d7d1cf0b828104503aa67a88e7cc6d (diff)
downloadhardware-ti-libdce-fc0bd63ab3728743b0374a9696dd837f1012e913.tar.gz
hardware-ti-libdce-fc0bd63ab3728743b0374a9696dd837f1012e913.tar.xz
hardware-ti-libdce-fc0bd63ab3728743b0374a9696dd837f1012e913.zip
libdce[LINUX] : Mutex protection support and other bug fixes
* The dce_init/dce_deinit APIs can be called multiple times by applications. This is called from multiple thread contexts in the viddec3test and is also invoked several times by the GStreamer framework. * But certain init functions and deinit operations need to be done only on the first and last calls of the respective APIs. * Additionally, according the pthread documentation we need to use **either** the PTHREAD_MUTEX_INITIALIZER or the pthread_mutex_init APIs with the attribs * The protection for the dce_init with the ref count mechanism is additionally needed for the mutex initialization because if this is not done conditionally (for the first dce_init) sequence, the subsequent call to this API would actually reinit the mutex value and cause the new thread sequence to acquire the same. Change-Id: I2d129a2b030a25c4e8c5f621abf05d68562db6b8 Signed-off-by: Karthik Ramanan <a0393906@ti.com> Signed-off-by: Buddy Liong <buddy.budiono@ti.com>
-rw-r--r--libdce.c6
-rw-r--r--libdce_linux.c32
2 files changed, 22 insertions, 16 deletions
diff --git a/libdce.c b/libdce.c
index 7704613..108d8f3 100644
--- a/libdce.c
+++ b/libdce.c
@@ -50,7 +50,13 @@
50/* Handle used for Remote Communication */ 50/* Handle used for Remote Communication */
51MmRpc_Handle MmRpcHandle[MAX_REMOTEDEVICES] = { NULL}; 51MmRpc_Handle MmRpcHandle[MAX_REMOTEDEVICES] = { NULL};
52Engine_Handle gEngineHandle[MAX_INSTANCES][MAX_REMOTEDEVICES] = { {NULL, NULL}}; 52Engine_Handle gEngineHandle[MAX_INSTANCES][MAX_REMOTEDEVICES] = { {NULL, NULL}};
53
54#ifdef BUILDOS_LINUX
55pthread_mutex_t ipc_mutex;
56#else
53pthread_mutex_t ipc_mutex = PTHREAD_MUTEX_INITIALIZER; 57pthread_mutex_t ipc_mutex = PTHREAD_MUTEX_INITIALIZER;
58#endif
59
54static int __ClientCount[MAX_REMOTEDEVICES] = {0}; 60static int __ClientCount[MAX_REMOTEDEVICES] = {0};
55int dce_debug = DCE_DEBUG_LEVEL; 61int dce_debug = DCE_DEBUG_LEVEL;
56const String DCE_DEVICE_NAME[MAX_REMOTEDEVICES]= {"rpmsg-dce","rpmsg-dce-dsp"}; 62const String DCE_DEVICE_NAME[MAX_REMOTEDEVICES]= {"rpmsg-dce","rpmsg-dce-dsp"};
diff --git a/libdce_linux.c b/libdce_linux.c
index 3de2e0a..43ea740 100644
--- a/libdce_linux.c
+++ b/libdce_linux.c
@@ -33,7 +33,6 @@
33#include <stdlib.h> 33#include <stdlib.h>
34#include <string.h> 34#include <string.h>
35#include <stdio.h> 35#include <stdio.h>
36
37#include <pthread.h> 36#include <pthread.h>
38 37
39#include <xf86drm.h> 38#include <xf86drm.h>
@@ -48,31 +47,33 @@
48 47
49#define INVALID_DRM_FD (-1) 48#define INVALID_DRM_FD (-1)
50 49
51int OmapDrm_FD = INVALID_DRM_FD; 50static int OmapDrm_FD = INVALID_DRM_FD;
52int bDrmOpenedByDce = FALSE; 51static int dce_init_count = 0;
53struct omap_device *OmapDev = NULL; 52struct omap_device *OmapDev = NULL;
54extern MmRpc_Handle MmRpcHandle[]; 53extern MmRpc_Handle MmRpcHandle[];
55
56extern pthread_mutex_t ipc_mutex; 54extern pthread_mutex_t ipc_mutex;
57 55
58void *dce_init(void) 56void *dce_init(void)
59{ 57{
60 dce_error_status eError = DCE_EOK; 58 dce_error_status eError = DCE_EOK;
59 pthread_mutexattr_t attr;
61 60
62 DEBUG(" >> dce_init"); 61 DEBUG(" >> dce_init");
63 62
64 pthread_mutexattr_t attr; 63 /* Use this for refcount */
65 pthread_mutexattr_init(&attr); 64 dce_init_count++;
66 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
67 pthread_mutex_init(&ipc_mutex, &attr);
68 65
69 /* Open omapdrm device */ 66 /* Open omapdrm device only for the first dce_init call */
70 if( OmapDrm_FD == INVALID_DRM_FD ) { 67 if( dce_init_count == 1 ) {
71 DEBUG("Open omapdrm device"); 68 DEBUG("Open omapdrm device and initializing the mutex...");
72 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00"); 69 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
73 _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL); 70 _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL);
74 bDrmOpenedByDce = TRUE; 71
72 pthread_mutexattr_init(&attr);
73 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
74 pthread_mutex_init(&ipc_mutex, &attr);
75 } 75 }
76
76 OmapDev = omap_device_new(OmapDrm_FD); 77 OmapDev = omap_device_new(OmapDrm_FD);
77 _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL); 78 _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL);
78 79
@@ -84,12 +85,11 @@ void dce_deinit(void *dev)
84{ 85{
85 omap_device_del(dev); 86 omap_device_del(dev);
86 dev = NULL; 87 dev = NULL;
87 if (bDrmOpenedByDce == TRUE) { 88 if (--dce_init_count == 0) {
89 DEBUG("Closing omapdrm device...");
88 close(OmapDrm_FD); 90 close(OmapDrm_FD);
89 bDrmOpenedByDce = FALSE; 91 OmapDrm_FD = INVALID_DRM_FD;
90 } 92 }
91 OmapDrm_FD = INVALID_DRM_FD;
92
93 return; 93 return;
94} 94}
95 95