Added Josh's stack-copying threads code to threads.c. Currently it is
authorMilind Bhandarkar <milind@cs.uiuc.edu>
Mon, 3 May 1999 09:33:12 +0000 (09:33 +0000)
committerMilind Bhandarkar <milind@cs.uiuc.edu>
Mon, 3 May 1999 09:33:12 +0000 (09:33 +0000)
turned off on every machine.

41 files changed:
src/arch/exemplar-mpi/conv-mach.h
src/arch/exemplar/conv-mach.h
src/arch/ncube2/conv-mach.h
src/arch/net-aix-ppc/conv-mach.h
src/arch/net-hp-acc/conv-mach.h
src/arch/net-hp-cc/conv-mach.h
src/arch/net-hp/conv-mach.h
src/arch/net-irix-64/conv-mach.h
src/arch/net-irix/conv-mach.h
src/arch/net-linux-kcc/conv-mach.h
src/arch/net-linux-smp/conv-mach.h
src/arch/net-linux/conv-mach.h
src/arch/net-sol-cc/conv-mach.csh
src/arch/net-sol-cc/conv-mach.h
src/arch/net-sol-smp/conv-mach.h
src/arch/net-sol/conv-mach.h
src/arch/net-sun/conv-mach.h
src/arch/origin-mpi/conv-mach.h
src/arch/origin-pthreads/conv-mach.h
src/arch/origin2000/conv-mach.h
src/arch/paragon-red/conv-mach.h
src/arch/sim-hp/conv-mach.h
src/arch/sim-irix-64/conv-mach.h
src/arch/sim-irix/conv-mach.h
src/arch/sim-linux/conv-mach.h
src/arch/sim-rs6k/conv-mach.h
src/arch/sim-sol/conv-mach.h
src/arch/sim-sun/conv-mach.h
src/arch/sp3/conv-mach.h
src/arch/t3e/conv-mach.h
src/arch/uth-hp-cc/conv-mach.h
src/arch/uth-hp/conv-mach.h
src/arch/uth-irix-64/conv-mach.h
src/arch/uth-irix/conv-mach.h
src/arch/uth-linux/conv-mach.h
src/arch/uth-rs6k/conv-mach.h
src/arch/uth-sol-cc/conv-mach.h
src/arch/uth-sol/conv-mach.h
src/conv-core/converse.h
src/conv-core/memory.c
src/conv-core/threads.c

index d76d6e0278862e059c3fbf830fe7d81d6887e628..abe1b36bead70989c418377230e5180680df81b9 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              1
index 302f573893f9e62dfdaebb2b66b853198d3ad871..6c152f2f478b50e3434ed6f574eb7754e366ac71 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 3cd108345cf1a566a03f445a8d84aefbedab9841..524319bb92ba18d72e127b810922b4cd10e28ac0 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              1
index 6cfc97d5a7ad515641666cc79ae18fa6745e50cc..fe630e13bae08ccf5f395bd001c9f439369a69fc 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 604571088eaafea10f5a133f5c69d3681aee64d7..eb462d08c64483c11390fc85f4365b115ff7fd17 100644 (file)
@@ -83,6 +83,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index f081c2206ce265c6a7f1c9cf6e6df75a2757da12..b9360ccf86922d45ca97d40bcb37269470e04938 100644 (file)
@@ -83,6 +83,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 5d3b85cf46e13cfbd4d5e5c7773d549bc4dbf521..c12ddaaa7865289db9015dbcb26e97563f26c78a 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index eda20778897cbc511d8cdfde87f3f734a034d805..1cf1e8119c978b5c3ee0368f6e0ea754faf98ef9 100644 (file)
@@ -84,6 +84,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            0
 #define CMK_THREADS_USE_ALLOCA                             0
index 7af52c2163b9d28b188912671cbbae5ab54ce232..247dac6cf0fc2d8df6c60f337813ca7876446ba4 100644 (file)
@@ -84,6 +84,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 41e58d71089757f71f8fb2516bf3eb8c9af7f6e8..7794d4ecb105194903fc5b8ed5929f579bada0bf 100644 (file)
@@ -77,6 +77,7 @@
 #define CMK_STRINGS_USE_STRING_H                           1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            1
 #define CMK_TIMER_USE_SPECIAL                              0
