From 557f749d6f37082c8f97bc4458df826bd128e1c5 Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Fri, 23 May 2014 16:54:25 +0200
Subject: [PATCH] Removed dead feature PIKE_RUN_UNLOCKED

This feature has not worked since at least y2k
(5b15bb756813728027b8f9d6077ac0a3a1faaf0b)

In fact, it never did work very well even befor that, and has always
much slower than not running unlocked. Especially on multi-cpu
systems.
---
 src/block_alloc.h   |  73 ++------
 src/block_alloc_h.h |   7 +-
 src/global.h        |   7 -
 src/module.c        |   1 -
 src/multiset.h      |   3 -
 src/object.c        |   2 +
 src/pike_cpulib.h   | 421 --------------------------------------------
 src/stralloc.c      | 117 +-----------
 src/svalue.h        | 192 +-------------------
 9 files changed, 24 insertions(+), 799 deletions(-)

diff --git a/src/block_alloc.h b/src/block_alloc.h
index 8aa01452ef..ca4bba18c0 100644
--- a/src/block_alloc.h
+++ b/src/block_alloc.h
@@ -15,43 +15,15 @@
 #undef PTR_HASH_ALLOC_FILL_PAGES
 #undef PTR_HASH_ALLOC_FIXED_FILL_PAGES
 
-/* Define this to keep freed blocks around in a backlog, which can
- * help locating leftover pointers to other blocks. It can also hide
- * bugs since the blocks remain intact a while after they are freed.
- * Valgrind will immediately detect attempts to use blocks on the
- * backlog list, though. Only available with dmalloc debug. */
-/* #define DMALLOC_BLOCK_BACKLOG */
-
 #define INIT_BLOCK(X)
 #define EXIT_BLOCK(X)
 #define BLOCK_ALLOC_HSIZE_SHIFT 2
-
-#if defined (DMALLOC_BLOCK_BACKLOG) && defined (DEBUG_MALLOC)
-#define DO_IF_BLOCK_BACKLOG(X) X
-#define DO_IF_NOT_BLOCK_BACKLOG(X)
-#define BLOCK_ALLOC_USED real_used
-#else
-#define DO_IF_BLOCK_BACKLOG(X)
-#define DO_IF_NOT_BLOCK_BACKLOG(X) X
-#define BLOCK_ALLOC_USED used
-#endif
-
 #ifndef PIKE_HASH_T
 #define PIKE_HASH_T	size_t
 #endif /* !PIKE_HASH_T */
 
-#ifdef PIKE_RUN_UNLOCKED
-#include "threads.h"
-
-/* Block Alloc UnLocked */
-#define BA_UL(X) PIKE_CONCAT(X,_unlocked)
-#define BA_STATIC static
-#define BA_INLINE INLINE
-#else
-#define BA_UL(X) X
 #define BA_STATIC
 #define BA_INLINE
-#endif
 
 
 #define PTR_HASH_ALLOC_FILL_PAGES(DATA, PAGES)				\
@@ -123,7 +95,7 @@ struct DATA **PIKE_CONCAT(DATA,_hash_table)=0;				     \
 size_t PIKE_CONCAT(DATA,_hash_table_size)=0;				     \
 static size_t PIKE_CONCAT(num_,DATA)=0;					     \
 									     \
-static INLINE struct DATA *						     \
+static struct DATA *						     \
  PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(void *ptr,		     \
 					       PIKE_HASH_T hval)	     \
 {									     \
@@ -147,14 +119,11 @@ struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr)				     \
 {									     \
   struct DATA *p;                                                            \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   if(!PIKE_CONCAT(DATA,_hash_table)) {                                       \
-    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                \
     return 0;                                                                \
   }                                                                          \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval);		     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return p;								     \
 }									     \
 									     \
@@ -179,14 +148,11 @@ static struct DATA *PIKE_CONCAT(just_find_,DATA)(void *ptr)		     \
 {									     \
   struct DATA *p;                                                            \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   if(!PIKE_CONCAT(DATA,_hash_table)) {                                       \
-    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                \
     return 0;                                                                \
   }                                                                          \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   p=PIKE_CONCAT3(just_find_,DATA,_unlocked)(ptr, hval);			     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return p;								     \
 }									     \
 									     \
@@ -196,10 +162,8 @@ struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr)				     \
 {									     \
   struct DATA *p;							     \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr,hval);                            \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return p;								     \
 }									     \
 									     \
@@ -207,27 +171,22 @@ struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr)			 	     \
 {									     \
   struct DATA *p;							     \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   if(!(p=PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval)))          \
     p=PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval);		             \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return p;                                                                  \
 }									     \
 									     \
 int PIKE_CONCAT3(check_,DATA,_semaphore)(void *ptr)			     \
 {									     \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   if(PIKE_CONCAT3(really_low_find_,DATA,_unlocked)(ptr, hval))		     \
   {                                                                          \
-    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                \
     return 0;								     \
   }                                                                          \
 									     \
   PIKE_CONCAT3(make_,DATA,_unlocked)(ptr, hval);			     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return 1;								     \
 }									     \
 									     \
@@ -235,7 +194,6 @@ void PIKE_CONCAT(move_,DATA)(struct DATA *block, void *new_ptr)		     \
 {									     \
   struct DATA **pp, *p;							     \
   PIKE_HASH_T hval = ptr_hashfun(block->PTR_HASH_ALLOC_DATA);		     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));		     \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
   pp=PIKE_CONCAT(DATA,_hash_table) + hval;                                   \
   while((p = *pp))							     \
@@ -253,17 +211,14 @@ void PIKE_CONCAT(move_,DATA)(struct DATA *block, void *new_ptr)		     \
     ((PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1);		     \
   block->BLOCK_ALLOC_NEXT = PIKE_CONCAT(DATA,_hash_table)[hval];	     \
   PIKE_CONCAT(DATA,_hash_table)[hval] = block;				     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));		     \
 }									     \
 									     \
 int PIKE_CONCAT(remove_,DATA)(void *ptr)				     \
 {									     \
   struct DATA **pp, *p;							     \
   PIKE_HASH_T hval = ptr_hashfun(ptr);			                     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   if(!PIKE_CONCAT(DATA,_hash_table))                                         \
   {                                                                          \
-    DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                \
     return 0;				                                     \
   }                                                                          \
   hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;		     \
@@ -274,19 +229,16 @@ int PIKE_CONCAT(remove_,DATA)(void *ptr)				     \
     {									     \
       *pp = p->BLOCK_ALLOC_NEXT;					     \
       PIKE_CONCAT(num_,DATA)--;						     \
-      BA_UL(PIKE_CONCAT(really_free_,DATA))(p);				     \
-      DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));              \
+      PIKE_CONCAT(really_free_,DATA)(p);				     \
       return 1;								     \
     }									     \
     pp = &p->BLOCK_ALLOC_NEXT;						     \
   }									     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
   return 0;								     \
 }									     \
 									     \
