[PD-cvs] pd/src d_soundfile.c,1.4.4.5,1.4.4.6

Tim Blechmann timblech at users.sourceforge.net
Sat Nov 27 11:22:39 CET 2004


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31244

Modified Files:
      Tag: devel_0_38
	d_soundfile.c 
Log Message:
using idle callbacks for thread synchronisation

Index: d_soundfile.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_soundfile.c,v
retrieving revision 1.4.4.5
retrieving revision 1.4.4.6
diff -C2 -d -r1.4.4.5 -r1.4.4.6
*** d_soundfile.c	26 Nov 2004 10:09:46 -0000	1.4.4.5
--- d_soundfile.c	27 Nov 2004 10:22:36 -0000	1.4.4.6
***************
*** 1141,1145 ****
      TB: adapted for threaded use
      */
! static t_int soundfiler_t_read_callback(t_int * w);
  
  static void soundfiler_t_read(t_soundfiler *x, t_symbol *s,
--- 1141,1150 ----
      TB: adapted for threaded use
      */
! 
! /* callback prototypes */
! static t_int soundfiler_read_update_garray(t_int * w);
! static t_int soundfiler_read_update_graphics(t_int * w);
! static t_int soundfiler_read_output(t_int * w);
! 
  
  static void soundfiler_t_read(t_soundfiler *x, t_symbol *s,
***************
*** 1166,1169 ****
--- 1171,1176 ----
  	pthread_cond_t resume_after_callback = PTHREAD_COND_INITIALIZER;
  	pthread_mutex_t resume_after_callback_mutex = PTHREAD_MUTEX_INITIALIZER; /* dummy */
+ 	t_int outargs[2];
+ 	
      while (argc > 0 && argv->a_type == A_SYMBOL &&
  		   *argv->a_w.w_symbol->s_name == '-')
***************
*** 1371,1377 ****
  		t_int w[4];
  		
- 		post("nvec %p",(char*)nvecs[i]);
- 		post("%d",finalsize);
- 
  		w[0] = (t_int)(garrays[i]);
  		w[1] = (t_int)nvecs[i];
--- 1378,1381 ----
***************
*** 1379,1383 ****
  		w[3] = (t_int)(&resume_after_callback);
  
! 		set_callback(&soundfiler_t_read_callback, w, 4);
  		pthread_cond_wait(&resume_after_callback, &resume_after_callback_mutex);
  
--- 1383,1387 ----
  		w[3] = (t_int)(&resume_after_callback);
  
! 		set_callback(&soundfiler_read_update_garray, w, 4);
  		pthread_cond_wait(&resume_after_callback, &resume_after_callback_mutex);
  
***************
*** 1388,1410 ****
  #endif
  
! 	/* todo: do all graphics updates */
! 
! 	/* run this in the main thread via callback */
! /* 	for (i = 0; i < argc; i++) */
! /* 	{ */
! /* 		t_glist *gl; */
! /* 		int n = finalsize; */
! /* 		/\* if this is the only array in the graph, */
! /* 		   reset the graph's coordinates *\/ */
! /* 		gl = garrays[i]->x_glist; */
! /* 		if (gl->gl_list == &garrays[i]->x_gobj && !garrays[i]->x_gobj.g_next) */
! /* 		{ */
! /* 			vmess(&gl->gl_pd, gensym("bounds"), "ffff", */
! /* 				  0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2); */
! /* 			/\* close any dialogs that might have the wrong info now... *\/ */
! /* 			gfxstub_deleteforkey(gl); */
! /* 		} */
! /* 		else garray_redraw(garrays[i]); */
! /* 	} */
  
   end:
--- 1392,1405 ----
  #endif
  
! 	/* do all graphics updates
! 	 * run this in the main thread via callback */
! 	for (i = 0; i < argc; i++)
! 	{
! 		t_int w[2];
! 		
! 		w[0] = (t_int)(garrays[i]);
! 		w[1] = (t_int)finalsize;
! 		set_callback(&soundfiler_read_update_graphics, w, 2);
! 	}
  
   end:
***************
*** 1430,1441 ****
  	post("bang");
  	
! 	/* todo: do this in the idle callback */
! /*     sys_lock(); */
! /* 	outlet_float(x->x_obj.ob_outlet, (float)itemsread);  */
! /*     sys_unlock(); */
  }
  
  /* idle callback for threadsafe synchronisation */
! static t_int soundfiler_t_read_callback(t_int * w)
  {
  	t_garray* garray = (t_garray*)w[0];
--- 1425,1435 ----
  	post("bang");
  	
! 	outargs[0] = (t_int)x->x_obj.ob_outlet;
! 	outargs[1] = (t_int)itemsread;
! 	set_callback(&soundfiler_read_output, outargs, 2);
  }
  
  /* idle callback for threadsafe synchronisation */
! static t_int soundfiler_read_update_garray(t_int * w)
  {
  	t_garray* garray = (t_garray*)w[0];
***************
*** 1459,1463 ****
  	garray->x_array.a_vec = (char *) nvec;
  	garray->x_array.a_n = finalsize;
! 	if (garray->x_usedindsp) canvas_update_dsp();
  
  #ifdef GARRAY_THREAD_LOCK
--- 1453,1457 ----
  	garray->x_array.a_vec = (char *) nvec;
  	garray->x_array.a_n = finalsize;
! /* 	if (garray->x_usedindsp) canvas_update_dsp(); */
  
  #ifdef GARRAY_THREAD_LOCK
***************
*** 1469,1472 ****
--- 1463,1468 ----
  	garray_unlock(garray);
  #endif
+ 
+ 	/* signal helper thread */
  	pthread_cond_broadcast(conditional);
  	
***************
*** 1474,1477 ****
--- 1470,1508 ----
  }
  
+ static t_int soundfiler_read_update_graphics(t_int * w)
+ {
+ 	t_garray* garray = (t_garray*) w[0];
+ 	t_glist *gl;
+ 	int n = w[1];
+ 	/* if this is the only array in the graph,
+ 	   reset the graph's coordinates */
+ 	gl = garray->x_glist;
+ 	if (gl->gl_list == &garray->x_gobj && !garray->x_gobj.g_next)
+ 	{
+ 		vmess(&gl->gl_pd, gensym("bounds"), "ffff",
+ 			  0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2);
+ 		/* close any dialogs that might have the wrong info now... */
+ 		gfxstub_deleteforkey(gl);
+ 	}
+ 	else 
+ 		garray_redraw(garray);
+ 
+ 	return 0;
+ }
+ 
+ 
+ static t_int soundfiler_read_output(t_int * w)
+ {
+ 	t_outlet* outlet = (t_outlet*) w[0];
+ 	float itemsread = (float) w[1];
+ 	
+ 	outlet_float (outlet, itemsread);
+ 	
+ 	return 0;
+ }
+ 
+ 
+ 
+ 
      /* this is broken out from soundfiler_write below so garray_write can
      call it too... not done yet though. */





More information about the Pd-cvs mailing list