Commit 8437bd59 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@188 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 39a1a877
No preview for this file type
......@@ -353,6 +353,13 @@ public:
bool ShouldExit() const { return shouldexit; }
void Yield() // yield to other threads (for cooperative multitasking)
#ifndef MAXMSP
{}
#else
;
#endif
class ThrMutex
{
public:
......@@ -524,6 +531,9 @@ private:
qmsg *qhead,*qtail;
t_clock *qclk;
ThrMutex qmutex;
#ifdef MAXMSP
t_clock *yclk;
#endif
static void QTick(flext_base *th);
void Queue(qmsg *m);
......
......@@ -143,6 +143,9 @@ flext_base::flext_base():
qhead = qtail = NULL;
qclk = (t_clock *)(clock_new(this,(t_method)QTick));
thrhead = thrtail = NULL;
#ifdef MAXMSP
yclk = (t_clock *)(clock_new(this,(t_method)QTick));
#endif
#endif
}
......@@ -172,6 +175,9 @@ flext_base::~flext_base()
// send remaining pending messages
while(qhead) QTick(this);
clock_free((object *)qclk);
#ifdef MAXMSP
clock_free((object *)yclk);
#endif
#endif
if(inlist) delete inlist;
......
......@@ -12,6 +12,11 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <flext.h>
#ifdef MAXMSP
#define SCHEDTICK 1
#include <sched.h>
#endif
bool flext_base::StartThread(void *(*meth)(thr_params *p),thr_params *p,char *methname)
{
#ifdef _DEBUG
......@@ -27,8 +32,12 @@ bool flext_base::StartThread(void *(*meth)(thr_params *p),thr_params *p,char *me
delete p;
return false;
}
else
else {
#ifdef MAXMSP
sched_yield();
#endif
return true;
}
}
void flext_base::PushThread()
......@@ -39,6 +48,10 @@ void flext_base::PushThread()
else thrhead = nt;
thrtail = nt;
tlmutex.Unlock();
#ifdef MAXMSP
if(thrhead) clock_delay(yclk,SCHEDTICK);
#endif
}
void flext_base::PopThread()
......@@ -60,8 +73,15 @@ void flext_base::PopThread()
}
tlmutex.Unlock();
#ifdef MAXMSP
if(!thrhead) clock_unset(&yclk);
#endif
}
#ifdef MAXMSP
void flext_base::Yield() { sched_yield(); }
#endif
class flext_base::qmsg
{
......@@ -123,6 +143,8 @@ void flext_base::QTick(flext_base *th)
}
#endif
th->Yield();
th->qmutex.Lock();
while(th->qhead) {
qmsg *m = th->qhead;
......@@ -145,6 +167,10 @@ void flext_base::QTick(flext_base *th)
delete m;
}
th->qmutex.Unlock();
#ifdef MAXMSP
if(th->thrhead) clock_delay(th->yclk,SCHEDTICK);
#endif
}
void flext_base::Queue(qmsg *m)
......
......@@ -14,6 +14,11 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <windows.h>
#endif
#ifdef MAXMSP
#include <Timer.h>
#include <Threads.h>
#endif
t_atom *flext_base::CopyList(int argc,const t_atom *argv)
{
int i;
......@@ -26,7 +31,14 @@ void flext_base::Sleep(float s)
{
#ifdef NT
::Sleep((long)(s*1000));
#else
Delay(s*1000,NULL);
#elif defined MAXMSP
UnsignedWide tick;
Microseconds(&tick);
double target = tick.hi*((double)(1<<16)*(double)(1<<16))+tick.lo+s*1.e6;
for(;;) {
Microseconds(&tick);
if(target <= tick.hi*((double)(1<<16)*(double)(1<<16))+tick.lo) break;
YieldToAnyThread();
}
#endif
}
\ No newline at end of file
......@@ -41,6 +41,8 @@ private:
t_symbol *bliptxt;
ThrCond cond;
int flag;
};
FLEXT_NEW_2("thread2",thread2,int,t_symptr)
......@@ -52,6 +54,8 @@ thread2::thread2(int del,t_symptr txt):
stopit(false),
running(false),blipping(false)
{
flag = 0;
AddInAnything();
AddOutInt();
SetupInOut(); // set up inlets and outlets
......@@ -62,6 +66,8 @@ thread2::thread2(int del,t_symptr txt):
void thread2::m_start(int st)
{
++flag;
post("start 1");
if(running) { count = st; return; }
......@@ -90,6 +96,7 @@ void thread2::m_start(int st)
void thread2::m_stop()
{
post("stop 1");
post("flag = %i",flag);
cond.Lock();
stopit = true;
......
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