-void PIKE_CONCAT3(low_init_,DATA,_hash)(size_t size)			     \
+static void PIKE_CONCAT3(low_init_,DATA,_hash)(size_t size)			     \
 {									     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   PIKE_CONCAT(DATA,_hash_table_size)=					     \
      ptr_hash_find_hashsize(size);                                           \
 									     \
@@ -299,30 +251,27 @@ void PIKE_CONCAT3(low_init_,DATA,_hash)(size_t size)			     \
   }									     \
   MEMSET(PIKE_CONCAT(DATA,_hash_table),0,				     \
 	 sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size));	     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
 }									     \
 									     \
 									     \
-void PIKE_CONCAT3(init_,DATA,_hash)(void)				     \
+static void PIKE_CONCAT3(init_,DATA,_hash)(void)				     \
 {									     \
   PIKE_CONCAT3(low_init_,DATA,_hash)(BSIZE);		                     \
 }									     \
 									     \
-void PIKE_CONCAT3(exit_,DATA,_hash)(void)				     \
+static void PIKE_CONCAT3(exit_,DATA,_hash)(void)				     \
 {									     \
-  DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));                    \
   ba_free_all(& PIKE_CONCAT(DATA,_allocator));                               \
   free(PIKE_CONCAT(DATA,_hash_table));					     \
   PIKE_CONCAT(DATA,_hash_table)=0;					     \
   PIKE_CONCAT(num_,DATA)=0;						     \
-  DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));                  \
 }
 
 #define PTR_HASH_ALLOC_FIXED(DATA,BSIZE)				     \
-struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval);\
+static struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval);\
 LOW_PTR_HASH_ALLOC(DATA,BSIZE)                                               \
 									     \
-struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval) \
+static struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval) \
 {									     \
   struct DATA *p;							     \
 									     \
@@ -330,7 +279,7 @@ struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval) \
     Pike_fatal("Hash table error!\n"); )				     \
   PIKE_CONCAT(num_,DATA)++;						     \
 									     \
-  p=BA_UL(PIKE_CONCAT(alloc_,DATA))();					     \
+  p=PIKE_CONCAT(alloc_,DATA)();                                              \
   p->PTR_HASH_ALLOC_DATA=ptr;						     \
   p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval];		     \
   PIKE_CONCAT(DATA,_hash_table)[hval]=p;				     \
@@ -339,7 +288,7 @@ struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr, PIKE_HASH_T hval) \
 
 
 #define PTR_HASH_ALLOC(DATA,BSIZE)					     \
-struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr,		     \
+static struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr,		     \
 						PIKE_HASH_T hval);	     \
 LOW_PTR_HASH_ALLOC(DATA,BSIZE)                                               \
                                                                              \
@@ -379,7 +328,7 @@ static void PIKE_CONCAT(DATA,_rehash)(void)				     \
   }									     \
 }									     \
 									     \
-struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr,		     \
+static struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr,		     \
 						PIKE_HASH_T hval)	     \
 {									     \
   struct DATA *p;							     \
@@ -396,7 +345,7 @@ struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)(void *ptr,		     \
     hval &= (PIKE_HASH_T)PIKE_CONCAT(DATA,_hash_table_size) - 1;	     \
   }									     \
 									     \
-  p=BA_UL(PIKE_CONCAT(alloc_,DATA))();					     \
+  p=PIKE_CONCAT(alloc_,DATA)();                                              \
   p->PTR_HASH_ALLOC_DATA=ptr;						     \
   p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval];		     \
   PIKE_CONCAT(DATA,_hash_table)[hval]=p;				     \
diff --git a/src/block_alloc_h.h b/src/block_alloc_h.h
index 24fa542279..37cd38c82d 100644
--- a/src/block_alloc_h.h
+++ b/src/block_alloc_h.h
@@ -30,16 +30,11 @@ BLOCK_ALLOC(DATA,BSIZE);					\
 extern struct DATA **PIKE_CONCAT(DATA,_hash_table);		\
 extern size_t PIKE_CONCAT(DATA,_hash_table_size);		\
 struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr);		\
-struct DATA *PIKE_CONCAT3(make_,DATA,_unlocked)			\
-		(void *ptr, PIKE_HASH_T hval);			\
 struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr);		\
 struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr);			\
 int PIKE_CONCAT3(check_,DATA,_semaphore)(void *ptr);		\
 void PIKE_CONCAT(move_,DATA)(struct DATA *block, void *new_ptr); \
-int PIKE_CONCAT(remove_,DATA)(void *ptr);			\
-void PIKE_CONCAT3(low_init_,DATA,_hash)(size_t);		\
-void PIKE_CONCAT3(init_,DATA,_hash)(void);			\
-void PIKE_CONCAT3(exit_,DATA,_hash)(void);
+int PIKE_CONCAT(remove_,DATA)(void *ptr);
 
 #define PTR_HASH_ALLOC_FIXED(DATA,BSIZE)			\
 PTR_HASH_ALLOC(DATA,BSIZE)
diff --git a/src/global.h b/src/global.h
index d882f2f8dc..7522a868f4 100644
--- a/src/global.h
+++ b/src/global.h
@@ -695,14 +695,7 @@ char *crypt(const char *, const char *);
 /* Compatibility... */
 #define USE_PIKE_TYPE	2
 
-#ifdef PIKE_RUN_UNLOCKED
-#define DO_IF_RUN_UNLOCKED(X) X
-#else
-#define DO_IF_RUN_UNLOCKED(X)
-#endif
-
 /* Used in more than one place, better put it here */
-
 #if defined(PROFILING)
 #define DO_IF_PROFILING(X) X
 #else
diff --git a/src/module.c b/src/module.c
index 1f6f02293e..25bfdf5340 100644
--- a/src/module.c
+++ b/src/module.c
@@ -350,7 +350,6 @@ static void exit_builtin_modules(void)
 
   cleanup_callbacks();
   free_all_callable_blocks();
-  exit_destroy_called_mark_hash();
 
   cleanup_pike_type_table();
   cleanup_shared_string_table();
diff --git a/src/multiset.h b/src/multiset.h
index 591764fcae..10a73018e1 100644
--- a/src/multiset.h
+++ b/src/multiset.h
@@ -52,9 +52,6 @@ union msnode
 struct multiset_data
 {
   INT32 refs, noval_refs;
-#ifdef PIKE_RUN_UNLOCKED
-#error multiset_data has not been adapted for running unlocked.
-#endif
   union msnode *root, *free_list;
   struct svalue cmp_less;
   INT32 size, allocsize;
diff --git a/src/object.c b/src/object.c
index 96a4509568..7afbc3aaed 100644
--- a/src/object.c
+++ b/src/object.c
@@ -3279,6 +3279,8 @@ void exit_object(void)
     free_program(magic_types_program);
     magic_types_program=0;
   }
