aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranz Zotter <fzotter@users.sourceforge.net>2006-03-26 21:34:29 +0000
committerFranz Zotter <fzotter@users.sourceforge.net>2006-03-26 21:34:29 +0000
commit233856ed92f86cdb4e07da8877df20cb931d5ef7 (patch)
tree95410040d0ddff89a3276dbecc820ab94abf6cc2
parent4998870e6829a2a3818ae87557f81f220442a6b0 (diff)
pdoctave weekend, yeah! So obviously, total nerdness has struck me already. IAOUOIASSFAIUOOOOOOAA!!!
But it works!!! - Octave error handling for errors of write_shared_mem.cc (i.e. undefined variables). - Return value for non existent data packages corrected in write_shared_mem.cc (it has to be removeSharedData instead of freeSharedData in exceptional cases) - opening octave on library startup - removed annoying post messages yesyesyes, perhaps it's time for Georgies threadlib "detach" for pdoctave_get now! svn path=/trunk/externals/iem/pdoctave/; revision=4775
-rw-r--r--pdoctave_command.c4
-rw-r--r--pdoctave_dataframe.c50
-rw-r--r--pdoctave_dataframe.h2
-rw-r--r--pdoctave_get.c14
-rw-r--r--write_shared_mem.cc9
5 files changed, 46 insertions, 33 deletions
diff --git a/pdoctave_command.c b/pdoctave_command.c
index de4135a..e86f9aa 100644
--- a/pdoctave_command.c
+++ b/pdoctave_command.c
@@ -58,7 +58,7 @@ static void removeEscapeSlashes (char *c)
}
static void pDOctaveCommandBang (PDOctaveCommand *pdoctcmd_obj)
{
- post("command: %s sent", pdoctcmd_obj->oct_command);
+ //post("command: %s sent", pdoctcmd_obj->oct_command);
writeToOctaveStdIN (pdoctcmd_obj->oct_command);
}
@@ -82,7 +82,7 @@ static void *newPDOctaveCommand (t_symbol *s, int argc, t_atom *argv)
PDOctaveCommand *pdoctcmd_obj = (PDOctaveCommand *)
pd_new (pdoctave_command_class);
- post("getpdoctaveinstances returned %d", getPDOctaveInstances());
+// post("getpdoctaveinstances returned %d", getPDOctaveInstances());
if (getPDOctaveInstances()<1) {
error("Octave not running, insert a 'pdoctave' object!!");
return 0;
diff --git a/pdoctave_dataframe.c b/pdoctave_dataframe.c
index a5d64a6..89d4455 100644
--- a/pdoctave_dataframe.c
+++ b/pdoctave_dataframe.c
@@ -1,5 +1,5 @@
#include "pdoctave_dataframe.h"
-static int scheduling_ok = 1;
+//static int scheduling_ok = 1;
SharedDataFrame *newSharedDataFrame ()
{
@@ -207,40 +207,48 @@ void blockForWriting (SharedDataFrame *sdf)
int sleepUntilReadUnBlocked (SharedDataFrame *sdf)
{
- //alarm(MAX_SLEEP_TIME);
- while ((sdf->block_for_read!=0)&&scheduling_ok)
- sched_yield();
- return scheduling_ok;
+ int elapsed_time=0;
+ while ((sdf->block_for_read!=0)&&(elapsed_time<MAX_USLEEP_TIME)) {
+ elapsed_time += STD_USLEEP_TIME;
+ usleep(STD_USLEEP_TIME);
+ }
+ return (elapsed_time<MAX_USLEEP_TIME);
}
int sleepUntilReadBlocked (SharedDataFrame *sdf)
{
- //alarm(MAX_SLEEP_TIME);
- while ((sdf->block_for_read==0)&&scheduling_ok)
- sched_yield();
- return scheduling_ok;
+ int elapsed_time=0;
+ while ((sdf->block_for_read==0)&&(elapsed_time<MAX_USLEEP_TIME)) {
+ elapsed_time += STD_USLEEP_TIME;
+ usleep(STD_USLEEP_TIME);
+ }
+ return (elapsed_time<MAX_USLEEP_TIME);
}
int sleepUntilWriteUnBlocked (SharedDataFrame *sdf)
{
- //alarm(MAX_SLEEP_TIME);
- while ((sdf->block_for_write!=0)&&scheduling_ok)
- sched_yield();
- return scheduling_ok;
+ int elapsed_time=0;
+ while ((sdf->block_for_write!=0)&&(elapsed_time<MAX_USLEEP_TIME)) {
+ elapsed_time += STD_USLEEP_TIME;
+ usleep(STD_USLEEP_TIME);
+ }
+ return (elapsed_time<MAX_USLEEP_TIME);
}
int sleepUntilWriteBlocked (SharedDataFrame *sdf)
{
- //alarm(MAX_SLEEP_TIME);
- while ((sdf->block_for_write==0)&&scheduling_ok)
- sched_yield();
- return scheduling_ok;
+ int elapsed_time=0;
+ while ((sdf->block_for_write==0)&&(elapsed_time<MAX_USLEEP_TIME)) {
+ elapsed_time += STD_USLEEP_TIME;
+ usleep(STD_USLEEP_TIME);
+ }
+ return (elapsed_time<MAX_USLEEP_TIME);
}
/*
void sleepUntilReadUnBlocked (SharedDataFrame *sdf, int usleep_time)
{
int timer = 0;
if (sdf) {
- while ((sdf->block_for_read!=0)&&(timer < MAX_SLEEP_TIME)) {
+ while ((sdf->block_for_read!=0)&&(timer < MAX_USLEEP_TIME)) {
timer += usleep_time;
usleep (usleep_time);
}
@@ -250,7 +258,7 @@ void sleepUntilReadBlocked (SharedDataFrame *sdf, int usleep_time)
{
int timer = 0;
if (sdf) {
- while ((sdf->block_for_read==0)&&(timer < MAX_SLEEP_TIME)) {
+ while ((sdf->block_for_read==0)&&(timer < MAX_USLEEP_TIME)) {
timer +=usleep_time;
usleep (usleep_time);
}
@@ -261,7 +269,7 @@ void sleepUntilWriteUnBlocked (SharedDataFrame *sdf, int usleep_time)
{
int timer = 0;
if (sdf) {
- while ((sdf->block_for_write!=0)&&(timer < MAX_SLEEP_TIME)) {
+ while ((sdf->block_for_write!=0)&&(timer < MAX_USLEEP_TIME)) {
timer +=usleep_time;
usleep (usleep_time);
}
@@ -272,7 +280,7 @@ void sleepUntilWriteBlocked (SharedDataFrame *sdf, int usleep_time)
{
int timer = 0;
if (sdf) {
- while ((sdf->block_for_write==0)&&(timer < MAX_SLEEP_TIME)) {
+ while ((sdf->block_for_write==0)&&(timer < MAX_USLEEP_TIME)) {
timer +=usleep_time;
usleep (usleep_time);
}
diff --git a/pdoctave_dataframe.h b/pdoctave_dataframe.h
index c20ee45..787b275 100644
--- a/pdoctave_dataframe.h
+++ b/pdoctave_dataframe.h
@@ -15,7 +15,7 @@ extern "C" {
#include "pdoctave_datatypes.h"
#define STD_USLEEP_TIME 100
-#define MAX_SLEEP_TIME 2
+#define MAX_USLEEP_TIME 5000000
typedef struct _SharedDataFrame_ SharedDataFrame;
diff --git a/pdoctave_get.c b/pdoctave_get.c
index 614ec84..6c371a2 100644
--- a/pdoctave_get.c
+++ b/pdoctave_get.c
@@ -26,7 +26,7 @@ static void *newPDOctaveGet (t_symbol *s, int argc, t_atom *argv)
pd_new (pdoctave_get_class);
t_symbol *name;
- post("getpdoctaveinstances returned %d", getPDOctaveInstances());
+// post("getpdoctaveinstances returned %d", getPDOctaveInstances());
if (getPDOctaveInstances()<1) {
error("Octave not running, insert a 'pdoctave' object!!");
return 0;
@@ -64,7 +64,7 @@ static void pDOctaveGetCommand (PDOctaveGet *pdoctget_obj)
sprintf(cmd, "%d", getSharedDataFrameId(pdoctget_obj->sdf));
cmd +=strlen(cmd);
strcpy (cmd,");\n end\n\0");
- post("pdoctave_get: %s",pdoctget_obj->oct_command);
+ //post("pdoctave_get: %s",pdoctget_obj->oct_command);
writeToOctaveStdIN (pdoctget_obj->oct_command);
}
@@ -140,6 +140,7 @@ static void pdoctaveOutletList (PDOctaveGet *pdoctget_obj)
break;
case UNKNOWN:
post("pdoctave_get: unknown return value");
+ s = gensym("");
return;
}
outlet_anything (pdoctget_obj->outlet,
@@ -161,13 +162,18 @@ static void pDOctaveGetBang (PDOctaveGet *pdoctget_obj)
// sending read command
blockForWriting (sdf);
pDOctaveGetCommand (pdoctget_obj);
+ // waiting for results
if((sleepUntilWriteUnBlocked (sdf))==0) {
error("pdoctave_get: pd and octave scheduling error, restart pd!");
+ unBlockForReading (sdf);
return;
}
- // waiting for results
- pdoctget_obj->data = getSharedData (sdf);
+ if ((pdoctget_obj->data = getSharedData (sdf))==0) {
+ error("pdoctave_get: empty data package received");
+ unBlockForReading (sdf);
+ return;
+ }
// converting incoming data
pdoctaveConvertData (pdoctget_obj);
diff --git a/write_shared_mem.cc b/write_shared_mem.cc
index 7810d1d..b1c01dc 100644
--- a/write_shared_mem.cc
+++ b/write_shared_mem.cc
@@ -66,9 +66,8 @@ DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
return octave_value();
}
if (args(0).is_empty()) {
- pdtype = UNKNOWN;
unBlockForWriting (sdf);
- freeSharedDataFrame (&sdf);
+ removeSharedDataFrame (&sdf);
return octave_value();
}
else if (args(0).is_string()) {
@@ -80,7 +79,7 @@ DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
else {
error("failed to get new data memory!");
unBlockForWriting (sdf);
- freeSharedDataFrame (&sdf);
+ removeSharedDataFrame (&sdf);
return octave_value();
}
@@ -94,7 +93,7 @@ DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
else {
error("failed to get new data memory!");
unBlockForWriting (sdf);
- freeSharedDataFrame (&sdf);
+ removeSharedDataFrame (&sdf);
return octave_value();
}
}
@@ -106,7 +105,7 @@ DEFUN_DLD (write_shared_mem, args, , "returning an octave value to pd-value")
else {
error("failed to get new data memory!");
unBlockForWriting (sdf);
- freeSharedDataFrame (&sdf);
+ removeSharedDataFrame (&sdf);
return octave_value();
}
}