From 86bdc7d828f8df51a072da396217ce6c38b7034a Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 30 Jun 2003 02:33:10 +0000 Subject: "" svn path=/trunk/; revision=739 --- externals/grill/flext/source/flthr.cpp | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'externals/grill/flext/source/flthr.cpp') 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; -- cgit v1.2.1