+
+  exit_destroy_called_mark_hash();
 }
 
 #ifdef PIKE_DEBUG
diff --git a/src/pike_cpulib.h b/src/pike_cpulib.h
index 318d88539d..a7575f421e 100644
--- a/src/pike_cpulib.h
+++ b/src/pike_cpulib.h
@@ -56,427 +56,6 @@ PMOD_EXPORT void x86_get_cpuid(int oper, INT32 *cpuid_ptr);
 #endif
 #endif
 
-/* FIXME: Should we have an #ifdef PIKE_RUN_UNLOCKED here? -Hubbe
- * Good side: No problems compiling unless --run-unlocked is used
- * Bad side: Can't use these things for other purposes..
- */
-/* Since the memlock stuff doesn't work yet, I disable the code for now.
- *	/grubba
- */
-#ifdef PIKE_RUN_UNLOCKED
-
-#define pike_atomic_fool_gcc(x) (*(volatile struct { int a[100]; } *)x)
-
-
-/* These will work on any cpu, but should only be used as a
- * last resort. We must also define PIKE_NEED_MEMLOCK if we
- * use these. /Hubbe
- */
-#define BEGIN_MEMORY_LOCK(ADDR) do { \
-    PIKE_MUTEX_T *pike_mem_mutex=pike_memory_locks+ \
-        ((unsigned long)(ADDR))%PIKE_MEM_HASH; \
-    mt_lock(pike_mem_mutex)
-
-#define END_MEMORY_LOCK()  \
-    mt_unlock(pike_mem_mutex);  \
-  }while(0)
-
-#define pike_memlock(ADDR) do{				\
-    PIKE_MUTEX_T *pike_mem_mutex=pike_memory_locks+	\
-        ((unsigned long)(ADDR))%PIKE_MEM_HASH;		\
-    mt_lock(pike_mem_mutex)				\
-}while(0)
-
-#define pike_unmemlock(ADDR) do{			\
-    PIKE_MUTEX_T *pike_mem_mutex=pike_memory_locks+	\
-        ((unsigned long)(ADDR))%PIKE_MEM_HASH;		\
-    mt_unlock(pike_mem_mutex)				\
-}while(0)
-
-#define PIKE_NEED_MEMLOCK
-
-/* Autoconf this? */
-#if defined(__i386__) && defined(__GNUC__)
-
-/*
- * ia32 general purpose registers
- * "a" = %eax, "b" = %edx, "c" = %ecx, "d" = %edx
- * "S" = %esi, "D" = %edi, "B" = %ebp
- */
-
-
-#define PIKE_HAS_INC32
-static INLINE void pike_atomic_inc32(volatile INT32 *v)
-{
-  __asm__ __volatile__("lock ; incl %0"
-		       :"=m" (pike_atomic_fool_gcc(v))
-		       :"m" (pike_atomic_fool_gcc(v))
-                       :"cc");
-}
-
-
-#define PIKE_HAS_DEC_AND_TEST32
-static INLINE int pike_atomic_dec_and_test32(INT32 *v)
-{
-  unsigned char c;
-
-  __asm__ __volatile__("lock ; decl %0; setne %1"
-		       :"=m" (pike_atomic_fool_gcc(v)), "=qm" (c)
-		       :"m" (pike_atomic_fool_gcc(v))
-                       :"cc");
-  return c;
-}
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  char ret;
-  INT32 readval;
-
-  __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
-			: "=q" (ret), "=m" (*p), "=a" (readval)
-			: "r" (newval), "m" (*p), "a" (oldval)
-			: "cc", "memory");
-  return ret;
-}
-
-
-/* NOT USED */
-#define PIKE_HAS_COMPARE_AND_SWAP64
-static INLINE int
-pike_atomic_compare_and_swap64 (INT64 *p, INT64 oldval, INT64 newval)
-{
-  char ret;
-#define HIGH(X) ((INT32 *)&(X))[1]
-#define LOW(X) ((INT32 *)&(X))[0]
-
-#if 1
-  INT32 t1, t2, t3;
-/*fprintf(stderr,"cas64(%p(%llx),%llx,%llx) << %d\n",p,*p,oldval,newval,ret);*/
-#if 0
-  __asm__ __volatile__ (
-    "xchgl %%ebx, %%edi ;"
-    "lock; cmpxchg8b (%%esi); sete %%al;"
-    "movl  %%edi, %%ebx; "
-    "movb  %%al, %0 "
-    :"=q" (ret),
-     "=a" (t1),"=d" (t2),"=D" (t3)
-    :"S" (p),
-     "1" (LOW(oldval)), "2" (HIGH(oldval)),
-     "3" (LOW(newval)), "c" (HIGH(newval))
-    :"cc", "memory");
-#else
-  __asm__ __volatile__ (
-    "xchgl %%ebx, %%edi ;"
-    "lock; cmpxchg8b (%%esi); sete %%al;"
-    "movl  %%edi, %%ebx; "
-    "movb  %%al, %0 "
-    :"=q" (ret),
-     "=a" (t1),"=d" (t2),"=D" (t3)
-    :"S" (p),
-     "a" (LOW(oldval)), "d" (HIGH(oldval)),
-     "D" (LOW(newval)), "c" (HIGH(newval))
-    :"cc", "memory");
-#endif
-/*fprintf(stderr,"cas64(%p(%llx),%llx,%llx) => %d\n",p,*p,oldval,newval,ret);*/
-#else
-  INT32 readval;
-  /* this doesn't work because GCC use %ebp for PIC code */
-  __asm__ __volatile__ ("lock; cmpxchg8b (%1); sete %0"
-			:"=q" (ret), "=m" (*p)
-			:"r" (newval), "m" (*p),
-			 "a" (LOW(oldval)),"d" (HIGH(oldval)),
-			 "b" (LOW(newval)),"c" (HIGH(newval))
-			: "cc", "memory");
-#endif
-  return ret;
-}
-
-#endif /* __i386__ && __GNUC__ */
-
-#if defined(__ia64__) && defined(__GNUC__)
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  INT32 ret;
-
-  __asm__ __volatile__ ("mov ar.ccv = %1;\n"
-			"\t;;\n"
-			"\tcmpxchg4.rel.nta %0 = [%2], %3, ar.ccv"
-			: "=r" (ret)
-			: "r" (oldval), "r" (p), "r" (newval)
-			: "memory", "ar.ccv");
-  return ret == oldval;
-}
-
-#endif /* __ia64__ && __GNUC__ */
-
-#if defined(_M_IA64)
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  return _InterlockedCompareExchange(p, newval, oldval) == oldval;
-}
-
-#endif /* _M_IA64 */
-
-#if defined(__sparc_v9__) && defined(__GNUC__)
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  __asm__ __volatile__ ("membar #LoadStore\n"
-			"cas [%2], %3, %0"
-			: "=r" (newval)
-			: "0" (newval), "r" (p), "r" (oldval)
-			: "memory");
-  return newval == oldval;
-}
-
-#endif /* __sparc_v9__ && __GNUC__ */
-
-#if defined(__m68k__) && defined(__GNUC__)
-
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  INT32 cmpval = oldval;
-
-  /* if (oldval == *p) {
-   *   *p = newval;
-   * } else {
-   *   oldval = *p;
-   * }
-   */
-  __asm__ __volatile__ ("casl %0, %3, %1;"
-			: "=d" (oldval), "=m", (*p)
-			: "0" (oldval), "d" (newval), "0" (p)
-			: "memory");
-  return oldval == cmpval;
-}
-
-#endif /* __m68k__ && __GNUC__ */
-
-
-
-/*
- * These functions are used if we don't have
- * compare-and-swap instructions available
- */
-#ifndef PIKE_HAS_COMPARE_AND_SWAP32
-
-#define PIKE_HAS_COMPARE_AND_SWAP32
-#undef PIKE_NEED_MEMLOCK
-#define PIKE_NEED_MEMLOCK
-
-#include "threads.h"
-
-static INLINE int
-pike_atomic_compare_and_swap32 (INT32 *p, INT32 oldval, INT32 newval)
-{
-  int ret;
-  BEGIN_MEMORY_LOCK(p);
-  if(ret == (*p == oldval)) *p=newval;
-  END_MEMORY_LOCK();
-  return ret;
-}
-
-
-#ifndef PIKE_HAS_INC32
-#define PIKE_HAS_INC32
-static INLINE void pike_atomic_inc32(INT32 *ref)
-{
-  BEGIN_MEMORY_LOCK(p);
-  ref++;
-  END_MEMORY_LOCK();
-}
-#endif /* PIKE_HAS_INC32 */
-
-#ifndef PIKE_HAS_DEC_AND_TEST32
-#define PIKE_HAS_DEC_AND_TEST32
-static INLINE int pike_atomic_dec_and_test32(INT32 *ref)
-{
-  INT32 ret;
-  BEGIN_MEMORY_LOCK(p);
-  ret=--ref;
-  END_MEMORY_LOCK();
-  return ret;
-}
-#endif /*  PIKE_HAS_DEC_AND_TEST32 */
-
-
-
-#ifndef PIKE_HAS_SWAP32
-#define PIKE_HAS_SWAP32
-static INLINE INT32 pike_atomic_swap32(INT32 *addr, INT32 newval)
-{
-  INT32 ret;
-  BEGIN_MEMORY_LOCK(p);
-  ret=*addr;
-  *addr=newval;
-  END_MEMORY_LOCK();
-  return ret;
-}
-#endif
-
-#endif /* PIKE_HAS_COMPARE_AND_SWAP32 */
-
-#if !defined(PIKE_HAS_COMPARE_AND_SWAP64) && defined(INT64)
-
-#define PIKE_HAS_COMPARE_AND_SWAP64
-#undef PIKE_NEED_MEMLOCK
-#define PIKE_NEED_MEMLOCK
-
-#include "threads.h"
-
-static INLINE int
-pike_atomic_compare_and_swap64 (INT64 *p, INT64 oldval, INT64 newval)
-{
-  int ret;
-  BEGIN_MEMORY_LOCK(p);
-  if(ret == (*p == oldval)) *p=newval;
-  END_MEMORY_LOCK();
-  return ret;
-}
-
-
-#ifndef PIKE_HAS_SWAP64
-#define PIKE_HAS_SWAP64
-static INLINE INT64 pike_atomic_swap64(INT64 *addr, INT64 newval)
-{
-  INT64 ret;
-  BEGIN_MEMORY_LOCK(p);
-  ret=*addr;
-  *addr=newval;
-  END_MEMORY_LOCK();
-  return ret;
-}
-#endif
-
-
-#ifndef PIKE_HAS_SET64
-#define PIKE_HAS_SET64
-static INLINE void pike_atomic_set64(INT64 *addr, INT64 newval)
-{
-  BEGIN_MEMORY_LOCK(p);
-  *addr=newval;
-  END_MEMORY_LOCK();
-}
-#endif
-
-#ifndef PIKE_HAS_GET64
-#define PIKE_HAS_GET64
-static INLINE INT64 pike_atomic_get64(INT64 *addr)
-{
-  INT64 ret;
-  BEGIN_MEMORY_LOCK(p);
-  ret=*addr;
-  END_MEMORY_LOCK();
-  return ret;
-}
-#endif
-
-
-#endif /* PIKE_HAS_COMPARE_AND_SWAP64 */
-
-
-
-/* These functions are used if we have
- * compare-and-swap, but not the rest of
- * the atomic functions
- */
-
-#if defined(PIKE_HAS_COMPARE_AND_SWAP32) && !defined(PIKE_HAS_INC32)
-#define PIKE_HAS_INC32
-static INLINE void pike_atomic_inc32(INT32 *ref)
-{
-  INT32 oldrefs;
-  do 
-    oldrefs=*ref;
-  while(! pike_atomic_compare_and_swap32(ref, oldrefs, oldrefs+1));
-}
-#endif
-
-
-#if defined(PIKE_HAS_COMPARE_AND_SWAP32) && !defined(PIKE_HAS_DEC_AND_TEST32)
-#define PIKE_HAS_DEC_AND_TEST32
-static INLINE int pike_atomic_dec_and_test32(INT32 *ref)
-{
-  INT32 oldrefs;
-  do 
-    oldrefs=*ref;
-  while(! pike_atomic_compare_and_swap32(ref, oldrefs, oldrefs-1));
-  return oldrefs-1;
-}
-#endif
-
-
-#if defined(PIKE_HAS_COMPARE_AND_SWAP32) && !defined(PIKE_HAS_SWAP32)
-#define PIKE_HAS_SWAP32
-static INLINE INT32 pike_atomic_swap32(INT32 *addr, INT32 newval)
-{
-  INT32 ret;
-  do
-  {
-    ret=*addr;
-  }while(!pike_atomic_compare_and_swap32(addr, ret, newval));
-  return ret;
-}
-#endif
-
-
-#if defined(PIKE_HAS_COMPARE_AND_SWAP64) && !defined(PIKE_HAS_SWAP64)
-#define PIKE_HAS_SWAP64
-static INLINE INT64 pike_atomic_swap64(INT64 *addr, INT64 newval)
-{
-  INT64 ret;
-  do
-  {
-    ret=*addr;
-  }while(!pike_atomic_compare_and_swap64(addr, ret, newval));
-  return ret;
-}
-#endif
-
-
-
-#if defined(PIKE_HAS_SWAP64) && !defined(PIKE_HAS_SET64)
-#define PIKE_HAS_SET64
-static INLINE void pike_atomic_set64(INT64 *addr, INT64 newval)
-{
-  pike_atomic_swap64(addr, newval);
-}
-#endif
-
-#if defined(PIKE_HAS_COMPARE_AND_SWAP64) && !defined(PIKE_HAS_GET64)
-#define PIKE_HAS_GET64
-static INLINE INT64 pike_atomic_get64(INT64 *addr)
-{
-  INT64 ret;
-  do
-  {
-    ret=*addr;
-  }while(!pike_atomic_compare_and_swap64(addr, ret, ret));
-  return ret;
-}
-#endif
-
-/* End emulating functions */
-
-#endif /* PIKE_RUN_UNLOCKED */
-
 #ifdef PIKE_NEED_MEMLOCK
 extern void init_pike_cpulib(void);
 #else
