Commit dc1b99fb authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@262 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 3dfbc7fe
No preview for this file type
......@@ -85,7 +85,8 @@ Version history:
- bugfix for threaded methods with var list or anything arguments
- added threaded method for arbitrary (void *) data structs
- ThrMutex: added lock count functions Push() and Pop()
- eliminated dangerous SetThing,GetThing and introduced DoBind,DoUnbind,GetBound instead
- eliminated potentiallly dangerous SetThing,GetThing and introduced DoBind,DoUnbind,GetBound instead
- fixed severe bug with the current threads list
0.3.1:
- added some more functionality to the AtomList class
......@@ -225,13 +226,10 @@ tests:
- PD: test argument order (t_symbol, pointers before floats)
features:
- abstraction for parsing argument lists
- abstraction for clock functions
- sending messages to own inlet (passing computation to other patch objects - message queue?)
- manage running threads individually (stop, isrunning?, priority etc.)
premature thoughts:
- explore jMax interface style
- interface for scripting language modules? (python?)
- GUI objects
......
......@@ -485,6 +485,7 @@ public:
;
#endif
#if 0
/*! \brief Set current thread to normal priority
\bug Not working under all platforms
*/
......@@ -497,6 +498,13 @@ public:
\bug Not working under all platforms
*/
void LowestPriority();
static int GetPriority();
#else
/*! \brief Increase/Decrease priority of the current thread
*/
static void ChangePriority(int dp);
#endif
/*! \brief Thread mutex
\sa pthreads documentation
......@@ -511,7 +519,7 @@ public:
//! Lock thread mutex
int Lock() { cnt = 1; return pthread_mutex_lock(&mutex); }
//! Try if thread mutex is locked
//! Try to lock, but don't wait
int TryLock() { return pthread_mutex_trylock(&mutex); }
//! Unlock thread mutex
int Unlock() { cnt = 0; return pthread_mutex_unlock(&mutex); }
......
......@@ -192,14 +192,11 @@ flext_base::~flext_base()
if(inlets) {
for(int ix = 0; ix < incnt; ++ix)
if(inlets[ix]) {
object_free(inlets[ix]->obj);
/*
#ifdef PD
pd_free(&inlets[ix]->obj.ob_pd);
#elif defined(MAXMSP)
freeobject((object *)inlets[ix]);
#endif
*/
}
delete[] inlets;
}
......@@ -229,15 +226,15 @@ void flext_base::ToOutBang(outlet *o) { CRITON(); outlet_bang((t_outlet *)o); CR
void flext_base::ToOutFloat(outlet *o,float f) { CRITON(); outlet_float((t_outlet *)o,f); CRITOFF(); }
void flext_base::ToOutInt(outlet *o,int f) { CRITON(); outlet_flint((t_outlet *)o,f); CRITOFF(); }
void flext_base::ToOutSymbol(outlet *o,const t_symbol *s) { CRITON(); outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(s)); CRITOFF(); }
void flext_base::ToOutList(outlet *o,int argc,t_atom *argv) { CRITON(); outlet_list((t_outlet *)o,gensym("list"),argc,argv); CRITOFF(); }
void flext_base::ToOutAnything(outlet *o,const t_symbol *s,int argc,t_atom *argv) { CRITON(); outlet_anything((t_outlet *)o,const_cast<t_symbol *>(s),argc,argv); CRITOFF(); }
void flext_base::ToOutList(outlet *o,int argc,const t_atom *argv) { CRITON(); outlet_list((t_outlet *)o,gensym("list"),argc,(t_atom *)argv); CRITOFF(); }
void flext_base::ToOutAnything(outlet *o,const t_symbol *s,int argc,const t_atom *argv) { CRITON(); outlet_anything((t_outlet *)o,const_cast<t_symbol *>(s),argc,(t_atom *)argv); CRITOFF(); }
#else
void flext_base::ToOutBang(outlet *o) { if(IsSystemThread()) { CRITON(); outlet_bang((t_outlet *)o); CRITOFF(); } else QueueBang(o); }
void flext_base::ToOutFloat(outlet *o,float f) { if(IsSystemThread()) { CRITON(); outlet_float((t_outlet *)o,f); CRITOFF(); } else QueueFloat(o,f); }
void flext_base::ToOutInt(outlet *o,int f) { if(IsSystemThread()) { CRITON(); outlet_flint((t_outlet *)o,f); CRITOFF(); } else QueueInt(o,f); }
void flext_base::ToOutSymbol(outlet *o,const t_symbol *s) { if(IsSystemThread()) { CRITON(); outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(s)); CRITOFF(); } else QueueSymbol(o,s); }
void flext_base::ToOutList(outlet *o,int argc,t_atom *argv) { if(IsSystemThread()) { CRITON(); outlet_list((t_outlet *)o,gensym("list"),argc,argv); CRITOFF(); } else QueueList(o,argc,argv); }
void flext_base::ToOutAnything(outlet *o,const t_symbol *s,int argc,t_atom *argv) { if(IsSystemThread()) { CRITON(); outlet_anything((t_outlet *)o,const_cast<t_symbol *>(s),argc,argv); CRITOFF(); } else QueueAnything(o,s,argc,argv); }
void flext_base::ToOutList(outlet *o,int argc,const t_atom *argv) { if(IsSystemThread()) { CRITON(); outlet_list((t_outlet *)o,gensym("list"),argc,(t_atom *)argv); CRITOFF(); } else QueueList(o,argc,(t_atom *)argv); }
void flext_base::ToOutAnything(outlet *o,const t_symbol *s,int argc,const t_atom *argv) { if(IsSystemThread()) { CRITON(); outlet_anything((t_outlet *)o,const_cast<t_symbol *>(s),argc,(t_atom *)argv); CRITOFF(); } else QueueAnything(o,s,argc,(t_atom *)argv); }
#endif
bool flext_base::SetupInOut()
......@@ -249,14 +246,11 @@ bool flext_base::SetupInOut()
if(inlets) {
for(int ix = 0; ix < incnt; ++ix)
if(inlets[ix]) {
object_free(inlets[ix]->obj);
/*
#ifdef PD
pd_free(&inlets[ix]->obj.ob_pd);
#elif defined(MAXMSP)
freeobject(inlets[ix]);
#endif
*/
}
delete[] inlets;
inlets = NULL;
......
......@@ -41,7 +41,7 @@ void libfunction::add(libfunction *n) { if(nxt) nxt->add(n); else nxt = n; }
void flext_obj::libfun_add(const char *name,t_newmethod newfun,void (*freefun)(flext_hdr *),int argtp1,...)
{
for(int ix = 0; ; ++ix) {
const char *c = fl_extract(name,ix);
const char *c = flext::extract(name,ix);
if(!c || !*c) break;
alias(const_cast<char *>(c)); // make object name available to Max
......
......@@ -16,6 +16,16 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <ctype.h>
#include <string.h>
#define ALIASDEL ','
#ifdef MAXMSP
#define ALIASSLASH ':'
#elif defined(NT)
#define ALIASSLASH '/'
#else
#define ALIASSLASH '/'
#endif
//! C++ strcup function
char *flext::strdup(const char *t)
{
......@@ -31,12 +41,23 @@ const char *flext::extract(const char *name,int ix)
{
static char tmp[1024];
const char *n = name;
const char *del = strchr(name,ALIASDEL);
if(del) {
char *t;
for(t = tmp; *n && n < del && !isspace(*n); ++t,++n) *t = *n;
*(t++) = ALIASSLASH;
n = del+1;
}
for(int i = 0; n && *n; ++i) {
if(i == ix) {
char *t;
for(t = tmp; *n && !isspace(*n); ++t,++n) *t = *n;
*t = 0;
return *tmp?flext::strdup(tmp):NULL;
// return *tmp?flext::strdup(tmp):NULL;
return *tmp?tmp:NULL;
}
else {
while(*n && !isspace(*n)) ++n;
......
......@@ -74,6 +74,8 @@ void flext_base::PopThread()
{
tlmutex.Lock();
pthread_t id = pthread_self();
thr_entry *prv = NULL,*ti;
for(ti = thrhead; ti; prv = ti,ti = ti->nxt)
if(ti->Is()) break;
......@@ -83,7 +85,7 @@ void flext_base::PopThread()
prv->nxt = ti->nxt;
else
thrhead = ti->nxt;
if(!ti->nxt) thrtail = ti;
if(thrtail == ti) thrtail = prv;
ti->nxt = NULL;
delete ti;
......@@ -108,6 +110,7 @@ void flext_base::YTick(flext_base *th) {
#endif
/*
void flext_base::NormalPriority()
{
#ifdef NT
......@@ -155,6 +158,36 @@ void flext_base::LowestPriority()
#endif
}
int flext_base::GetPriority()
{
sched_param parm;
int policy;
if(pthread_getschedparam(pthread_self(),&policy,&parm)) {
post("flext - failed to get parms");
return -1;
}
else
return parm.sched_priority;
}
*/
void flext_base::ChangePriority(int dp)
{
sched_param parm;
int policy;
if(pthread_getschedparam(pthread_self(),&policy,&parm)) {
post("flext - failed to get parms");
}
else {
parm.sched_priority += dp;
if(pthread_setschedparam(pthread_self(),policy,&parm)) {
post("flext - failed to change priority");
}
}
}
class flext_base::qmsg
{
......
......@@ -47,7 +47,7 @@ class flext_base::thr_entry
public:
thr_entry(pthread_t id = pthread_self()): thrid(id),nxt(NULL) {}
bool Is(pthread_t id = pthread_self()) const { return pthread_equal(thrid,id) == 0; }
bool Is(pthread_t id = pthread_self()) const { return pthread_equal(thrid,id) != 0; }
pthread_t thrid;
thr_entry *nxt;
......
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