aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source/flthr.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2003-06-30 02:33:10 +0000
committerThomas Grill <xovo@users.sourceforge.net>2003-06-30 02:33:10 +0000
commit86bdc7d828f8df51a072da396217ce6c38b7034a (patch)
tree4c5bbfeadd75ba0821c54d02f6103e74811e7b3a /externals/grill/flext/source/flthr.cpp
parentd5c52075e76d9eb3a373b6367f59d457ee9e7c71 (diff)
""
svn path=/trunk/; revision=739
Diffstat (limited to 'externals/grill/flext/source/flthr.cpp')
-rw-r--r--externals/grill/flext/source/flthr.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/externals/grill/flext/source/flthr.cpp b/externals/grill/flext/source/flthr.cpp
index 3bd5bbf4..84623a3d 100644
--- a/externals/grill/flext/source/flthr.cpp
+++ b/externals/grill/flext/source/flthr.cpp
@@ -25,10 +25,6 @@ flext::thrid_t flext::thrid = 0;
//! Thread id of helper thread
flext::thrid_t flext::thrhelpid = 0;
-/*
-flext::thr_entry *flext::thrhead = NULL,*flext::thrtail = NULL;
-flext::ThrMutex flext::tlmutex;
-*/
static flext::thr_entry *thrhead = NULL,*thrtail = NULL;
static flext::ThrMutex tlmutex;
@@ -198,6 +194,49 @@ bool flext::LaunchThread(void (*meth)(thr_params *p),thr_params *p)
return true;
}
+bool flext::StopThread(void (*meth)(thr_params *p),thr_params *p,bool wait)
+{
+#ifdef FLEXT_DEBUG
+ if(!thrhelpcond) {
+ ERRINTERNAL();
+ return false;
+ }
+#endif
+
+ int found = 0;
+
+ tlmutex.Lock();
+ for(thr_entry *ti = thrhead; ti; ti = ti->nxt)
+ // set shouldexit if meth and params match
+ if(ti->meth == meth && ti->params == p) { ti->shouldexit = true; found++; }
+ tlmutex.Unlock();
+
+ if(found) {
+ // signal thread helper
+ thrhelpcond->Signal();
+
+ int cnt = 0;
+ for(int wi = 0; wi < 100; ++wi) {
+ // lock and count this object's threads
+ cnt = 0;
+ tlmutex.Lock();
+ for(thr_entry *t = thrhead; t; t = t->nxt)
+ if(t->meth == meth && t->params == p) ++cnt;
+ tlmutex.Unlock();
+
+ // if no threads are remaining, we are done
+ if(!cnt) break;
+
+ // Wait
+ Sleep(0.01f);
+ }
+
+ return cnt == 0;
+ }
+ else
+ return false;
+}
+
bool flext_base::ShouldExit() const
{
bool ret = true;