diff --git a/src/stralloc.c b/src/stralloc.c
index 54c483957a..e9aca391ae 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -40,37 +40,6 @@ static unsigned INT32 htable_mask;
 #define ULONG_MAX	UINT_MAX
 #endif
 
-#if PIKE_RUN_UNLOCKED
-/* Make this bigger when we get lightweight threads */
-#define BUCKET_LOCKS 2048
-static PIKE_MUTEX_T *bucket_locks;
-
-#define BUCKETLOCK(HVAL) \
- (bucket_locks + (HMODULO(hval__) & (BUCKET_LOCKS-1)))
-
-#define LOCK_BUCKET(HVAL) do {						    \
-  size_t hval__=(HVAL);							    \
-  PIKE_MUTEX_T *bucket_lock;						    \
-  while(1)								    \
-  {									    \
-    bucket_lock=BUCKETLOCK(hval__);                                         \
-    mt_lock(bucket_lock);						    \
-    if(bucket_lock == BUCKETLOCK(hval__))                                   \
-      break;								    \
-    mt_unlock(bucket_lock);						    \
-  }									    \
-}while(0)
-
-#define UNLOCK_BUCKET(HVAL) do {			\
-  size_t hval__=(HVAL);					\
-  mt_unlock(BUCKETLOCK(hval__));                        \
-}while(0)
-
-#else
-#define LOCK_BUCKET(HVAL)
-#define UNLOCK_BUCKET(HVAL)
-#endif /* PIKE_RUN_UNLOCKED */
-
 #define BEGIN_HASH_SIZE 1024
 
 static unsigned int hash_prefix_len=64;
