From e319b2fbf90010a70157fa75afdb34b4d9a9917c Mon Sep 17 00:00:00 2001
From: Joao <joao@leap-jsantos.(none)>
Date: Fri, 27 May 2011 17:21:03 +0100
Subject: [PATCH] fix YAPOR THREADS. fix threads + tabling.

---
 C/stdpreds.c        | 2 +-
 OPTYap/opt.init.c   | 3 ++-
 OPTYap/opt.proto.h  | 4 ++--
 OPTYap/tab.macros.h | 8 ++++----
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/C/stdpreds.c b/C/stdpreds.c
index cfccdd836..9937d4f9b 100755
--- a/C/stdpreds.c
+++ b/C/stdpreds.c
@@ -4110,7 +4110,7 @@ Proc E_Modules[]= {/* init_fc,*/ (Proc) 0 };
 
 #ifndef YAPOR
 static
-Int p_yapor_threads(void) {
+Int p_yapor_threads( USES_REGS1 ) {
   return FALSE;
 }
 #endif
diff --git a/OPTYap/opt.init.c b/OPTYap/opt.init.c
index 8654ca50b..e6a3dceab 100644
--- a/OPTYap/opt.init.c
+++ b/OPTYap/opt.init.c
@@ -173,8 +173,9 @@ void Yap_init_local_optyap_data(int wid) {
   INIT_LOCK(REMOTE_lock_signals(wid));
 #endif /* YAPOR_COPY */
   Set_REMOTE_prune_request(wid, NULL);
-#endif /* YAPOR */
   INIT_LOCK(REMOTE_lock(wid));
+#endif /* YAPOR */
+
 #ifdef TABLING
   /* local data related to tabling */
   REMOTE_next_free_ans_node(wid) = NULL;
diff --git a/OPTYap/opt.proto.h b/OPTYap/opt.proto.h
index 2e6cd10ef..2b496cd3f 100644
--- a/OPTYap/opt.proto.h
+++ b/OPTYap/opt.proto.h
@@ -11,9 +11,9 @@
 **                                                                     **
 ************************************************************************/
 
-#ifdef TABLING
+#if defined(TABLING) || defined(YAPOR) 
 #include "SWI-Stream.h"
-#endif /* TABLING */
+#endif /* TABLING || YAPOR */
 
 
 
diff --git a/OPTYap/tab.macros.h b/OPTYap/tab.macros.h
index 0da74cb72..b9899a4b2 100644
--- a/OPTYap/tab.macros.h
+++ b/OPTYap/tab.macros.h
@@ -523,7 +523,7 @@ static inline void rebind_variables(tr_fr_ptr rebind_tr, tr_fr_ptr end_tr) {
   CACHE_REGS
   TABLING_ERROR_CHECKING(rebind_variables, rebind_tr < end_tr);
   /* rebind loop */
-  Yap_NEW_MAHASH((ma_h_inner_struct *)H);
+  Yap_NEW_MAHASH((ma_h_inner_struct *)H PASS_REGS);
   while (rebind_tr != end_tr) {
     CELL ref = (CELL) TrailTerm(--rebind_tr);
     /* check for global or local variables */
@@ -541,7 +541,7 @@ static inline void rebind_variables(tr_fr_ptr rebind_tr, tr_fr_ptr end_tr) {
 #ifdef MULTI_ASSIGNMENT_VARIABLES
     } else {
       CELL *cell_ptr = RepAppl(ref);
-      if (!Yap_lookup_ma_var(cell_ptr)) {
+      if (!Yap_lookup_ma_var(cell_ptr PASS_REGS)) {
 	/* first time we found the variable, let's put the new value */
 	*cell_ptr = TrailVal(rebind_tr);
       }
@@ -560,7 +560,7 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
 
   TABLING_ERROR_CHECKING(restore_variables, unbind_tr < rebind_tr);
   end_tr = rebind_tr;
-  Yap_NEW_MAHASH((ma_h_inner_struct *)H);
+  Yap_NEW_MAHASH((ma_h_inner_struct *)H PASS_REGS);
   while (unbind_tr != end_tr) {
     /* unbind loop */
     while (unbind_tr > end_tr) {
@@ -582,7 +582,7 @@ static inline void restore_bindings(tr_fr_ptr unbind_tr, tr_fr_ptr rebind_tr) {
 	/* multi-assignment variable */
 	/* so that the upper cell is the old value */ 
 	--unbind_tr;
-	if (!Yap_lookup_ma_var(pt)) {
+	if (!Yap_lookup_ma_var(pt PASS_REGS)) {
 	  pt[0] = TrailVal(unbind_tr);
 	}
 #endif /* MULTI_ASSIGNMENT_VARIABLES */