index 1614df5009e8a1932f88d287fa380acac090b51f..a156629d155df7b5a0ffc09398e1a612eb1536ca 100644 (file)
@@ -78,6 +78,7 @@
 #define CMK_STRINGS_USE_STRING_H                           1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            1
 #define CMK_TIMER_USE_SPECIAL                              0
index 8572dc1ff880d5a10f4a33e34eeea2a2ee1d3a4c..647cb5c6145fcbcce1203c75bdedf45cb5705cab 100644 (file)
@@ -77,6 +77,7 @@
 #define CMK_STRINGS_USE_STRING_H                           1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            1
 #define CMK_TIMER_USE_SPECIAL                              0
index d31d09cd3799dab34eddcdcd5863195e89e857b9..eee3c9153f0ec68161120aa42cc72098036b407f 100755 (executable)
@@ -1,9 +1,9 @@
 set CMK_CPP_CHARM='/usr/ccs/lib/cpp '
 set CMK_CPP_C='cc -E '
-set CMK_CC='cc '
+set CMK_CC='cc -Kpic '
 set CMK_CC_RELIABLE='cc '
 set CMK_CC_FASTEST='cc '
-set CMK_CXX='CC '
+set CMK_CXX='CC -Kpic '
 set CMK_CXXPP='CC -E '
 set CMK_CF77=''
 set CMK_C_DEBUG='-g'
index 6a91302d2c9782931891e1ba81c5eff8b06eee12..b4d9e1ddd5863a83854fcc7ecbf7b9af6c8f7566 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 571f7e10075e37ac39c815fbd193828dfad1c73e..0a0e8f3b469352fd1bf57aeb5b7f2c3bf87d9c43 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 6b2c1925efd2295b13642d3810deadf5791d950e..b7b4984c42b1527053ff63a7e2837ba02344384d 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 07311f48893c6fc0c259c32c57800d405905eeb6..263c784af535b295a174f7e3166367cd560045ae 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            1
 #define CMK_TIMER_USE_SPECIAL                              0
index d67484af7bf8aac7c9aa6033ce5a904506db5172..aae7b31dd28ce426219637cccce67253538a8153 100644 (file)
@@ -83,6 +83,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            0
 #define CMK_THREADS_USE_ALLOCA                             0
index 28d4f7a5c8fda632562728bdb3f13944a07681ff..d8d07ac5256b5c26b809af63047bf3af6bc369c4 100644 (file)
@@ -84,6 +84,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            0
 #define CMK_THREADS_USE_ALLOCA                             0
index 6db97e2028489ce103d14b478f910ad72baa55d1..29b4c1fe981f8c442f86edeb6bce9a4b0e46acb9 100644 (file)
@@ -83,6 +83,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            0
 #define CMK_THREADS_USE_ALLOCA                             0
index 52679477fbdc04de6e4d87c3cbdfe0105c4c1aac..49e35433b3f8ad21a2c2c01be06b9d6be02973c7 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              1
index 2104f2187acda812842c576a8d4b8dbc4529ac81..d2fe84371d97b7e9eea6af8841f41f04f175a283 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index c2ca08c6d2b25bb09254d27b5a249c7ee35b0887..2e7210a0767dde7e15eee22bb14aa3a5114364cc 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            1
 #define CMK_THREADS_USE_ALLOCA                             0
index ed95e6827a02a27aafcba66cfcd693628704b9e6..3097a0e6f9a5f328178d8438effb730cc4e3405c 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            1
 #define CMK_THREADS_USE_ALLOCA                             0
