Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16922
Modified Files:
Tag: devel_0_38
m_obj.c
Added Files:
Tag: devel_0_38
m_atomic.h
Log Message:
thread-safe stack management
Index: m_obj.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_obj.c,v
retrieving revision 1.2.4.1
retrieving revision 1.2.4.2
diff -C2 -d -r1.2.4.1 -r1.2.4.2
*** m_obj.c 5 Nov 2004 14:27:46 -0000 1.2.4.1
--- m_obj.c 2 Jan 2005 19:56:02 -0000 1.2.4.2
***************
*** 12,16 ****
--- 12,26 ----
/* T.Grill - define for a modified, more portable method to detect stack overflows */
#define NEWSTACKMETH
+ /* tb: threadsafe stack overflow detection */
+ #ifdef ATOMIC
+ #include "m_atomic.h"
+ #define STACK_INC int* scp = &stackcount; ATOMIC_INC(scp)
+ #define STACK_DEC ATOMIC_DEC(scp)
+ #else /* ATOMIC */
+ #define STACK_INC ++stackcount
+ #define STACK_DEC --stackcount
+ #endif /* ATOMIC */
+ /* tb: } */
union inletunion
***************
*** 361,365 ****
t_outconnect *oc;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 371,376 ----
t_outconnect *oc;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 370,375 ****
for (oc = x->o_connections; oc; oc = oc->oc_next)
pd_bang(oc->oc_to);
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 381,387 ----
for (oc = x->o_connections; oc; oc = oc->oc_next)
pd_bang(oc->oc_to);
+ post("%d", stackcount);
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
***************
*** 380,384 ****
t_gpointer gpointer;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 392,397 ----
t_gpointer gpointer;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 400,404 ****
}
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 413,417 ----
}
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
***************
*** 408,412 ****
t_outconnect *oc;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 421,426 ----
t_outconnect *oc;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 418,422 ****
pd_float(oc->oc_to, f);
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 432,436 ----
pd_float(oc->oc_to, f);
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
***************
*** 426,430 ****
t_outconnect *oc;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 440,445 ----
t_outconnect *oc;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 436,440 ****
pd_symbol(oc->oc_to, s);
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 451,455 ----
pd_symbol(oc->oc_to, s);
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
***************
*** 444,448 ****
t_outconnect *oc;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 459,464 ----
t_outconnect *oc;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 454,458 ****
pd_list(oc->oc_to, s, argc, argv);
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 470,474 ----
pd_list(oc->oc_to, s, argc, argv);
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
***************
*** 462,466 ****
t_outconnect *oc;
#ifdef NEWSTACKMETH
! if(++stackcount >= STACKITER)
#else
char c;
--- 478,483 ----
t_outconnect *oc;
#ifdef NEWSTACKMETH
! STACK_INC;
! if(stackcount >= STACKITER)
#else
char c;
***************
*** 472,476 ****
typedmess(oc->oc_to, s, argc, argv);
#ifdef NEWSTACKMETH
! --stackcount;
#endif
}
--- 489,493 ----
typedmess(oc->oc_to, s, argc, argv);
#ifdef NEWSTACKMETH
! STACK_DEC;
#endif
}
--- NEW FILE: m_atomic.h ---
/* Copyright (c) 2005, Tim Blechmann
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt" in this distribution. */
#if defined(__GNUC__) && (defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__))
/* gcc, x86 */
#define ATOMIC_INC(X) \
asm __volatile__("lock incl (%0) \n" \
: :"r"(X) :"memory")
#define ATOMIC_DEC(X) \
asm __volatile__("lock decl (%0) \n" \
: :"r"(X) :"memory")
#elif defined(NT) && defined(_MSC_VER)
/* msvc */
#include <windows.h>
#define ATOMIC_INC(X) InterlockedIncrement(X)
#define ATOMIC_DEC(X) InterlockedDecrement(X)
#elif defined(__GNUC__) && defined(__POWERPC__)
/* ppc */
#define ATOMIC_INC(X) \
int X##_i; \
asm __volatile__( \
"1: \n" \
"lwarx %0, 0, %2 \n" \
"addic %0, %0, 1 \n" \
"stwcx %0, 0, %2 \n" \
"bne- 1b \n" \
:"=&r"(X##_i), "=m"(X) \
: "r" (&X), "m"(X) \
: "cc");
#define ATOMIC_DEC(X) \
int X##_i; \
asm __volatile__( \
"1: \n" \
"lwarx %0, 0, %2 \n" \
"addic %0, %0, -1 \n" \
"stwcx %0, 0, %2 \n" \
"bne- 1b \n" \
:"=&r"(i), "=m"(X) \
: "r" (X##_&X), "m"(X) \
: "cc");
#endif