From e306abcb858c16f3e4d357727045cc9975bc2b6a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 11 Aug 2006 22:55:19 +0000 Subject: [PATCH] Ported threading to win32 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9247 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/director_thread.i | 36 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/SWIG/Examples/test-suite/director_thread.i b/SWIG/Examples/test-suite/director_thread.i index bb4ec287d..4e792858c 100644 --- a/SWIG/Examples/test-suite/director_thread.i +++ b/SWIG/Examples/test-suite/director_thread.i @@ -8,22 +8,40 @@ #endif %{ +#ifdef _WIN32 +#include +#include +#else #include +#include +#endif + #include class Foo; -extern "C" void* working(void* t); +extern "C" { + void* SWIGSTDCALL working(void* t); +} %} %director Foo; %inline { + static void MilliSecondSleep(int milliseconds) { + #ifdef _WIN32 + Sleep(milliseconds); + #else + usleep(milliseconds*1000); + #endif + } + class Foo { public: int val; pthread_t *t; + unsigned int thread_id; - Foo() : val(0) { + Foo() : val(0), thread_id(0) { t = new pthread_t; } @@ -32,8 +50,12 @@ extern "C" void* working(void* t); } void run() { +#ifdef _WIN32 + _beginthreadex(NULL,0,run,this,0,&thread_id); +#else pthread_create(t,NULL,working,this); - sleep(5); +#endif + MilliSecondSleep(5000); } virtual void do_foo() { @@ -42,13 +64,15 @@ extern "C" void* working(void* t); }; } -%inline { - extern "C" void* working(void* t) { +%inline %{ + extern "C" { + void* working(void* t) { Foo* f = static_cast(t); while (1) { - sleep(1); + MilliSecondSleep(1000); f->do_foo(); } return 0; } } +%}