index 40cdcc9506700cb328a735db6865c09111437448..2f13d97f09b89f6175abfc85df3329aa65216eab 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_STRINGS_USE_STRING_H                           0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index a14b907bf456673d5521fca5b5e76881333c7f52..9f15230a533b10a60b2061c0f0ef923924bb16cc 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 93516e464872663187cf3b6cbd7cbabceb6f8895..e9a751bd180278ac64a04c74ed14a6c9f2bee87b 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index fc8143e921f1aa0244baaa785a4e6aa45fbea103..6a9dd1712c571f538eb7f32d48a9b334477fa6f6 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       1
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 6db155c7e21341fb43f0382b7696e1096295e60b..cb295990980bd6f4d6236423228d59ae44da42a6 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              1
index 1ad3cf9a796368d3cb181f3cf409c504711f91cd..4d371cfe95972f6cc501d460a20a5e0ec4db1abc 100644 (file)
@@ -83,6 +83,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         0
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              1
index 416a62bbfb26a8f82da54af059f14396fd031e64..b457c53bf88db1e2453c4d69de39c62e0ba3bd01 100644 (file)
@@ -79,6 +79,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index d8ac80a12100ca86750a4c101901635fd599e551..9629e43d510b2bfe3a412c39e0291ab3989015a6 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 0f6102169cf6013ad017f4a8f7b830fd98dd1c4a..54f482b1d8c3909ef0a87e36ee8efa1f88815729 100644 (file)
@@ -82,6 +82,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_THREADS_UNAVAILABLE                            0
 #define CMK_THREADS_USE_ALLOCA                             0
index 7366e9b97255f91753ffe0fab13421e838ef39d5..78d25d394b7265c99a8493aa88e789c208401b7e 100644 (file)
@@ -84,6 +84,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 82b4d8e4b307cd9b354e543d4ac07afce75e289d..2c497176a775788d0908f3e7379990341656c3b2 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 06fb72926cc7e13cc7f0806325d0b92b6cdc0f8a..a472b176098d1c353ade0af47560c0facc5e00b0 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index d4fd35ebf56f49d8f2c79301ea7fb014387f11df..99b8525d4f5e4a6e26226301df33a49b2a023334 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 4d4fe798c29d00499459b98da18be616d4df7681..eb34fc537d0b117fc3962ba164cf461e76d9d0b9 100644 (file)
@@ -81,6 +81,7 @@
 #define CMK_SYNCHRONIZE_ON_TCP_CLOSE                       0
 
 #define CMK_THREADS_REQUIRE_NO_CPV                         1
+#define CMK_THREADS_COPY_STACK                             0
 
 #define CMK_TIMER_USE_GETRUSAGE                            0
 #define CMK_TIMER_USE_SPECIAL                              0
index 61471cf370f5758cd92a70e627cdd9a6a1309122..3d46a20ae0c2d2f458f2233f9bcd8f3a7ea197f3 100644 (file)
@@ -123,6 +123,7 @@ extern CmiNodeLock CmiCreateLock(void);
 
 #include <thread.h>
 #include <synch.h>
+#include <stdlib.h>
 
 extern int Cmi_numpes;
 extern int Cmi_mynodesize;
index f87ef23f7b25313402bad67fdb12fb96b5368f25..f28d36931a31ed43fcdeba55882d54201a8826ee 100644 (file)
@@ -119,7 +119,7 @@ void *realloc(mem, size)
   return (void *) result;
 }
 