@@ -414,7 +383,6 @@ static void locate_problem(int (*isproblem)(const struct pike_string *))
 
   for(e=0;e<htable_size;e++)
   {
-    LOCK_BUCKET(e);
     for(s=base_table[e];s;s=s->next)
     {
       if(isproblem(s))
@@ -426,7 +394,6 @@ static void locate_problem(int (*isproblem)(const struct pike_string *))
 	DM(add_marks_to_memhdr(no,s));
       }
     }
-    UNLOCK_BUCKET(e);
   }
 
   DM(fprintf(stderr,"Plausible problem location(s):\n"));
@@ -471,7 +438,6 @@ static struct pike_string *internal_findstring(const char *s,
   unsigned int prefix_depth=0;
 
   size_t h;
-  LOCK_BUCKET(hval);
   h=HMODULO(hval);
   for(curr = base_table[h]; curr; curr = curr->next)
   {
@@ -494,7 +460,6 @@ static struct pike_string *internal_findstring(const char *s,
       /* *prev = curr->next; */
       /* curr->next = *base; */
       /* *base = curr; */
-      UNLOCK_BUCKET(hval);
       return curr;		/* pointer to string */
     }
     depth++;
@@ -517,7 +482,6 @@ static struct pike_string *internal_findstring(const char *s,
 #endif /* 0 */
     need_more_hash_prefix_depth = prefix_depth;
   }
-  UNLOCK_BUCKET(hval);
   return 0; /* not found */
 }
 
@@ -633,22 +597,6 @@ static void stralloc_rehash(void)
   old=htable_size;
   old_base=base_table;
 
-#ifdef PIKE_RUN_UNLOCKED
-  mt_lock(bucket_locks);
-  if(old != htable_size)
-  {
-    /* Someone got here before us */
-    mt_lock(bucket_locks);
-    return;
-  }
-
-  /* Now that we have bucket zero, the hash table
-   * cannot change, go ahead and lock ALL buckets.
-   * NOTE: bucket zero is already locked
-   */
-  for(h=1;h<BUCKET_LOCKS;h++) mt_lock(bucket_locks+h);
-#endif
-
   SET_HSIZE( ++hashprimes_entry );
 
   base_table=xcalloc(sizeof(struct pike_string *), htable_size);
@@ -660,10 +608,6 @@ static void stralloc_rehash(void)
 
   if(old_base)
     free(old_base);
-
-#ifdef PIKE_RUN_UNLOCKED
-  for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);
-#endif
 }
 
 /* Allocation of strings */
@@ -741,14 +685,12 @@ static void link_pike_string(struct pike_string *s, size_t hval)
     Pike_fatal ("Got undefined contents in pike string %p.\n", s);
 #endif
 
-  LOCK_BUCKET(hval);
   h=HMODULO(hval);
   s->next = base_table[h];
   base_table[h] = s;
   s->hval=hval;
   s->flags &= ~(STRING_NOT_HASHED|STRING_NOT_SHARED);
   num_strings++;
-  UNLOCK_BUCKET(hval);
 
   if(num_strings > htable_size) {
     stralloc_rehash();
@@ -784,25 +726,9 @@ static void link_pike_string(struct pike_string *s, size_t hval)
       need_new_hashkey_depth = 0;
     }
 
-#ifdef PIKE_RUN_UNLOCKED
-    mt_lock(bucket_locks);
-    if(need_more_hash_prefix_depth <= 4)
-    {
-      /* Someone got here before us */
-      mt_lock(bucket_locks);
-      return;
-    }
-    for(h=1;h<BUCKET_LOCKS;h++) mt_lock(bucket_locks+h);
-#endif
-
-    if (need_more_hash_prefix_depth > 4) 
-    {
+    if (need_more_hash_prefix_depth > 4)
       hash_prefix_len=hash_prefix_len*2;
-#if 0
-      fprintf(stderr, "Doubling hash_prefix_len to %d and rehashing\n",
-	      hash_prefix_len);
-#endif /* 0 */
-    }
+
     /* NOTE: No need to update to the correct values, since that will
      *       be done on demand.
      */
