[PD-cvs] pd/src m_class.c,1.3.4.2,1.3.4.3

Tim Blechmann timblech at users.sourceforge.net
Sun Nov 21 22:06:21 CET 2004


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

Modified Files:
      Tag: devel_0_38
	m_class.c 
Log Message:
thread safe dogensym()

Index: m_class.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_class.c,v
retrieving revision 1.3.4.2
retrieving revision 1.3.4.3
diff -C2 -d -r1.3.4.2 -r1.3.4.3
*** m_class.c	10 Nov 2004 18:29:50 -0000	1.3.4.2
--- m_class.c	21 Nov 2004 21:06:18 -0000	1.3.4.3
***************
*** 17,20 ****
--- 17,21 ----
  #include <stdarg.h>
  #include <string.h>
+ #include <pthread.h> /* tb: for hashtable locking */
  
  #ifdef QUALIFIED_NAME
***************
*** 503,511 ****
  #define HASHSIZE 1024
  
! static t_symbol *symhash[HASHSIZE];
! 
  t_symbol *dogensym(char *s, t_symbol *oldsym)
  {
!     t_symbol **sym1, *sym2;
      unsigned int hash1 = 0,  hash2 = 0;
      int length = 0;
--- 504,514 ----
  #define HASHSIZE 1024
  
! /* tb: made dogensym() threadsafe */
  t_symbol *dogensym(char *s, t_symbol *oldsym)
  {
! 	static t_symbol *symhash[HASHSIZE];
!     static pthread_mutex_t hash_lock = PTHREAD_MUTEX_INITIALIZER;
! 	
! 	t_symbol **sym1, *sym2;
      unsigned int hash1 = 0,  hash2 = 0;
      int length = 0;
***************
*** 524,527 ****
--- 527,545 ----
          sym1 = &sym2->s_next;
      }
+ 
+ 
+ 	pthread_mutex_lock(&hash_lock);
+ 	/* tb: maybe another thread added the symbol to the hash table
+ 	 *     double check */
+     while (sym2 = *sym1) 
+     {
+         if (!strcmp(sym2->s_name, s)) 
+ 		{
+ 			pthread_mutex_unlock(&hash_lock);
+ 			return(sym2);
+ 		}
+         sym1 = &sym2->s_next;
+     }
+ 
      if (oldsym) sym2 = oldsym;
      else
***************
*** 534,540 ****
--- 552,560 ----
      }
      *sym1 = sym2;
+ 	pthread_mutex_unlock(&hash_lock);
      return (sym2);
  }
  
+ 
  t_symbol *gensym(char *s)
  {





More information about the Pd-cvs mailing list