Skip to content

Commit

Permalink
trylocks
Browse files Browse the repository at this point in the history
  • Loading branch information
vlazzarini committed Dec 12, 2017
1 parent 3b4cf69 commit 76bfb83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Engine/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ uintptr_t event_insert_thread(void *p) {
csoundSleep((int) ((int) wakeup > 0 ? wakeup : 1));
else while(items) {
if(inst[rp].isMidi) {
#ifdef HAVE_PTHREAD_SPIN_LOCK
while (pthread_spin_trylock(&csound->alloc_spinlock))
csoundSleep((int) ((int) wakeup > 0 ? wakeup : 1));
#else
csoundSpinLock(&csound->alloc_spinlock);
#endif
insert_midi(csound, inst[rp].insno, inst[rp].chn, &inst[rp].mep);
csoundSpinUnLock(&csound->alloc_spinlock);
}
else {
#ifdef HAVE_PTHREAD_SPIN_LOCK
while (pthread_spin_trylock(&csound->alloc_spinlock))
csoundSleep((int) ((int) wakeup > 0 ? wakeup : 1));
#else
csoundSpinLock(&csound->alloc_spinlock);
#endif
insert_event(csound, inst[rp].insno, &inst[rp].blk);
csoundSpinUnLock(&csound->alloc_spinlock);
}
Expand Down
8 changes: 8 additions & 0 deletions Engine/musmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ int musmon(CSOUND *csound)
extern void *event_insert_thread(void *);
csound->init_pass_threadlock = csoundCreateMutex(0);
#ifdef HAVE_PTHREAD_SPIN_LOCK
csound->Message(csound, "Initialising spinlock...\n");
pthread_spin_init((pthread_spinlock_t*)&csound->alloc_spinlock,
PTHREAD_PROCESS_PRIVATE);
#endif
Expand Down Expand Up @@ -916,6 +917,7 @@ int sensevents(CSOUND *csound)
OPARMS *O = csound->oparms;
int retval = 0, sensType;
int conn, *sinp, end_check=1;
int trylock = 0;

csdebug_data_t *data = (csdebug_data_t *) csound->csdebug_data;
if (UNLIKELY(data && data->status == CSDEBUG_STATUS_STOPPED)) {
Expand All @@ -928,7 +930,12 @@ int sensevents(CSOUND *csound)
}
/* if turnoffs pending, remove any expired instrs */
if(csound->oparms->realtime)
#ifdef HAVE_PTHREAD_SPIN_LOCK
trylock = pthread_spin_trylock(&csound->alloc_spinlock);
#else
csoundSpinLock(&csound->alloc_spinlock);
#endif
if(trylock != 0) {
if (UNLIKELY(csound->frstoff != NULL)) {
double tval;
/* the following comparisons must match those in schedofftim() */
Expand All @@ -944,6 +951,7 @@ int sensevents(CSOUND *csound)
}
if(csound->oparms->realtime)
csoundSpinUnLock(&csound->alloc_spinlock);
}
e = &(csound->evt);
if (--(csound->cyclesRemaining) <= 0) { /* if done performing score segment: */
if (!csound->cyclesRemaining) {
Expand Down

0 comments on commit 76bfb83

Please sign in to comment.