@@ -825,9 +751,6 @@ static void link_pike_string(struct pike_string *s, size_t hval)
 	base_table[h2]=tmp2;
       }
     }
-#ifdef PIKE_RUN_UNLOCKED
-    for(h=0;h<BUCKET_LOCKS;h++) mt_unlock(bucket_locks + h);
-#endif
   }
 }
 
@@ -1136,7 +1059,6 @@ PMOD_EXPORT struct pike_string *debug_make_shared_string2(const p_wchar2 *str)
 static void unlink_pike_string(struct pike_string *s)
 {
   size_t h;
-  LOCK_BUCKET(s->hval);
   h= HMODULO(s->hval);
   propagate_shared_string(s,h);
 #ifdef PIKE_DEBUG
@@ -1149,7 +1071,6 @@ static void unlink_pike_string(struct pike_string *s)
   s->next=(struct pike_string *)(ptrdiff_t)-1;
 #endif
   num_strings--;
-  UNLOCK_BUCKET(s->hval);
   s->flags |= STRING_NOT_SHARED;
 }
 
@@ -1228,7 +1149,6 @@ struct pike_string *add_string_status(int verbose)
     struct pike_string *p;
     for(e=0;e<htable_size;e++)
     {
-      LOCK_BUCKET(e);
       for(p=base_table[e];p;p=p->next)
       {
 	int is_short = (p->len <= SHORT_STRING_THRESHOLD);
@@ -1245,7 +1165,6 @@ struct pike_string *add_string_status(int verbose)
 	alloced_bytes[key] +=
 	  p->refs*DO_ALIGN((p->len+3) << p->size_shift,sizeof(void *));
       }
-      UNLOCK_BUCKET(e);
     }
     string_builder_sprintf(&s,
 			   "\nShared string hash table:\n"
@@ -1387,7 +1306,6 @@ PMOD_EXPORT void verify_shared_strings_tables(void)
   for(e=0;e<htable_size;e++)
   {
     h=0;
-    LOCK_BUCKET(e);
     for(s=base_table[e];s;s=s->next)
     {
       num++;
@@ -1433,7 +1351,6 @@ PMOD_EXPORT void verify_shared_strings_tables(void)
 	h=0;
       }
     }
-    UNLOCK_BUCKET(e);
   }
   if(num != num_strings)
     Pike_fatal("Num strings is wrong %d!=%d\n",num,num_strings);
@@ -1446,16 +1363,13 @@ int safe_debug_findstring(struct pike_string *foo)
   for(e=0;e<htable_size;e++)
   {
     struct pike_string *p;
-    LOCK_BUCKET(e);
     for(p=base_table[e];p;p=p->next)
     {
       if(p==foo)
       {
-	UNLOCK_BUCKET(e);
 	return 1;
       }
     }
-    UNLOCK_BUCKET(e);
   }
   return 0;
 }
@@ -1476,7 +1390,6 @@ struct pike_string *debug_findstring(const struct pike_string *foo)
 	    (long)foo->len,
 	    foo->str);
 
-    LOCK_BUCKET(foo->hval);
     fprintf(stderr,"------ %p %ld\n",
 	    base_table[HMODULO(foo->hval)],
 	    foo->hval);
@@ -1488,11 +1401,9 @@ struct pike_string *debug_findstring(const struct pike_string *foo)
 	fprintf(stderr,"%p->",tmp2);
     }
     fprintf(stderr,"0\n");
-    UNLOCK_BUCKET(foo->hval);
 
     for(e=0;e<htable_size;e++)
     {
-      LOCK_BUCKET(e);
       for(tmp2=base_table[e];tmp2;tmp2=tmp2->next)
       {
 	if(tmp2 == tmp)
@@ -1500,7 +1411,6 @@ struct pike_string *debug_findstring(const struct pike_string *foo)
 		  (long)e,
 		  (long)HMODULO(foo->hval));
       }
-      UNLOCK_BUCKET(e);
     }
   }
 #endif /* 0 */
@@ -1551,14 +1461,12 @@ void dump_stralloc_strings(void)
   struct pike_string *p;
   for(e=0;e<htable_size;e++)
   {
-    LOCK_BUCKET(e);
     for(p=base_table[e];p;p=p->next) {
       debug_dump_pike_string(p, 70);
 #ifdef DEBUG_MALLOC
       debug_malloc_dump_references (p, 2, 1, 0);
 #endif
     }
-    UNLOCK_BUCKET(e);
   }
 }
 
@@ -2261,13 +2169,6 @@ void init_shared_string_table(void)
   SET_HSIZE(hashprimes_entry);
   base_table=xcalloc(sizeof(struct pike_string *), htable_size);
 
-#ifdef PIKE_RUN_UNLOCKED
-  {
-    int h;
-    bucket_locks=xalloc(sizeof(PIKE_MUTEX_T)*BUCKET_LOCKS);
-    for(h=0;h<BUCKET_LOCKS;h++) mt_init(bucket_locks + h);
-  }
-#endif
   empty_pike_string = make_shared_string("");
   empty_pike_string->flags |= STRING_CONTENT_CHECKED | STRING_IS_LOWERCASE | STRING_IS_UPPERCASE;
   empty_pike_string->min = empty_pike_string->max = 0;
@@ -2314,18 +2215,12 @@ void cleanup_shared_string_table(void)
 
   for(e=0;e<htable_size;e++)
   {
-    LOCK_BUCKET(e);
     for(s=base_table[e];s;s=next)
     {
       next=s->next;
-#ifdef REALLY_FREE
-      free_unlinked_pike_string(s);
-#else
       s->next=0;
-#endif
     }
     base_table[e]=0;
-    UNLOCK_BUCKET(e);
   }
   free(base_table);
   base_table=0;
@@ -2362,13 +2257,11 @@ void count_memory_in_strings(size_t *num, size_t *size)
   for(e=0;e<htable_size;e++)
   {
     struct pike_string *p;
-    LOCK_BUCKET(e);
     for(p=base_table[e];p;p=p->next)
     {
       num_++;
       size_ += memory_in_string (p);
     }
-    UNLOCK_BUCKET(e);
   }
 #ifdef PIKE_DEBUG
   if(num_strings != num_)
@@ -2427,10 +2320,8 @@ struct pike_string *next_pike_string (struct pike_string *s)
     size_t h = s->hval;
     do {
       h++;
-      LOCK_BUCKET(h);
       h = HMODULO(h);
       next = base_table[h];
-      UNLOCK_BUCKET(h);
     } while (!next);
   }
   return next;
