Commit 39a1a877 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@187 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent fffd9372
No preview for this file type
......@@ -36,6 +36,9 @@ WARRANTIES, see the file, "license.txt," in this distribution.
\brief message only base object
*/
//class qmsg;
//class thr_entry;
class flext_base:
public flext_obj
{
......@@ -431,10 +434,12 @@ public:
// --- thread stuff -----------------------------------------------
#ifdef FLEXT_THREADS
class thr_params;
static bool StartThread(void *(*)(thr_params *p),thr_params *p,char *methname);
void PushThread();
void PopThread();
#endif
protected:
......
......@@ -141,7 +141,7 @@ flext_base::flext_base():
#ifdef FLEXT_THREAD
shouldexit = false;
qhead = qtail = NULL;
qclk = clock_new(this,(t_method)QTick);
qclk = (t_clock *)(clock_new(this,(t_method)QTick));
thrhead = thrtail = NULL;
#endif
}
......@@ -152,6 +152,8 @@ flext_base::~flext_base()
// wait for thread termination
shouldexit = true;
for(int wi = 0; thrhead && wi < 100; ++wi) Sleep(0.01f);
#ifdef PD
qmutex.Lock(); // Lock message queue
tlmutex.Lock();
// timeout -> hard termination
......@@ -163,10 +165,13 @@ flext_base::~flext_base()
}
tlmutex.Unlock();
qmutex.Unlock();
#else
#pragma message ("No tread cancelling")
#endif
// send remaining pending messages
while(qhead) QTick(this);
clock_free(qclk);
clock_free((object *)qclk);
#endif
if(inlist) delete inlist;
......
......@@ -95,6 +95,8 @@ typedef method t_method;
typedef method t_newmethod;
typedef int t_atomtype;
typedef struct clock t_clock;
#define A_NULL A_NOTHING
#define A_FLINT A_INT
#define A_DEFFLINT A_DEFLONG
......
......@@ -44,8 +44,8 @@ void flext_base::PushThread()
void flext_base::PopThread()
{
tlmutex.Lock();
thr_entry *prv = NULL;
for(thr_entry *ti = thrhead; ti && !ti->Is(); prv = ti,ti = ti->nxt);
thr_entry *prv = NULL,*ti;
for(ti = thrhead; ti && !ti->Is(); prv = ti,ti = ti->nxt);
if(ti) {
if(prv)
......
......@@ -10,6 +10,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
This shows an example of multiple threads and syncing with a thread conditional
*/
#define FLEXT_THREADS
#include <flext.h>
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 300)
......@@ -52,7 +53,7 @@ thread2::thread2(int del,t_symptr txt):
running(false),blipping(false)
{
AddInAnything();
AddOutAnything();
AddOutInt();
SetupInOut(); // set up inlets and outlets
FLEXT_ADDMETHOD(0,m_start);
......@@ -61,30 +62,42 @@ thread2::thread2(int del,t_symptr txt):
void thread2::m_start(int st)
{
post("start 1");
if(running) { count = st; return; }
running = true;
FLEXT_CALLMETHOD(m_blip);
post("start 2");
for(count = st; !ShouldExit() && !stopit; ++count)
{
Sleep(delay);
ToOutInt(0,count);
}
post("start 3");
cond.Lock();
running = false;
cond.Signal();
cond.Unlock();
post("start 4");
}
void thread2::m_stop()
{
post("stop 1");
cond.Lock();
stopit = true;
while(running || blipping) cond.Wait();
stopit = false;
cond.Unlock();
post("stop 2");
}
void thread2::m_blip()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment