Commit 4983e340 authored by Zhenyu Wang's avatar Zhenyu Wang

xvmc: move locking code into generic place

parent bcd656c8
This diff is collapsed.
......@@ -68,12 +68,7 @@ typedef struct _i915XvMCContext {
unsigned int yStride;
unsigned int uvStride;
unsigned short ref;
pthread_mutex_t ctxmutex;
int lock; /* Lightweight lock to avoid locking twice */
int locked;
volatile drmI830Sarea *sarea;
drmLock *driHwLock;
drm_context_t hHWContext; /* drmcontext; */
unsigned int sarea_priv_offset; /* Offset in sarea to private part */
unsigned int depth;
......@@ -94,11 +89,7 @@ typedef struct _i915XvMCContext {
i915XvMCDrmMap ssb;
i915XvMCDrmMap psp;
i915XvMCDrmMap psc;
i915XvMCDrmMap corrdata;
sigset_t sa_mask;
} i915XvMCContext;
/***************************************************************************
......
......@@ -30,6 +30,35 @@ struct _intel_xvmc_driver *xvmc_driver = NULL;
static int error_base;
static int event_base;
/* locking */
static void intel_xvmc_try_heavy_lock(drm_context_t ctx)
{
drmGetLock(xvmc_driver->fd, ctx, 0);
}
void LOCK_HARDWARE(drm_context_t ctx)
{
char __ret = 0;
PPTHREAD_MUTEX_LOCK();
assert(!xvmc_driver->locked);
DRM_CAS(xvmc_driver->driHwLock, ctx,
(DRM_LOCK_HELD | ctx), __ret);
if (__ret)
intel_xvmc_try_heavy_lock(ctx);
xvmc_driver->locked = 1;
}
void UNLOCK_HARDWARE(drm_context_t ctx)
{
xvmc_driver->locked = 0;
DRM_UNLOCK(xvmc_driver->fd, xvmc_driver->driHwLock, ctx);
PPTHREAD_MUTEX_UNLOCK();
}
/*
* Function: XvMCCreateContext
* Description: Create a XvMC context for the given surface parameters.
......@@ -196,6 +225,9 @@ Status XvMCCreateContext(Display *display, XvPortID port,
free(priv_data);
return BadAlloc;
}
pSAREA = (drm_sarea_t *)xvmc_driver->sarea_address;
xvmc_driver->driHwLock = (drmLock *)&pSAREA->lock;
pthread_mutex_init(&xvmc_driver->ctxmutex, NULL);
/* call driver hook.
* driver hook should free priv_data after return if success.*/
......
......@@ -136,6 +136,12 @@ typedef struct _intel_xvmc_driver {
intel_xvmc_drm_map_t batchbuffer;
unsigned int last_render;
sigset_t sa_mask;
pthread_mutex_t ctxmutex;
int lock; /* Lightweight lock to avoid locking twice */
int locked;
drmLock *driHwLock;
void *private;
/* XXX: remove? */
......@@ -180,4 +186,31 @@ typedef struct _intel_xvmc_driver {
extern struct _intel_xvmc_driver i915_xvmc_mc_driver;
extern struct _intel_xvmc_driver *xvmc_driver;
#define SET_BLOCKED_SIGSET() do { \
sigset_t bl_mask; \
sigfillset(&bl_mask); \
sigdelset(&bl_mask, SIGFPE); \
sigdelset(&bl_mask, SIGILL); \
sigdelset(&bl_mask, SIGSEGV); \
sigdelset(&bl_mask, SIGBUS); \
sigdelset(&bl_mask, SIGKILL); \
pthread_sigmask(SIG_SETMASK, &bl_mask, &xvmc_driver->sa_mask); \
} while (0)
#define RESTORE_BLOCKED_SIGSET() do { \
pthread_sigmask(SIG_SETMASK, &xvmc_driver->sa_mask, NULL); \
} while (0)
#define PPTHREAD_MUTEX_LOCK() do { \
SET_BLOCKED_SIGSET(); \
pthread_mutex_lock(&xvmc_driver->ctxmutex); \
} while (0)
#define PPTHREAD_MUTEX_UNLOCK() do { \
pthread_mutex_unlock(&xvmc_driver->ctxmutex); \
RESTORE_BLOCKED_SIGSET(); \
} while (0)
extern void LOCK_HARDWARE(drm_context_t);
extern void UNLOCK_HARDWARE(drm_context_t);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment