[PD-cvs] pd/src s_inter.c,1.5.4.10.2.25.2.6,1.5.4.10.2.25.2.7

Mathieu Bouchard matju at users.sourceforge.net
Sun Dec 3 01:20:35 CET 2006


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

Modified Files:
      Tag: desiredata
	s_inter.c 
Log Message:
cleanup.


Index: s_inter.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v
retrieving revision 1.5.4.10.2.25.2.6
retrieving revision 1.5.4.10.2.25.2.7
diff -C2 -d -r1.5.4.10.2.25.2.6 -r1.5.4.10.2.25.2.7
*** s_inter.c	2 Dec 2006 05:21:51 -0000	1.5.4.10.2.25.2.6
--- s_inter.c	3 Dec 2006 00:20:33 -0000	1.5.4.10.2.25.2.7
***************
*** 11,14 ****
--- 11,15 ----
  #include "s_stuff.h"
  #include "m_imp.h"
+ #include "pthread.h"
  #ifdef UNISTD
  #include <unistd.h>
***************
*** 147,196 ****
  }
  
! 
! int sys_pollsockets (void)
! {
      struct timeval timout;
      int didsomething = 0;
! 	int i;
      t_fdpoll *fp;
!         fd_set readset, writeset, exceptset;
! 
      timout.tv_sec = 0;
      timout.tv_usec = 0;
- 
  	FD_ZERO(&writeset);
  	FD_ZERO(&readset);
  	FD_ZERO(&exceptset);
! 	for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++)
! 		FD_SET(fp->fdp_fd, &readset);
  	select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout);
  	for (i = 0; i < sys_nfdpoll; i++)
  		if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
          {
!             (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd);
              didsomething = 1;
          }
! 	return (didsomething);
  }
  
! void sys_microsleep(int microsec)
! {
! 	/* tb:
! 	   sleep granularity on "modern" operating systems is only 1ms??? 
! 
! 	   linux: we might be better with the high precision posix timer kernel
! 	   patches ...
! 	   
! 	   windows: win9x doesn't implement a SwitchToThread function, so we can't
! 	   sleep for small timeslices
! 
! 	   osx: ???
  	*/
! 
! 	if (!sys_callbackscheduler && microsec < 1000)
! 		if (500 < microsec)
!  			microsec = 1000;
! 		else
! 			return;
  #ifndef MSW
  	struct timeval timeout;
--- 148,182 ----
  }
  
! int sys_pollsockets (void) {
      struct timeval timout;
      int didsomething = 0;
!     int i;
      t_fdpoll *fp;
!     fd_set readset, writeset, exceptset;
      timout.tv_sec = 0;
      timout.tv_usec = 0;
  	FD_ZERO(&writeset);
  	FD_ZERO(&readset);
  	FD_ZERO(&exceptset);
! 	for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++) FD_SET(fp->fdp_fd, &readset);
  	select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout);
  	for (i = 0; i < sys_nfdpoll; i++)
  		if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset))
          {
!             sys_fdpoll[i].fdp_fn(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd);
              didsomething = 1;
          }
! 	return didsomething;
  }
  
! void sys_microsleep(int microsec) {
! 	/* Tim says: sleep granularity on "modern" operating systems is only 1ms???
! 	   - linux: we might be better with the high precision posix timer kernel patches ...
! 	   - windows: win9x doesn't implement a SwitchToThread function, so we can't sleep for small timeslices
! 	   - osx: ???
  	*/
! 	if (!sys_callbackscheduler && microsec < 1000) {
! 		if (500 < microsec) microsec = 1000; else return;
! 	}
  #ifndef MSW
  	struct timeval timeout;
***************
*** 202,212 ****
  	Sleep(microsec/1000);
  #endif
- 
  	/* a solution for lower timeslices might be a busysleep but this might
  	   block a low-priority thread and won't work for win9x
- 
  #define _WIN32_WINNT 0x0400
- 
- 	   
  	double end = sys_getrealtime() + (double)microsec * 1e-6;
  	do
--- 188,194 ----
***************
*** 219,223 ****
  	}
  	while(sys_getrealtime() < end);
- 
  	*/
  }
--- 201,204 ----
***************
*** 472,500 ****
  }
  
! static void socketreceiver_getudp(t_socketreceiver *x, int fd)
! {
      char buf[INBUFSIZE+1];
      int ret = recv(fd, buf, INBUFSIZE, 0);
!     if (ret < 0)
!     {
          sys_sockerror("recv");
          sys_rmpollfn(fd);
          sys_closesocket(fd);
!     }
!     else if (ret > 0)
!     {
          buf[ret] = 0;
! #if 0
!         post("%s", buf);
! #endif
!         if (buf[ret-1] != '\n')
!         {
! #if 0
!             buf[ret] = 0;
!             error("dropped bad buffer %s\n", buf);
! #endif
!         }
!         else
!         {
              char *semi = strchr(buf, ';');
              if (semi) 
--- 453,466 ----
  }
  
! static void socketreceiver_getudp(t_socketreceiver *x, int fd) {
      char buf[INBUFSIZE+1];
      int ret = recv(fd, buf, INBUFSIZE, 0);
!     if (ret < 0) {
          sys_sockerror("recv");
          sys_rmpollfn(fd);
          sys_closesocket(fd);
!     } else if (ret > 0) {
          buf[ret] = 0;
!         if (buf[ret-1] == '\n') {
              char *semi = strchr(buf, ';');
              if (semi) 
***************
*** 503,507 ****
              outlet_setstacklim();
              x->socketreceivefn(x->owner, inbinbuf);
!         }
      }
  }
--- 469,473 ----
              outlet_setstacklim();
              x->socketreceivefn(x->owner, inbinbuf);
!         } else {/*bad buffer ignored */}
      }
  }