-char *memalign(align, size)
+void *memalign(align, size)
     int align, size;
 {
   char *result;
index 4805ea36277c956a434b2290a94ec486439b3e26..0b4d4f18022ae85ede609c212b1eb8450996aca7 100644 (file)
 #include "converse.h"
 #include "qt.h"
 #include "conv-trace.h"
+#include <sys/types.h>
+
+#if CMK_THREADS_COPY_STACK
+
+#define SWITCHBUF_SIZE 16384
+
+typedef struct CthProcInfo *CthProcInfo;
+
+CthThread x;
+
+struct CthThreadStruct
+{
+  char cmicore[CmiMsgHeaderSizeBytes];
+  CthVoidFn  awakenfn;
+  CthThFn    choosefn;
+  CthVoidFn  startfn;    /* function that thread will execute */
+  void      *startarg;   /* argument that start function will be passed */
+  int        insched;    /* is this thread in scheduler queue */
+  int        killed;     /* thread is marked for death */
+  char      *data;       /* thread private data */
+  int        datasize;   /* size of thread-private data, in bytes */
+/** addition for tracing */
+  int        Event;
+/** End Addition */
+  CthThread  qnext;      /* for cthsetnext and cthgetnext */
+  qt_t      *savedstack; /* pointer to saved stack (null when running) */
+  int        savedsize;  /* length of saved stack (zero when running) */
+  qt_t      *savedptr;   /* stack pointer (null when running) */
+};
+
+/** addition for tracing */
+void setEvent(CthThread t, int event)
+{
+  t->Event = event;
+}
+
+int getEvent(CthThread t)
+{
+  return t->Event;
+}
+/** End Addition */
+
+struct CthProcInfo
+{
+  CthThread  current;
+  int        datasize;
+  qt_t      *stackbase;
+  qt_t      *switchbuf_sp;
+  qt_t      *switchbuf;
+};
+
+CthCpvDeclare(char *, CthData);
+CthCpvDeclare(CthProcInfo, CthProc);
+
+int CthImplemented()
+{ return 1; }
+
+static void CthThreadInit(CthThread t, CthVoidFn fn, void *arg)
+{
+  t->awakenfn = 0;
+  t->choosefn = 0;
+  t->startfn = fn;
+  t->startarg = arg;
+  t->insched = 0;
+  t->killed = 0;
+  t->data = 0;
+  t->datasize = 0;
+  t->qnext = 0;
+  t->savedstack = 0;
+  t->savedsize = 0;
+  t->savedptr = 0;
+  CthSetStrategyDefault(t);
+}
+
+void CthFixData(CthThread t)
+{
+  CthProcInfo proc = CthCpvAccess(CthProc);
+  int datasize = proc->datasize;
+  if (t->data == 0) {
+    t->datasize = datasize;
+    t->data = (char *)malloc(datasize);
+    return;
+  }
+  if (t->datasize != datasize) {
+    t->datasize = datasize;
+    t->data = (char *)realloc(t->data, datasize);
+    return;
+  }
+}
+
+static void CthFreeNow(CthThread t)
+{
+  if (t->data) free(t->data);
+  if (t->savedstack) free(t->savedstack);
+  free(t);
+}
+
+void CthFree(t)
+CthThread t;
+{
+  CthProcInfo proc = CthCpvAccess(CthProc);
+  if ((t->insched == 0)&&(t != proc->current)) {
+    CthFreeNow(t);
+    return;
+  }
+  t->killed = 1;
+}
+
+void CthDummy() { }
+
+void CthInit()
+{
+  CthThread t; CthProcInfo p; qt_t *switchbuf, *sp;
+
+  CthCpvInitialize(char *, CthData);
+  CthCpvInitialize(CthProcInfo, CthProc);
+
+  t = (CthThread)malloc(sizeof(struct CthThreadStruct));
+  p = (CthProcInfo)malloc(sizeof(struct CthProcInfo));
+  CthThreadInit(t,0,0);
+  CthCpvAccess(CthData)=0;
+  CthCpvAccess(CthProc)=p;
+  sp = (qt_t*)(((size_t)&t) & ~((size_t)0xFFFFF));
+  p->stackbase = QT_SP(sp, 0x100000);
+  p->current = t;
+  p->datasize = 0;
+  switchbuf = (qt_t*)malloc(QT_STKALIGN + SWITCHBUF_SIZE);
+  switchbuf = (qt_t*)((((size_t)switchbuf)+QT_STKALIGN-1) & (~QT_STKALIGN));
+  p->switchbuf = switchbuf;
+  sp = QT_SP(switchbuf, SWITCHBUF_SIZE);
+  sp = QT_ARGS(sp,0,0,0,(qt_only_t*)CthDummy);
+  p->switchbuf_sp = sp;
+  CthSetStrategyDefault(t);
+}
+
+CthThread CthSelf()
+{
+  CthThread result = CthCpvAccess(CthProc)->current;
+  if (result==0) CmiAbort("BARF!");
+  return result;
+}
+
+static void CthOnly(CthThread t, void *dum1, void *dum2)
+{
+  t->startfn(t->startarg);
+  t->killed = 1;
+  CthSuspend();
+}
+
+static void CthResume1(qt_t *sp, CthProcInfo proc, CthThread t)
+{
+  int bytes; qt_t *lo, *hi;
+  CthThread old = proc->current;
+  if (old->killed) {
+    if (old->insched==0) CthFreeNow(old);
+  } else {
+#ifdef QT_GROW_DOWN
+    lo = sp; hi = proc->stackbase;
+#else
+    hi = sp; lo = proc->stackbase;
+#endif
+    bytes = ((size_t)hi)-((size_t)lo);
+    old->savedstack = (qt_t*)malloc(bytes);
+    old->savedsize = bytes;
+    old->savedptr = sp;
+    memcpy(old->savedstack, lo, bytes);
+  }
+  CthFixData(t);
+  CthCpvAccess(CthData) = t->data;
+  if (t->savedstack) {
+#ifdef QT_GROW_DOWN
+    lo = t->savedptr;
+#else
+    lo = proc->stackbase;
+#endif
+    memcpy(lo, t->savedstack, t->savedsize);
+    free(t->savedstack);
+    t->savedstack=0;
+    t->savedsize=0;
+    sp = t->savedptr;
+  } else {
+    sp = proc->stackbase;
+    sp = QT_ARGS(sp,t,0,0,(qt_only_t*)CthOnly);
+  }
+  proc->current = t;
+  t->insched = 0;
+  QT_ABORT((qt_helper_t*)CthDummy,0,0,sp);
+}
+
+void CthResume(t)
+CthThread t;
+{
+  CthProcInfo proc = CthCpvAccess(CthProc);
+  QT_BLOCK((qt_helper_t*)CthResume1, proc, t, proc->switchbuf_sp);
+}
+
+CthThread CthCreate(fn, arg, size)
+CthVoidFn fn; void *arg; int size;
+{
+  CthThread result = (CthThread)malloc(sizeof(struct CthThreadStruct));
+  CthThreadInit(result, fn, arg);
+  return result;
+}
+
+static void CthNoStrategy()
+{
+  CmiAbort("Called CthAwaken or CthSuspend before calling CthSetStrategy.\n");
+}
+
+void CthSuspend()
+{
+  CthThread current, next;
+  current = CthCpvAccess(CthProc)->current;
+  if (current->choosefn == 0) CthNoStrategy();
+  /* Pick a thread, discarding dead ones */
+  while (1) {
+    next = current->choosefn();
+    if (next->killed == 0) break;
+    CmiAbort("picked dead thread.");
+    if (next==current)
+      CmiAbort("Current thread dead, cannot pick new thread.");
+    CthFreeNow(next);
+  }
+  CthResume(next);
+}
+
+void CthAwaken(th)
+CthThread th;
+{
+  if (th->awakenfn == 0) CthNoStrategy();
+  if (th->insched) CmiAbort("CthAwaken: thread already awake.");
+  th->awakenfn(th);
+  th->insched = 1;
+}
+
+void CthSetStrategy(t, awkfn, chsfn)
+CthThread t;
+CthVoidFn awkfn;
+CthThFn chsfn;
+{
+  t->awakenfn = awkfn;
+  t->choosefn = chsfn;
+}
+
+void CthYield()
+{
+  CthAwaken(CthCpvAccess(CthProc)->current);
+  CthSuspend();
+}
+
+int CthRegister(size)
+int size;
+{
+  CthProcInfo proc = CthCpvAccess(CthProc);
+  int result;
+  proc->datasize = (proc->datasize + 7) & (~7);
+  result = proc->datasize;
+  proc->datasize += size;
+  CthFixData(proc->current);
+  CthCpvAccess(CthData) = proc->current->data;
+  return result;
+}
+
+void CthSetNext(CthThread t, CthThread v)
+{
+  t->qnext = v;
+}
+
+CthThread CthGetNext(CthThread t) 
+{
+  return t->qnext;
+}
+
+#else
 
 #define STACKSIZE (32768)
 
@@ -383,4 +657,4 @@ CthThread CthGetNext(CthThread t)
 {
   return t->qnext;
 }
-
+#endif