Fix win32 threads
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9253 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
91fe301ff4
commit
2607efe86e
1 changed files with 26 additions and 19 deletions
|
|
@ -20,7 +20,13 @@
|
||||||
|
|
||||||
class Foo;
|
class Foo;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void* SWIGSTDCALL working(void* t);
|
#ifdef _WIN32
|
||||||
|
unsigned int __stdcall working(void* t);
|
||||||
|
unsigned int thread_id(0);
|
||||||
|
#else
|
||||||
|
void* working(void* t);
|
||||||
|
pthread_t thread;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
@ -28,34 +34,30 @@ extern "C" {
|
||||||
|
|
||||||
%inline {
|
%inline {
|
||||||
static void MilliSecondSleep(int milliseconds) {
|
static void MilliSecondSleep(int milliseconds) {
|
||||||
#ifdef _WIN32
|
%#ifdef _WIN32
|
||||||
Sleep(milliseconds);
|
Sleep(milliseconds);
|
||||||
#else
|
%#else
|
||||||
usleep(milliseconds*1000);
|
usleep(milliseconds*1000);
|
||||||
#endif
|
%#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
int val;
|
int val;
|
||||||
pthread_t *t;
|
|
||||||
unsigned int thread_id;
|
|
||||||
|
|
||||||
Foo() : val(0), thread_id(0) {
|
Foo() : val(0) {
|
||||||
t = new pthread_t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Foo() {
|
virtual ~Foo() {
|
||||||
delete t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
#ifdef _WIN32
|
%#ifdef _WIN32
|
||||||
_beginthreadex(NULL,0,run,this,0,&thread_id);
|
_beginthreadex(NULL,0,working,this,0,&thread_id);
|
||||||
#else
|
%#else
|
||||||
pthread_create(t,NULL,working,this);
|
pthread_create(&thread,NULL,working,this);
|
||||||
#endif
|
%#endif
|
||||||
MilliSecondSleep(5000);
|
MilliSecondSleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void do_foo() {
|
virtual void do_foo() {
|
||||||
|
|
@ -64,12 +66,17 @@ extern "C" {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
%inline %{
|
%{
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void* working(void* t) {
|
#ifdef _WIN32
|
||||||
|
unsigned int __stdcall working(void* t)
|
||||||
|
#else
|
||||||
|
void* working(void* t)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
Foo* f = static_cast<Foo*>(t);
|
Foo* f = static_cast<Foo*>(t);
|
||||||
while (1) {
|
while (1) {
|
||||||
MilliSecondSleep(1000);
|
MilliSecondSleep(50);
|
||||||
f->do_foo();
|
f->do_foo();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue