a _setjmp/_longjmp lightweighted version for mac 64bit.
authorGengbin Zheng <gzheng@illinois.edu>
Thu, 5 Jan 2006 05:35:59 +0000 (05:35 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Thu, 5 Jan 2006 05:35:59 +0000 (05:35 +0000)
src/QuickThreads/md/setjmp64_.c [new file with mode: 0644]
src/QuickThreads/mkfiles/generic64-light [new file with mode: 0644]

diff --git a/src/QuickThreads/md/setjmp64_.c b/src/QuickThreads/md/setjmp64_.c
new file mode 100644 (file)
index 0000000..f1dc3f2
--- /dev/null
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * $Source$
+ * $Author$
+ * $Date$
+ * $Revision$
+ *****************************************************************************/
+
+/*
+_setjmp/_longjmp is much light weighted than setjmp/longjmp
+because it does not store signal mask, which is not a problem for netpoll
+versions of charm.
+*/
+
+
+#include "qt.h"
+#include <setjmp.h>
+
+#ifdef ALLOCA_H
+#include <alloca.h>
+#endif
+
+struct helpdesc { qt_helper_t *hfn; qt_t *jb; void *old; void *new; };
+
+#ifdef __CYGWIN__
+# ifdef QT_GROW_DOWN
+#define SHIFTSP(pos) asm ( "mov %0, %%esp\n"::"m"((char*)pos-256));
+# else
+#define SHIFTSP(pos) asm ( "mov %0, %%esp\n"::"m"((char*)pos+256));
+# endif
+#else
+# ifdef QT_GROW_DOWN
+#define SHIFTSP(pos) {char *osp=alloca(0); alloca((osp-((char*)pos))+256); }
+# else
+#define SHIFTSP(pos) {char *osp=alloca(0); alloca((((char*)pos)-osp)+256); }
+# endif
+#endif
+
+#define MAXTABLE 1000
+static void * pbuf[MAXTABLE] = {0};
+static int    pcounter = 1;
+
+static int push_buf(void *ptr)
+{
+  int cur = pcounter;
+  pbuf[pcounter] = ptr;
+  pcounter++;
+  if (pcounter >= MAXTABLE) pcounter = 1;   /* reuse the table */
+  return cur;
+}
+
+static void qt_args_1(qt_t *rjb, void *u, void *t,
+                     qt_userf_t *userf, qt_only_t *only)
+{
+  jmp_buf jb; struct helpdesc *rhelp;
+  int index;
+  index = _setjmp(jb);
+  rhelp = (struct helpdesc *)pbuf[index];
+  if (rhelp == 0) {
+    SHIFTSP(rjb);
+    _longjmp((unsigned long*)rjb, push_buf((void *)jb));
+  }
+  rhelp->hfn(rhelp->jb, rhelp->old, rhelp->new);
+  only(u, t, userf);
+  write(2,"Never get here 2.\n",18);
+}
+
+qt_t *qt_args(qt_t *sp, void *u, void *t,
+             qt_userf_t *userf, qt_only_t *only)
+{
+  jmp_buf jb; qt_t *result;
+  int index;
+  index = _setjmp(jb);
+  result = (qt_t*)pbuf[index];
+  if (result==0) {
+    SHIFTSP(sp);
+    qt_args_1((qt_t*)jb,u,t,userf,only);
+    write(2,"Never get here 1.\n",18);
+  }
+  return result;
+}
+
+void *qt_block(qt_helper_t *hfn, void *old, void *new, qt_t *sp)
+{
+  struct helpdesc help, *rhelp; char *oldsp; int offs;
+  jmp_buf jb;
+  int index;
+  help.hfn = hfn;
+  help.jb  = (qt_t*)&jb;
+  help.old = old;
+  help.new = new;
+  index = _setjmp(jb);
+  rhelp = (struct helpdesc *)pbuf[index];
+  if (rhelp==0) {
+    SHIFTSP(sp);
+    _longjmp((unsigned long*)sp, push_buf((void *)&help));
+  }
+  rhelp->hfn(rhelp->jb, rhelp->old, rhelp->new);
+}
+
+void *qt_abort(qt_helper_t *hfn, void *old, void *new, qt_t *sp)
+{
+  struct helpdesc help, *rhelp;
+  help.hfn = hfn;
+  help.jb  = (qt_t*)&help;
+  help.old = old;
+  help.new = new;
+  SHIFTSP(sp);
+  _longjmp((unsigned long*)sp, push_buf((void *)&help));
+}
diff --git a/src/QuickThreads/mkfiles/generic64-light b/src/QuickThreads/mkfiles/generic64-light
new file mode 100644 (file)
index 0000000..8b1def0
--- /dev/null
@@ -0,0 +1,23 @@
+
+CHARMC = ../../bin/charmc -seq -I. $(OPTS)
+CHARMC_SHARED = ../../bin/charmc -seq -I. -shared $(OPTS)
+
+all: qt stp testpgm
+
+qt: md/setjmp_d.h qt.c md/setjmp64_.c
+       rm -f qtmd.h
+       ../system_ln  md/setjmp_d.h qtmd.h
+       $(CHARMC) -c -o qt.o qt.c
+       $(CHARMC) -c -o qtmds.o md/setjmp64_.c
+       CHARMINC=..; . ../conv-config.sh;       \
+       $(CHARMC_SHARED) -o libqt.$$CMK_SHARED_SUF qt.o qtmds.o
+       $(CHARMC) -o libqt.a qt.o qtmds.o 
+
+stp:
+       $(CC) -c stp.c
+       ar q libstp.a stp.o
+
+testpgm:
+       $(CC) -c meas.c
+       $(CC) -c -o qtmdb.o md/setjmp_b.c
+       $(CC) -o run meas.o qtmdb.o libstp.a libqt.a