[xf86-input-synaptics v3 04/14] Allocate SynapticsHwStruct for local function use

Chase Douglas chase.douglas at canonical.com
Fri Feb 10 11:56:48 PST 2012


SynapticsHwStruct (SHS) will soon include ValuatorMasks, which can only
be allocated on the heap. The input driver callbacks are called in
signal context, so we can't instantiate a new SHS when that occurs.
Since we only ever need one SHS, allocate one at device init time and
use it in place of local SHS instances.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/synaptics.c    |   22 +++++++++++++++-------
 src/synapticsstr.h |    2 ++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/synaptics.c b/src/synaptics.c
index a4c1e5a..e7deb9b 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -934,6 +934,7 @@ DeviceClose(DeviceIntPtr dev)
     TimerFree(priv->timer);
     priv->timer = NULL;
     free_shm_data(priv);
+    SynapticsHwStateFree(&priv->local_hw_state);
     return RetValue;
 }
 
@@ -1179,8 +1180,15 @@ no_touch:
 
     free(axes_labels);
 
+    priv->local_hw_state = SynapticsHwStateAlloc(priv);
+    if (!priv->local_hw_state)
+	return !Success;
+
     if (!alloc_shm_data(pInfo))
+    {
+	free(priv->local_hw_state);
 	return !Success;
+    }
 
     InitDeviceProperties(pInfo);
     XIRegisterPropertyHandler(pInfo->dev, SetProperty, NULL, NULL);
@@ -1310,15 +1318,15 @@ timerFunc(OsTimerPtr timer, CARD32 now, pointer arg)
 {
     InputInfoPtr pInfo = arg;
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
-    struct SynapticsHwState hw;
+    struct SynapticsHwState *hw = priv->local_hw_state;
     int delay;
     int sigstate;
 
     sigstate = xf86BlockSIGIO();
 
     priv->hwState.millis += now - priv->timer_time;
-    hw = priv->hwState;
-    delay = HandleState(pInfo, &hw, hw.millis, TRUE);
+    *hw = priv->hwState;
+    delay = HandleState(pInfo, hw, hw->millis, TRUE);
 
     priv->timer_time = now;
     priv->timer = TimerSet(priv->timer, 0, delay, timerFunc, pInfo);
@@ -1353,13 +1361,13 @@ static void
 ReadInput(InputInfoPtr pInfo)
 {
     SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
-    struct SynapticsHwState hw;
+    struct SynapticsHwState *hw = priv->local_hw_state;
     int delay = 0;
     Bool newDelay = FALSE;
 
-    while (SynapticsGetHwState(pInfo, priv, &hw)) {
-	priv->hwState = hw;
-	delay = HandleState(pInfo, &hw, hw.millis, FALSE);
+    while (SynapticsGetHwState(pInfo, priv, hw)) {
+	priv->hwState = *hw;
+	delay = HandleState(pInfo, hw, hw->millis, FALSE);
 	newDelay = TRUE;
     }
 
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index d3b8607..fff159c 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -201,6 +201,8 @@ typedef struct _SynapticsPrivateRec
 
     struct CommData comm;
 
+    struct SynapticsHwState *local_hw_state; /* used in place of local hw state variables */
+
     Bool absolute_events;               /* post absolute motion events instead of relative */
     SynapticsMoveHistRec move_hist[SYNAPTICS_MOVE_HISTORY]; /* movement history */
     int hist_index;			/* Last added entry in move_hist[] */
-- 
1.7.8.3



More information about the xorg-devel mailing list