@@ -3785,10 +3676,6 @@ PMOD_EXPORT double STRTOD_PCHARP(PCHARP nptr, PCHARP *endptr)
 
  underflow:
   /* Return an underflow error.  */
-#if 0
-  if (endptr != NULL)
-    *endptr = nptr;
-#endif
   errno = ERANGE;
   return 0.0;
   
diff --git a/src/svalue.h b/src/svalue.h
index 6a183a4c31..ba129c341b 100644
--- a/src/svalue.h
+++ b/src/svalue.h
@@ -417,29 +417,8 @@ do{ \
 }while(0)
 
 
-#ifdef PIKE_RUN_UNLOCKED
-#define add_ref(X) pike_atomic_inc32(&(X)->refs)
-#define sub_ref(X) pike_atomic_dec_and_test32(&(X)->refs)
-
-#if 0
-#define IF_LOCAL_MUTEX(X) X
-#define USE_LOCAL_MUTEX
-#define pike_lock_data(X) mt_lock(&(X)->mutex)
-#define pike_unlock_data(X) mt_unlock(&(X)->mutex)
-#else
-#define IF_LOCAL_MUTEX(X)
-#define pike_lock_data(X) pike_lockmem((X))
-#define pike_unlock_data(X) pike_unlockmem((X))
-#endif
-
-#else
-#define IF_LOCAL_MUTEX(X)
-#define add_ref(X) (void)((X)->refs++)
+#define add_ref(X) ((void)((X)->refs++))
 #define sub_ref(X) (--(X)->refs > 0)
-#define pike_lock_data(X) (void)(X)
-#define pike_unlock_data(X) (void)(X)
-#endif
-
 
 #ifdef PIKE_DEBUG
 PMOD_EXPORT extern void describe(void *); /* defined in gc.c */
@@ -508,15 +487,8 @@ if(REFCOUNTED_TYPE(T) && (S)->refs && (S)->refs[0] <= 0) {\
 #ifdef DEBUG_MALLOC
 static INLINE struct svalue *dmalloc_check_svalue(struct svalue *s, char *l)
 {
-#if 0
-  /* What's this supposed to accomplish? Dmalloc tracks memory blocks,
-   * not single svalues that point to them. /mast */
-  debug_malloc_update_location(s,l);
-#endif
-#if 1
   if(s && REFCOUNTED_TYPE(TYPEOF(*s)))
     debug_malloc_update_location(s->u.refs,l);
-#endif
   return s;
 }
 
@@ -528,32 +500,20 @@ static INLINE struct svalue *dmalloc_check_svalues(struct svalue *s, size_t num,
 
 static INLINE union anything *dmalloc_check_union(union anything *u,int type, char * l)
 {
-#if 0
-  debug_malloc_update_location(u,l);
-#endif
-#if 1
   if(u && REFCOUNTED_TYPE(type))
     debug_malloc_update_location(u->refs,l);
-#endif
   return u;
 }
 
 #undef add_ref
-#undef sub_ref
-
-#ifdef PIKE_RUN_UNLOCKED
-#define add_ref(X) pike_atomic_inc32((INT32 *)debug_malloc_update_location( &((X)->refs), DMALLOC_NAMED_LOCATION(" add_ref")))
-#define sub_ref(X) pike_atomic_dec_and_test32((INT32 *)debug_malloc_update_location( &((X)->refs), DMALLOC_NAMED_LOCATION(" sub_ref")))
-#else
 #define add_ref(X) (((INT32 *)debug_malloc_update_location( &((X)->refs), DMALLOC_NAMED_LOCATION(" add_ref")))[0]++)
+#undef sub_ref
 #define sub_ref(X) (--((INT32 *)debug_malloc_update_location( &((X)->refs), DMALLOC_NAMED_LOCATION(" sub_ref")))[0] > 0)
-#endif
 
 #else  /* !DEBUG_MALLOC */
 #define dmalloc_check_svalue(S,L) (S)
 #define dmalloc_check_svalues(S,L,N) (S)
 #define dmalloc_check_union(U,T,L) (U)
-
 #endif	/* !DEBUG_MALLOC */
 
 /* To be used for type checking in macros. */
@@ -620,30 +580,18 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
     );									\
   } while (0)
 
-/* This define
- * should check that the svalue address (X) is on the local stack,
- * the processor stack or in a locked memory object
- *
- * Or, it could just try to make sure it's not in an unlocked memory
- * object...
- */
-#define assert_svalue_locked(X)
-
-
-#define swap_svalues_unlocked(X,Y)  do {		\
+#define swap_svalues(X,Y)  do {		\
   struct svalue *_a=(X);				\
   struct svalue *_b=(Y);				\
   struct svalue _tmp;					\
-  assert_svalue_locked(_a); assert_svalue_locked(_b);	\
   dmalloc_touch_svalue(_a);				\
   dmalloc_touch_svalue(_b);				\
   _tmp=*_a; *_a=*_b; *_b=_tmp;				\
 }while(0)
 
 /* Handles PIKE_T_FREE. */
-#define free_svalue_unlocked(X) do {				\
+#define free_svalue(X) do {				\
   struct svalue *_s=(X);					\
-  assert_svalue_locked(_s);					\
   DO_IF_DEBUG (							\
     if (TYPEOF(*_s) != PIKE_T_FREE) {				\
       check_svalue_type(_s);					\
@@ -664,10 +612,9 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
   }								\
 }while(0)
 
-#define free_short_svalue_unlocked(X,T) do {				\
+#define free_short_svalue(X,T) do {				\
   union anything *_s=(X); TYPE_T _t=(T);				\
   check_type(_t); check_refs2(_s,_t);					\
