/*------------------------------------ senseXProcessQueue ---*/ static void senseXProcessQueue(SenseXData * xx) { if (xx && (! xx->fStopping)) { short prevLock; switch (xx->fState) { case kBetweenMessages: prevLock = lockout_set(1); xx->fState = kAwaitingFirstMessage; lockout_set(prevLock); break; case kAfterSecondMessage: prevLock = lockout_set(1); outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; lockout_set(prevLock); break; default: break; } #if USE_EVNUM evnum_incr(); #endif /* USE_EVNUM */ } } // senseXProcessQueue
/*------------------------------------ spaceballPerformWriteCommand ---*/ void spaceballPerformWriteCommand(SpaceballData * xx, const short numBytesToSend, unsigned char * bytesToFollow) { unsigned char dataValue; static t_atom dataList[OUT_BUFFER_SIZE]; if (xx) { short prevLock = lockout_set(1); /* Make sure serialX is in 'chunk' mode. */ if (! xx->fChunkPulseSent) { outlet_bang(xx->fChunkSendOut); xx->fChunkPulseSent = true; } /* Send data. */ for (short ii = 0; ii < numBytesToSend; ++ii, ++bytesToFollow) { dataValue = *bytesToFollow; atom_setlong(dataList + ii, dataValue); } outlet_list(xx->fDataSendOut, 0L, numBytesToSend, dataList); lockout_set(prevLock); } } // spaceballPerformWriteCommand
void match_set(t_match *x, t_symbol *s, short ac, t_atom *av) { t_atom *temp; char savelock; if (!ac) return; if (ac != x->m_size) temp = (t_atom *)sysmem_newptr((long)ac * sizeof(t_atom)); else temp = x->m_want; match_setwant(temp,ac,av); savelock = lockout_set(1); critical_enter(x->m_critical); if (ac != x->m_size) { match_freebytes(x); x->m_want = temp; x->m_seen = (t_atom *)sysmem_newptr((long)ac * sizeof(t_atom)); } x->m_size = ac; match_clear(x); lockout_set(savelock); critical_exit(x->m_critical); }
void LCD_drag(Lcd *x, Point pt, short button_down) { Rect r; short slider; Atom aList[2]; short way; EnterCallback(); #ifdef debug post("¥LCD_drag - start"); #endif r = x->lcd_box.b_rect; if (x->local) { if (button_down) { LCD_MoveTo(x,(long)(x->lcd_where.h),(long)(x->lcd_where.v)); LCD_LineTo(x,(long)(pt.h-r.left),(long)(pt.v-r.top)); } else x->lcd_shiftClick = false; } LCD_posToRC(x,pt); SETLONG(&aList[0],(long)(pt.h-r.left)); SETLONG(&aList[1],(long)(pt.v-r.top)); /* lockouts added by DDZ 12/14/92 */ way = lockout_set(1); outlet_list(x->lcd_outlet,0L,2,aList); lockout_set(way); ExitCallback(); }
void LCD_click(Lcd *x, Point where, short modifiers) { short i; Rect r; Atom aList[2]; short way; EnterCallback(); #ifdef debug post("¥LCD_click - start"); #endif r = x->lcd_box.b_rect; x->lcd_shiftClick = modifiers&shiftKey; if (x->local) LCD_MoveTo(x,(long)(where.h-r.left),(long)(where.v-r.top)); LCD_posToRC(x,where); wind_drag((void *)LCD_drag,x,where); SETLONG(&aList[0],(long)(where.h-r.left)); SETLONG(&aList[1],(long)(where.v-r.top)); /* lockouts added by DDZ 12/14/92 */ way = lockout_set(1); outlet_list(x->lcd_outlet,0L,2,aList); lockout_set(way); ExitCallback(); } /* ms_click */
/*------------------------------------ senseXDoMessage ---*/ void senseXDoMessage(SenseXData * xx) { if (! xx->fStopping) { short prevLock; switch (xx->fState) { case kAwaitingFirstMessage: prevLock = lockout_set(1); if (0 > xx->fOnDelay) { clock_delay(xx->fPollClock, xx->fOnDelay); xx->fState = kBetweenMessages; } else { outlet_int(xx->fResultOut, 1); if (0 > xx->fOffDelay) { clock_delay(xx->fPollClock, xx->fOffDelay); xx->fState = kAfterSecondMessage; } else { outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; } } lockout_set(prevLock); break; case kBetweenMessages: prevLock = lockout_set(1); outlet_int(xx->fResultOut, 1); clock_unset(xx->fPollClock); if (0 < xx->fOffDelay) { clock_delay(xx->fPollClock, xx->fOffDelay); xx->fState = kAfterSecondMessage; } else { outlet_int(xx->fResultOut, 0); xx->fState = kAwaitingFirstMessage; } lockout_set(prevLock); break; default: break; } } } // senseXDoMessage
/*------------------------------------ processErrorQueue ---*/ static void processErrorQueue(UdpObjectData * xx) { if (xx) { short prev_lock = lockout_set(1); outlet_bang(xx->fErrorBangOut); lockout_set(prev_lock); #if USE_EVNUM evnum_incr(); #endif /* USE_EVNUM */ } } // processErrorQueue
/*------------------------------------ x10ProcessQueue ---*/ static void x10ProcessQueue(X10ControlData * xx) { if (xx && (! xx->fStopping)) { short prevLock = lockout_set(1); outlet_bang(xx->fPollerOut); clock_delay(xx->fPollClock, xx->fPollRate); lockout_set(prevLock); #if USE_EVNUM evnum_incr(); #endif /* USE_EVNUM */ } } // x10ProcessQueue
static short AcquireLock(OTUDP *x) { // Mutual exclusion: Make sure that neither Max not Open Transport will interrupt us int i; short oldLockout; oldLockout = lockout_set(1); OTEnterNotifier(x->o_udp_ep); #define TOO_MANY_SPINS 1 i = 0; while (OTAcquireLock(&(x->o_readlock)) == false) { if ((++i) > TOO_MANY_SPINS) { error("¥ otudp_read: OTAcquireLock keeps failing!"); } } if (x->o_semaphoreTest != 0) { ++(x->o_semaphoreTestFailureCount); if (x->o_semaphoreTestFailureCount == 1 || (x->o_semaphoreTestFailureCount % 100) == 0) { error("¥ otudp_read: new semaphore test failed (%d times)"); } } ++(x->o_semaphoreTest); return oldLockout; }
/*------------------------------------ spaceballProcessQueue ---*/ static void spaceballProcessQueue(SpaceballData * xx) { if (xx && (! xx->fStopping)) { short prevLock = lockout_set(1); if (! xx->fReset) { static unsigned char resetString[] = "@RESET\015\015"; if (! xx->fDelayCounter) { spaceballPerformWriteCommand(xx, sizeof(resetString) - 1, resetString); ++xx->fDelayCounter; } else if (xx->fDelayCounter++ >= xx->fResetDuration) { xx->fReset = true; xx->fDelayCounter = 0; } } else if (! xx->fInited) { static unsigned char initString[] = "CB\015NT\015FR?\015P@r@r\015MSSV\015Z\015BcCcCc\015"; if (! xx->fDelayCounter) { spaceballPerformWriteCommand(xx, sizeof(initString) - 1, initString); spaceballZeroValues(xx); ++xx->fDelayCounter; } else if (xx->fDelayCounter++ >= xx->fInitDuration) { xx->fInited = true; xx->fDelayCounter = 0; } } outlet_bang(xx->fSampleBangOut); clock_delay(xx->fPollClock, xx->fPollRate); lockout_set(prevLock); #if USE_EVNUM evnum_incr(); #endif /* USE_EVNUM */ } } // spaceballProcessQueue
static void ReleaseLock(OTUDP *x, short oldLockout) { if (x->o_semaphoreTest != 1) { error("¥ otudp_read: about to release lock, but semaphoreTest is %ld", x->o_semaphoreTest); } --(x->o_semaphoreTest); OTClearLock(&(x->o_readlock)); OTLeaveNotifier(x->o_udp_ep); lockout_set(oldLockout); }
static short AcquireLock(OTTCP *x) { // Mutual exclusion: Make sure that neither Max not Open Transport will interrupt us int i; short oldLockout; oldLockout = lockout_set(1); OTEnterNotifier(x->o_tcp_ep); #define TOO_MANY_SPINS 1 i = 0; while (OTAcquireLock(&(x->o_readlock)) == false) { if ((++i) > TOO_MANY_SPINS) { ouchstring("OTAcquireLock keeps failing inside ottcp_read!"); } } return oldLockout; }
static void ReleaseLock(OTTCP *x, short oldLockout) { OTClearLock(&(x->o_readlock)); OTLeaveNotifier(x->o_tcp_ep); lockout_set(oldLockout); }
/*------------------------------------ spaceballProcessResponse ---*/ void spaceballProcessResponse(SpaceballData * xx, long rr) { if (xx) { short prevLock = lockout_set(1); unsigned char incoming = static_cast<unsigned char>(rr & 0x00ff); short slot = xx->fBufferPos; if (xx->fNextCharEscaped) { xx->fNextCharEscaped = false; if (kSpaceballResponseEscape != incoming) { incoming &= 0x001f; } if (IN_BUFFER_SIZE > slot) { xx->fBuffer[slot] = incoming; ++xx->fBufferPos; } else { xx->fBufferPos = 0; xx->fSkipping = true; } } else if (kSpaceballResponseEndCommand == incoming) { if (xx->fSkipping) { xx->fSkipping = false; } else if (0 < xx->fBufferPos) { spaceballProcessPacket(xx); } xx->fBufferPos = 0; } else if (kSpaceballResponseNewLine == incoming) { if (! xx->fSkipping) { if (slot) { if (IN_BUFFER_SIZE > slot) { xx->fBuffer[slot] = incoming; ++xx->fBufferPos; } else { xx->fBufferPos = 0; xx->fSkipping = true; } } } } else if (kSpaceballResponseXoff == incoming) { xx->fOutputBlocked = true; } else if (kSpaceballResponseXon == incoming) { xx->fOutputBlocked = false; } else if (kSpaceballResponseEscape == incoming) { if (! xx->fSkipping) { xx->fNextCharEscaped = true; } } else if (! xx->fSkipping) { if (IN_BUFFER_SIZE > slot) { xx->fBuffer[slot] = incoming; ++xx->fBufferPos; } else { xx->fBufferPos = 0; xx->fSkipping = true; } } lockout_set(prevLock); } } // spaceballProcessResponse