***************
*** 597,601 ****
      int writesize = self->ohead-self->otail, nwrote = 0;
      if (!writesize) return 0;
-     fprintf(stderr,"sys_flushtogui self=%p writesize=%d\n",self,writesize);
      nwrote = send(self->fd, self->obuf+self->otail, writesize, 0);
      if (nwrote < 0) {
--- 563,566 ----
***************
*** 803,807 ****
  }
  
- #include "pthread.h"
  static pthread_t watchdog_id;
  static pthread_t main_pd_thread;
--- 768,771 ----
***************
*** 809,828 ****
  static pthread_cond_t watchdog_cond = PTHREAD_COND_INITIALIZER;
  
! static void * watchdog_thread(void*);
  
  /* start a high priority watchdog thread */
! static int sys_start_watchdog_thread(void)
! {
  	pthread_attr_t w_attr;
  	int status;
- 	
- 	/* get parent thread ID */
  	main_pd_thread = pthread_self();
- 	
- 	/* set up attributes */
  	pthread_attr_init(&w_attr);
- 	
  	pthread_attr_setschedpolicy(&w_attr, SCHED_FIFO); /* use rt scheduling */
- 	
  	status = pthread_create(&watchdog_id, &w_attr, (void*(*)(void*)) watchdog_thread, NULL);
  	return status; /* what is this function supposed to return anyway? it tried returning void though declared as int */
--- 773,785 ----
  static pthread_cond_t watchdog_cond = PTHREAD_COND_INITIALIZER;
  
! static void *watchdog_thread(void *);
  
  /* start a high priority watchdog thread */
! static int sys_start_watchdog_thread(void) {
  	pthread_attr_t w_attr;
  	int status;
  	main_pd_thread = pthread_self();
  	pthread_attr_init(&w_attr);
  	pthread_attr_setschedpolicy(&w_attr, SCHED_FIFO); /* use rt scheduling */
  	status = pthread_create(&watchdog_id, &w_attr, (void*(*)(void*)) watchdog_thread, NULL);
  	return status; /* what is this function supposed to return anyway? it tried returning void though declared as int */
***************
*** 849,886 ****
  */
  
! static void * watchdog_thread(void* dummy)
! {
  	sys_set_priority(1);
  	post("watchdog thread started");
- 
  	sys_microsleep(6e7); /* start polling after 60 seconds ... hoping that everything is set up */
- 
  	post("watchdog thread active");
! 
! 	while (1)
! 	{
! 		/* - register idle callback
! 		   - wait for condition variable
! 		   - in case of timeout kill the parent thread 
! 		   - sleep
! 		*/
  		struct timespec timeout;
  		struct timeval now;
- 		
  		int status;
- 		
  		gettimeofday(&now,0);
  		timeout.tv_sec = now.tv_sec + 15; /* timeout: 15 seconds */
  		timeout.tv_nsec = now.tv_usec * 1000;
- 		
  		sys_callback((t_int(*)(t_int*))watchdog_callback, 0, 0);
  		status = pthread_cond_timedwait(&watchdog_cond, &watchdog_mutex, &timeout);
! 		
! 		if (status)
! 		{
  #if defined(__linux__) || defined(IRIX)
  			fprintf(stderr, "watchdog killing");
! 			/* kill parent thread */
! 			kill(0,9);
  #endif
  		}
--- 806,827 ----
  */
  
! static void * watchdog_thread(void* dummy) {
  	sys_set_priority(1);
  	post("watchdog thread started");
  	sys_microsleep(6e7); /* start polling after 60 seconds ... hoping that everything is set up */
  	post("watchdog thread active");
! 	while (1) {
  		struct timespec timeout;
  		struct timeval now;
  		int status;
  		gettimeofday(&now,0);
  		timeout.tv_sec = now.tv_sec + 15; /* timeout: 15 seconds */
  		timeout.tv_nsec = now.tv_usec * 1000;
  		sys_callback((t_int(*)(t_int*))watchdog_callback, 0, 0);
  		status = pthread_cond_timedwait(&watchdog_cond, &watchdog_mutex, &timeout);
! 		if (status) {
  #if defined(__linux__) || defined(IRIX)
  			fprintf(stderr, "watchdog killing");
! 			kill(0,9); /* kill parent thread */
  #endif
  		}





More information about the Pd-cvs mailing list