-  assert_svalue_locked(_s);						\
   if(REFCOUNTED_TYPE(_t) && _s->refs) {					\
     DO_IF_DEBUG (							\
       DO_IF_PIKE_CLEANUP (						\
@@ -680,7 +627,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
 }while(0)
 
 /* Handles PIKE_T_FREE. */
-#define add_ref_svalue_unlocked(X) do {				\
+#define add_ref_svalue(X) do {				\
   struct svalue *_tmp=(X);					\
   DO_IF_DEBUG (							\
     if (TYPEOF(*_tmp) != PIKE_T_FREE) {				\
@@ -692,7 +639,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
 }while(0)
 
 /* Handles PIKE_T_FREE. */
-#define assign_svalue_no_free_unlocked(X,Y) do {	\
+#define assign_svalue_no_free(X,Y) do {	\
   struct svalue *_to=(X);				\
   const struct svalue *_from=(Y);			\
   DO_IF_DEBUG (						\
@@ -708,7 +655,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
 }while(0)
 
 /* Handles PIKE_T_FREE. */
-#define assign_svalue_unlocked(X,Y) do {	\
+#define assign_svalue(X,Y) do {	\
   struct svalue *_to2=(X);			\
   const struct svalue *_from2=(Y);		\
   if (_to2 != _from2) {				\
@@ -908,124 +855,6 @@ static INLINE TYPE_FIELD dmalloc_gc_cycle_check_svalues (struct svalue *s, size_
 
 #endif /* !NO_PIKE_SHORTHAND */
 
-#if 0 /* PIKE_RUN_UNLOCKED */
-
-#include "pike_error.h"
-
-/*#define swap_svalues swap_svalues*/
-/*#define free_svalue free_svalue_unlocked*/
-/*#define free_short_svalue free_short_svalue_unlocked */
-/*#define add_ref_svalue add_ref_svalue_unlocked*/
-
-/*
- * These don't work right now - Hubbe
- */
-#define assign_svalue_no_free assign_svalue_no_free_unlocked
-#define assign_svalue assign_svalue_unlocked
-
-/* FIXME:
- * These routines assumes that pointers are 32 bit
- * and svalues 64 bit!!!!! - Hubbe
- */
-
-#ifndef swap_svalues 
-#define swap_svalues swap_svalues_unlocked
-#endif
-
-#ifndef free_svalue
-static INLINE void free_svalue(struct svalue *s)
-{
-  INT64 tmp;
-  struct svalue zero;
-  SET_SVAL(zero, PIKE_T_INT, NUMBER_NUMBER, integer, 0);
-  tmp=pike_atomic_swap64((INT64 *)s, *(INT64 *)&zero);
-  free_svalue_unlocked((struct svalue *)&tmp);
-}
-#endif
-
-#ifndef free_short_svalue
-static INLINE void free_short_svalue(union anything *s, int t)
-{
-  if(REFCOUNTED_TYPE(t))
-  {
-    INT32 tmp;
-    tmp=pike_atomic_swap32((INT32 *)s, 0);
-    free_short_svalue_unlocked((union anything *)&tmp, t);
-  }
-}
-#endif
-
-#ifndef add_ref_svalue
-static INLINE void add_ref_svalue(struct svalue *s)
-{
-  INT64 sv;
-  sv=pike_atomic_get64((INT64 *)s);
-  add_ref_svalue_unlocked((struct svalue *)&sv);
-}
-#endif
-
-#ifndef assign_svalue_no_free
-void assign_svalue_no_free(struct svalue *to, const struct svalue *from)
-{
-  INT64 tmp, sv;
-  sv=pike_atomic_get64((INT64 *)from);
-#ifdef PIKE_DEBUG
-  if(sv != *(INT64*)from)
-  {
-    fprintf(stderr,"pike_atomic_get64() is broken %llx != %llx (%08x%08x)!\n",
-	    sv,
-	    *(INT64*)from,
-	    ((INT32*)from)[1], ((INT32*)from)[0]);
-    abort();
-  }
-#endif
-  add_ref_svalue_unlocked((struct svalue *)&sv);
-  pike_atomic_set64((INT64 *)to, sv);
-#ifdef PIKE_DEBUG
-  if(*(INT64*)to != *(INT64*)from)
-  {
-    fprintf(stderr,"pike_atomic_set64() is broken!\n");
-    abort();
-  }
-#endif
-}
-#endif
-
-#ifndef assign_svalue
-static INLINE void assign_svalue(struct svalue *to, const struct svalue *from)
-{
-  INT64 tmp, sv;
-  if(to != from)
-  {
-    sv=pike_atomic_get64((INT64 *)from);
-    add_ref_svalue_unlocked((struct svalue *)&sv);
-    tmp=pike_atomic_swap64((INT64 *)to, sv);
-    free_svalue_unlocked((struct svalue *)&tmp);
-  }
-}
-#endif
-
-#else /* FOO_PIKE_RUN_UNLOCKED */
-#define swap_svalues swap_svalues_unlocked
-#define free_svalue free_svalue_unlocked
-#define free_short_svalue free_short_svalue_unlocked 
-#define add_ref_svalue add_ref_svalue_unlocked
-#define assign_svalue_no_free assign_svalue_no_free_unlocked
-#define assign_svalue assign_svalue_unlocked
-#endif /* FOO_PIKE_RUN_UNLOCKED */
-
-#ifdef PIKE_RUN_UNLOCKED
-#include "pike_threadlib.h"
-#endif
-
-/* 
- * Note to self:
- * It might be better to use a static array of mutexes instead
- * and just lock mutex ptr % array_size instead.
- * That way I wouldn't need a mutex in each memory object,
- * but it would cost a couple of cycles in every lock/unlock
- * operation instead.
- */
 #ifdef ATOMIC_SVALUE
 /* Atomic svalues: Store the type in the reference types,
  * instead of on the stack. This allows for changing an
@@ -1035,7 +864,6 @@ static INLINE void assign_svalue(struct svalue *to, const struct svalue *from)
   INT32 refs;				\
   INT32 ref_type			\
   DO_IF_SECURITY(; struct object *prot) \
-  IF_LOCAL_MUTEX(; PIKE_MUTEX_T mutex)
 
 #ifdef PIKE_SECURITY
 #ifdef USE_LOCAL_MUTEX
@@ -1057,13 +885,11 @@ static INLINE void assign_svalue(struct svalue *to, const struct svalue *from)
   v_->refs=0;						\
   add_ref(v_); /* For DMALLOC... */			\
   DO_IF_SECURITY( INITIALIZE_PROT(v_) );		\
-  IF_LOCAL_MUTEX(mt_init_recursive(&(v_->mutex)));	\
 }while(0)
 #else /* !ATOMIC_SVALUE */
 #define PIKE_MEMORY_OBJECT_MEMBERS	\
   INT32 refs				\
   DO_IF_SECURITY(; struct object *prot) \
-  IF_LOCAL_MUTEX(; PIKE_MUTEX_T mutex)
 
 #ifdef PIKE_SECURITY
 #ifdef USE_LOCAL_MUTEX
@@ -1084,14 +910,12 @@ static INLINE void assign_svalue(struct svalue *to, const struct svalue *from)
   v_->refs=0;						\
   add_ref(v_); /* For DMALLOC... */			\
   DO_IF_SECURITY( INITIALIZE_PROT(v_) );		\
-  IF_LOCAL_MUTEX(mt_init_recursive(&(v_->mutex)));	\
 }while(0)
 #endif /* ATOMIC_SVALUE */
 
 #define EXIT_PIKE_MEMOBJ(X) do {		\
   struct ref_dummy *v_=(struct ref_dummy *)(X);		\
   DO_IF_SECURITY( FREE_PROT(v_) );		\
-  IF_LOCAL_MUTEX(mt_destroy(&(v_->mutex)));	\
 }while(0)
 
 
-- 
GitLab