Update of /cvsroot/pure-data/externals/io/hidio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20484
Modified Files: hidio.c Log Message: added more mutexes for thread safe operation, renamed hidio_read to hidio_child_read because it get's called by child thread
Index: hidio.c =================================================================== RCS file: /cvsroot/pure-data/externals/io/hidio/hidio.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** hidio.c 1 Dec 2006 19:40:46 -0000 1.7 --- hidio.c 2 Dec 2006 00:24:51 -0000 1.8 *************** *** 73,77 **** static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv); //static t_int hidio_close(t_hidio *x); ! //static t_int hidio_read(t_hidio *x); //static void hidio_float(t_hidio* x, t_floatarg f);
--- 73,77 ---- static void hidio_open(t_hidio *x, t_symbol *s, int argc, t_atom *argv); //static t_int hidio_close(t_hidio *x); ! //static t_int hidio_child_read(t_hidio *x); //static void hidio_float(t_hidio* x, t_floatarg f);
*************** *** 289,292 **** --- 289,293 ---- debug_print(LOG_DEBUG,"stop_poll");
+ pthread_mutex_lock(&x->x_mutex); if (x->x_started) { *************** *** 295,298 **** --- 296,300 ---- x->x_started = 0; } + pthread_mutex_unlock(&x->x_mutex); }
*************** *** 304,307 **** --- 306,310 ---- void hidio_poll(t_hidio* x, t_float f) { + pthread_mutex_lock(&x->x_mutex); debug_print(LOG_DEBUG,"hidio_poll");
*************** *** 313,318 **** if(x->x_device_number > -1) { ! if(!x->x_device_open) hidio_open(x,ps_open,0,NULL); if(!x->x_started) { --- 316,325 ---- if(x->x_device_number > -1) { ! if(!x->x_device_open) ! { ! pthread_mutex_unlock(&x->x_mutex); hidio_open(x,ps_open,0,NULL); + pthread_mutex_lock(&x->x_mutex); + } if(!x->x_started) { *************** *** 322,329 **** --- 329,338 ---- } } + pthread_mutex_unlock(&x->x_mutex); }
static void hidio_set_from_float(t_hidio *x, t_floatarg f) { + pthread_mutex_lock(&x->x_mutex); /* values greater than 1 set the polling delay time */ /* 1 and 0 for start/stop so you can use a [tgl] */ *************** *** 331,345 **** --- 340,363 ---- { x->x_delay = (t_int)f; + pthread_mutex_unlock(&x->x_mutex); hidio_poll(x,f); + pthread_mutex_lock(&x->x_mutex); } else if(f == 1) { if(! x->x_started) + { + pthread_mutex_unlock(&x->x_mutex); hidio_poll(x,f); + pthread_mutex_lock(&x->x_mutex); + } } else if(f == 0) { + pthread_mutex_unlock(&x->x_mutex); stop_poll(x); + pthread_mutex_lock(&x->x_mutex); } + pthread_mutex_unlock(&x->x_mutex); }
*************** *** 388,394 ****
! t_int hidio_read(t_hidio *x) { ! // debug_print(LOG_DEBUG,"hidio_read"); unsigned int i; #ifdef PD --- 406,413 ----
! /* read from event queue, called from child thread, no mutex needed */ ! t_int hidio_child_read(t_hidio *x) { ! // debug_print(LOG_DEBUG,"hidio_child_read"); unsigned int i; #ifdef PD *************** *** 517,521 **** { pthread_mutex_unlock(&x->x_mutex); ! hidio_read(x); pthread_mutex_lock(&x->x_mutex); if (x->x_requestcode == REQUEST_READ) --- 536,540 ---- { pthread_mutex_unlock(&x->x_mutex); ! hidio_child_read(x); pthread_mutex_lock(&x->x_mutex); if (x->x_requestcode == REQUEST_READ) *************** *** 652,668 **** unsigned int i; ! /* init vars */ ! global_debug_level = 9; /* high numbers here means see more messages */ ! x->x_has_ff = 0; ! x->x_device_open = 0; ! x->x_started = 0; ! x->x_delay = DEFAULT_DELAY; ! for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
! x->x_clock = clock_new(x, (method)hidio_tick);
! /* create anything outlet used for HID data */ ! x->x_status_outlet = outlet_new(x, "anything"); ! x->x_data_outlet = outlet_new(x, "anything"); #endif
--- 671,687 ---- unsigned int i; ! /* init vars */ ! global_debug_level = 9; /* high numbers here means see more messages */ ! x->x_has_ff = 0; ! x->x_device_open = 0; ! x->x_started = 0; ! x->x_delay = DEFAULT_DELAY; ! for(i=0; i<MAX_DEVICES; ++i) last_execute_time[i] = 0;
! x->x_clock = clock_new(x, (method)hidio_tick);
! /* create anything outlet used for HID data */ ! x->x_status_outlet = outlet_new(x, "anything"); ! x->x_data_outlet = outlet_new(x, "anything"); #endif
*************** *** 671,683 **** pthread_cond_init(&x->x_answercondition, 0);
! x->x_device_number = get_device_number_from_arguments(argc, argv);
! x->x_instance = hidio_instance_count; ! hidio_instance_count++;
x->x_requestcode = REQUEST_NOTHING; pthread_create(&x->x_thread, 0, hidio_child, x); ! return (x); }
--- 690,702 ---- pthread_cond_init(&x->x_answercondition, 0);
! x->x_device_number = get_device_number_from_arguments(argc, argv);
! x->x_instance = hidio_instance_count; ! hidio_instance_count++;
x->x_requestcode = REQUEST_NOTHING; pthread_create(&x->x_thread, 0, hidio_child, x); ! return (x); }