Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/csound/csound into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gogins committed Dec 3, 2017
2 parents efc4b92 + 5c2fa4b commit 5447a8f
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Engine/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ void timexpire(CSOUND *, double);
static void instance(CSOUND *, int);
extern int argsRequired(char* argString);

typedef struct _inst_ {
CSOUND *csound;
int insno;
volatile unsigned char done;
} INST_DATA;

uintptr_t instance_thread(void *p) {
CSOUND *csound = ((INST_DATA *) p)->csound;
int insno = ((INST_DATA *) p)->insno;
instance(csound, insno);
#if defined(HAVE_ATOMIC_BUILTIN)
__atomic_add_fetch(&((INST_DATA *) p)->done, 1, __ATOMIC_SEQ_CST);
#else
&((INST_DATA *) p)->done = 1;
#endif
return (uintptr_t) NULL;
}

int init0(CSOUND *csound)
{
INSTRTXT *tp = csound->engineState.instrtxtp[0];
Expand Down Expand Up @@ -107,6 +125,7 @@ int insert(CSOUND *csound, int insno, EVTBLK *newevtp)
OPARMS *O = csound->oparms;
CS_VAR_MEM *pfields = NULL; /* *** was uninitialised *** */
int tie=0, i;
INST_DATA instance_data = { csound, 0, 0 };

if (UNLIKELY(csound->advanceCnt))
return 0;
Expand Down Expand Up @@ -172,11 +191,17 @@ int insert(CSOUND *csound, int insno, EVTBLK *newevtp)
else
csound->Message(csound, Str("new alloc for instr %d:\n"), insno);
}
instance(csound, insno);

if(csound->oparms->realtime) {
instance_data.insno = insno;
csound->CreateThread(instance_thread, &instance_data);
int done = instance_data.done;
while(!done) done = instance_data.done;
}
else instance(csound, insno);
tp->isNew=0;
}
/* **** COVERITY: note that call to instance fills in structure to
**** which tp points. This is a false positive **** */

/* pop from free instance chain */
if (UNLIKELY(csound->oparms->odebug))
csoundMessage(csound, "insert(): tp->act_instance = %p \n", tp->act_instance);
Expand Down

0 comments on commit 5447a8f

Please sign in to comment.