From 4d68d5d045b975d50adba6bf40fa63264a7224b9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 3 Jan 2005 18:01:32 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2456, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2457 --- detach/README | 4 + detach/detach.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ detach/makefile | 94 +++++++++++++++++++++ 3 files changed, 350 insertions(+) create mode 100644 detach/README create mode 100644 detach/detach.c create mode 100644 detach/makefile (limited to 'detach') diff --git a/detach/README b/detach/README new file mode 100644 index 0000000..1cdc041 --- /dev/null +++ b/detach/README @@ -0,0 +1,4 @@ +the message to the inlet will be sent to the outlet, but all +functions called as result of this message run in a helper thread. + +requirement: pd>=devel_0_38 \ No newline at end of file diff --git a/detach/detach.c b/detach/detach.c new file mode 100644 index 0000000..67c4b1e --- /dev/null +++ b/detach/detach.c @@ -0,0 +1,252 @@ +/* +* +* detatch +* Copyright (C) 2005 Tim Blechmann +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +*/ + +#include "m_pd.h" +#include "m_fifo.h" + +#include "pthread.h" + + +static t_class *detatch_class; + +typedef t_fifo fifo_t; /* for emacs syntax highlighting */ + +typedef struct _detatch +{ + t_object x_obj; + + t_outlet * x_outlet; + + pthread_t x_thread; + pthread_mutex_t x_mutex; + pthread_cond_t x_cond; + + fifo_t * x_fifo; + +} detatch_t; + +typedef struct _detatch_content +{ + enum { BANG, + POINTER, + FLOAT, + SYMBOL, + LIST, + ANYTHING, + CANCEL} type; + int argc; + t_atom * argv; +} detatch_content_t; + + +static void detatch_thread(detatch_t* x) +{ + detatch_content_t * me; + while(1) + { + pthread_cond_wait(&x->x_cond, &x->x_mutex); + + me = (detatch_content_t*) fifo_get(x->x_fifo); + + while (me != NULL) + { + /* run function */ + switch (me->type) + { + case BANG: + outlet_bang(x->x_outlet); + break; + case FLOAT: + outlet_float(x->x_outlet, atom_getfloat(me->argv)); + break; + case SYMBOL: + outlet_symbol(x->x_outlet, atom_getsymbol(me->argv)); + break; + case LIST: + outlet_list(x->x_outlet, 0, me->argc, me->argv); + freebytes(me->argv, me->argc * sizeof(t_atom)); + break; + case ANYTHING: + outlet_anything(x->x_outlet, 0, me->argc, me->argv); + freebytes(me->argv, me->argc * sizeof(t_atom)); + break; + case CANCEL: + goto done; + + } + + /* free */ + if (me->argc) + freebytes(me->argv, me->argc * sizeof (t_atom)); + freebytes (me, sizeof(detatch_content_t)); + + me = (detatch_content_t*) fifo_get(x->x_fifo); + } + } + + done: /* free the fifo and exit */ + + do + { + if (me->argc) + freebytes(me->argv, me->argc * sizeof (t_atom)); + freebytes (me, sizeof(detatch_content_t)); + } + while (me = (detatch_content_t*) fifo_get(x->x_fifo)); + + fifo_destroy(x->x_fifo); + return; +} + +/* todo: take argument for thread priority */ +static detatch_t * detatch_new(void) +{ + detatch_t *x = (detatch_t*) pd_new(detatch_class); + pthread_attr_t thread_attr; + struct sched_param thread_sched; + int status; + + x->x_outlet = outlet_new(&x->x_obj, NULL); + x->x_fifo = fifo_init(); + + /* thread initialisation */ + pthread_mutex_init (&x->x_mutex,NULL); + pthread_mutex_unlock (&x->x_mutex); + pthread_cond_init (&x->x_cond,NULL); + + pthread_attr_init(&thread_attr); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING + thread_sched.sched_priority=sched_get_priority_min(SCHED_OTHER); + pthread_attr_setschedparam(&thread_attr,&thread_sched); +#endif + status = pthread_create(&x->x_thread, &thread_attr, + (void*)detatch_thread, x); + +#if 1 + if (status == 0) + post("detatching thread"); +#endif + return x; +} + + +static void detatch_free(detatch_t * x) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = CANCEL; + me->argc = 0; + fifo_put(x->x_fifo, me); + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_bang(detatch_t * x) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = BANG; + me->argc = 0; + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_float(detatch_t * x, t_float f) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = FLOAT; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETFLOAT(me->argv, f); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_pointer(detatch_t * x, t_gpointer* gp) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = POINTER; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETPOINTER(me->argv, gp); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_symbol(detatch_t * x, t_symbol * s) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = SYMBOL; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETSYMBOL(me->argv, s); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_list(detatch_t * x, t_symbol * s, + int argc, t_atom* argv) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = LIST; + me->argc = argc; + me->argv = copybytes(argv, argc * sizeof(t_atom)); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_anything(detatch_t * x, t_symbol * s, + int argc, t_atom* argv) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = ANYTHING; + me->argc = argc; + me->argv = copybytes(argv, argc * sizeof(t_atom)); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +void detatch_setup(void) +{ + detatch_class = class_new(gensym("detatch"), (t_newmethod)detatch_new, + (t_method)detatch_free, sizeof(detatch_t), + CLASS_DEFAULT, 0); + class_addbang(detatch_class, detatch_bang); + class_addfloat(detatch_class, detatch_float); + class_addpointer(detatch_class, detatch_pointer); + class_addsymbol(detatch_class, detatch_symbol); + class_addlist(detatch_class, detatch_list); + class_addanything(detatch_class, detatch_anything); +} diff --git a/detach/makefile b/detach/makefile new file mode 100644 index 0000000..7a578d6 --- /dev/null +++ b/detach/makefile @@ -0,0 +1,94 @@ +NAME=detatch +CSYM=detatch + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From 37221809e95b99fdf73c39d73efc861875647fa1 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 6 Jan 2005 17:00:45 +0000 Subject: fixed spelling mistake svn path=/trunk/externals/tb/; revision=2468 --- detach/detach.c | 80 ++++++++++++++++++++++++++++----------------------------- detach/makefile | 4 +-- 2 files changed, 42 insertions(+), 42 deletions(-) (limited to 'detach') diff --git a/detach/detach.c b/detach/detach.c index 67c4b1e..6460f6b 100644 --- a/detach/detach.c +++ b/detach/detach.c @@ -1,6 +1,6 @@ /* * -* detatch +* detach * Copyright (C) 2005 Tim Blechmann * * This program is free software; you can redistribute it and/or modify @@ -25,11 +25,11 @@ #include "pthread.h" -static t_class *detatch_class; +static t_class *detach_class; typedef t_fifo fifo_t; /* for emacs syntax highlighting */ -typedef struct _detatch +typedef struct _detach { t_object x_obj; @@ -41,9 +41,9 @@ typedef struct _detatch fifo_t * x_fifo; -} detatch_t; +} detach_t; -typedef struct _detatch_content +typedef struct _detach_content { enum { BANG, POINTER, @@ -54,17 +54,17 @@ typedef struct _detatch_content CANCEL} type; int argc; t_atom * argv; -} detatch_content_t; +} detach_content_t; -static void detatch_thread(detatch_t* x) +static void detach_thread(detach_t* x) { - detatch_content_t * me; + detach_content_t * me; while(1) { pthread_cond_wait(&x->x_cond, &x->x_mutex); - me = (detatch_content_t*) fifo_get(x->x_fifo); + me = (detach_content_t*) fifo_get(x->x_fifo); while (me != NULL) { @@ -96,9 +96,9 @@ static void detatch_thread(detatch_t* x) /* free */ if (me->argc) freebytes(me->argv, me->argc * sizeof (t_atom)); - freebytes (me, sizeof(detatch_content_t)); + freebytes (me, sizeof(detach_content_t)); - me = (detatch_content_t*) fifo_get(x->x_fifo); + me = (detach_content_t*) fifo_get(x->x_fifo); } } @@ -108,18 +108,18 @@ static void detatch_thread(detatch_t* x) { if (me->argc) freebytes(me->argv, me->argc * sizeof (t_atom)); - freebytes (me, sizeof(detatch_content_t)); + freebytes (me, sizeof(detach_content_t)); } - while (me = (detatch_content_t*) fifo_get(x->x_fifo)); + while (me = (detach_content_t*) fifo_get(x->x_fifo)); fifo_destroy(x->x_fifo); return; } /* todo: take argument for thread priority */ -static detatch_t * detatch_new(void) +static detach_t * detach_new(void) { - detatch_t *x = (detatch_t*) pd_new(detatch_class); + detach_t *x = (detach_t*) pd_new(detach_class); pthread_attr_t thread_attr; struct sched_param thread_sched; int status; @@ -138,19 +138,19 @@ static detatch_t * detatch_new(void) pthread_attr_setschedparam(&thread_attr,&thread_sched); #endif status = pthread_create(&x->x_thread, &thread_attr, - (void*)detatch_thread, x); + (void*)detach_thread, x); #if 1 if (status == 0) - post("detatching thread"); + post("detaching thread"); #endif return x; } -static void detatch_free(detatch_t * x) +static void detach_free(detach_t * x) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = CANCEL; me->argc = 0; @@ -159,9 +159,9 @@ static void detatch_free(detatch_t * x) } -static void detatch_bang(detatch_t * x) +static void detach_bang(detach_t * x) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = BANG; me->argc = 0; @@ -171,9 +171,9 @@ static void detatch_bang(detatch_t * x) } -static void detatch_float(detatch_t * x, t_float f) +static void detach_float(detach_t * x, t_float f) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = FLOAT; me->argc = 1; @@ -184,9 +184,9 @@ static void detatch_float(detatch_t * x, t_float f) pthread_cond_broadcast(&x->x_cond); } -static void detatch_pointer(detatch_t * x, t_gpointer* gp) +static void detach_pointer(detach_t * x, t_gpointer* gp) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = POINTER; me->argc = 1; @@ -197,9 +197,9 @@ static void detatch_pointer(detatch_t * x, t_gpointer* gp) pthread_cond_broadcast(&x->x_cond); } -static void detatch_symbol(detatch_t * x, t_symbol * s) +static void detach_symbol(detach_t * x, t_symbol * s) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = SYMBOL; me->argc = 1; @@ -211,10 +211,10 @@ static void detatch_symbol(detatch_t * x, t_symbol * s) } -static void detatch_list(detatch_t * x, t_symbol * s, +static void detach_list(detach_t * x, t_symbol * s, int argc, t_atom* argv) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = LIST; me->argc = argc; @@ -224,10 +224,10 @@ static void detatch_list(detatch_t * x, t_symbol * s, pthread_cond_broadcast(&x->x_cond); } -static void detatch_anything(detatch_t * x, t_symbol * s, +static void detach_anything(detach_t * x, t_symbol * s, int argc, t_atom* argv) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = ANYTHING; me->argc = argc; @@ -238,15 +238,15 @@ static void detatch_anything(detatch_t * x, t_symbol * s, } -void detatch_setup(void) +void detach_setup(void) { - detatch_class = class_new(gensym("detatch"), (t_newmethod)detatch_new, - (t_method)detatch_free, sizeof(detatch_t), + detach_class = class_new(gensym("detach"), (t_newmethod)detach_new, + (t_method)detach_free, sizeof(detach_t), CLASS_DEFAULT, 0); - class_addbang(detatch_class, detatch_bang); - class_addfloat(detatch_class, detatch_float); - class_addpointer(detatch_class, detatch_pointer); - class_addsymbol(detatch_class, detatch_symbol); - class_addlist(detatch_class, detatch_list); - class_addanything(detatch_class, detatch_anything); + class_addbang(detach_class, detach_bang); + class_addfloat(detach_class, detach_float); + class_addpointer(detach_class, detach_pointer); + class_addsymbol(detach_class, detach_symbol); + class_addlist(detach_class, detach_list); + class_addanything(detach_class, detach_anything); } diff --git a/detach/makefile b/detach/makefile index 7a578d6..979bba0 100644 --- a/detach/makefile +++ b/detach/makefile @@ -1,5 +1,5 @@ -NAME=detatch -CSYM=detatch +NAME=detach +CSYM=detach current: pd_linux -- cgit v1.2.1 From 5fda6973fd8d94872a61d99d264ee5902824139d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Jun 2005 12:48:20 +0000 Subject: adapted for updated fifo implementation svn path=/trunk/externals/tb/; revision=3144 --- detach/detach.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'detach') diff --git a/detach/detach.c b/detach/detach.c index 6460f6b..661e073 100644 --- a/detach/detach.c +++ b/detach/detach.c @@ -45,6 +45,7 @@ typedef struct _detach typedef struct _detach_content { + struct _detach_content_t * next; enum { BANG, POINTER, FLOAT, @@ -54,6 +55,7 @@ typedef struct _detach_content CANCEL} type; int argc; t_atom * argv; + t_symbol * symbol; } detach_content_t; @@ -85,7 +87,7 @@ static void detach_thread(detach_t* x) freebytes(me->argv, me->argc * sizeof(t_atom)); break; case ANYTHING: - outlet_anything(x->x_outlet, 0, me->argc, me->argv); + outlet_anything(x->x_outlet, me->symbol, me->argc, me->argv); freebytes(me->argv, me->argc * sizeof(t_atom)); break; case CANCEL: @@ -232,6 +234,7 @@ static void detach_anything(detach_t * x, t_symbol * s, me->type = ANYTHING; me->argc = argc; me->argv = copybytes(argv, argc * sizeof(t_atom)); + me->symbol = s; fifo_put(x->x_fifo, me); pthread_cond_broadcast(&x->x_cond); -- cgit v1.2.1 From 2c1ff19c4d99921dcd55176b5574e932dda39c68 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 9 Jun 2009 17:34:48 +0000 Subject: replaced -export_dynamic with --export-dynamic and -Wl,--export-dynamic where appropriate. It seems that once upon a time -export_dynamic was a real flag. Now it means -e xport_dynamic, meaning set the entry symbol to xport_dynamic, giving this error message: /usr/bin/ld: warning: cannot find entry symbol xport_dynamic; defaulting to 0000000000001b60 svn path=/trunk/externals/tb/; revision=11724 --- detach/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'detach') diff --git a/detach/makefile b/detach/makefile index 979bba0..dc50b33 100644 --- a/detach/makefile +++ b/detach/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o -- cgit v1.2.1