From 32f79b1cfc3819a3af1e56f9bb6bf8ba03ecb2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Sun, 1 Nov 2009 13:10:40 +0000 Subject: better protection against NULL-pionters; sys_lock() the entire queue: do we have to lock the dequeue as well? svn path=/trunk/externals/hardware/wiimote/; revision=12712 --- wiimote.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wiimote.c b/wiimote.c index a0c8b94..3be07ae 100644 --- a/wiimote.c +++ b/wiimote.c @@ -488,6 +488,12 @@ static void wiimote_cwiid_error(t_wiimote *x, struct cwiid_error_mesg *mesg) { } static void wiimote_cwiid_message(t_wiimote *x, union cwiid_mesg*mesg) { + if(NULL==x){ + return; + } + if(NULL==mesg) { + return; + } switch (mesg->type) { case CWIID_MESG_STATUS: wiimote_cwiid_battery(x, mesg->status_mesg.battery); @@ -660,14 +666,12 @@ static void wiimote_queue(t_wiimote*x, union cwiid_mesg*mesg, double timestamp) } /* reset the clock */ - sys_lock(); clock_delay(g_clock, 0); - sys_unlock(); } #else static void wiimote_dequeue(void*nada) { - /* get all the messages from the queue that are scheduled until now */ + /* flush all the messages from the queue */ t_wiimoteMsgList*wl=g_wiimoteMsgList; t_wiimoteMsgList*next=NULL; @@ -770,6 +774,7 @@ static void cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count, pd_timestamp=wiimote_timestamp2logicaltime(x, timestamp); + sys_lock(); for (i=0; i < mesg_count; i++) { #if 1 wiimote_queue(x, mesg_array+i, pd_timestamp); @@ -777,6 +782,7 @@ static void cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count, wiimote_cwiid_message(x, mesg_array+i); #endif } + sys_unlock(); } // ============================================================== -- cgit v1.2.1