int TryEnterDebugSection(void) { if(AtomicCompareExchange( &debug_state, DEBUG_FREE, DEBUG_BUSY) == DEBUG_FREE){ if(__DEBUG){ return 1; } AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); } return 0; }
void testAtomicOps() { volatile esint32 key = 0; EAssert(AtomicIncrement(&key) == 1, "key != 1"); EAssert(AtomicDecrement(&key) == 0, "key != 0"); AtomicCompareExchange(1, 0, &key); EAssert(AtomicIncrement(&key) == 2, "key != 2"); }
int TryLockPython(void) { return AtomicCompareExchange( &python_state, PYTHON_FREE, PYTHON_BUSY) == PYTHON_FREE; }
int suspendDebug(int disable) { char cmd = DEBUG_UNLOCK; if (PLC_shutdown) return -1; while(AtomicCompareExchange( &debug_state, DEBUG_FREE, DEBUG_BUSY) != DEBUG_FREE && cmd == DEBUG_UNLOCK){ if(read(Debug_pipe_fd, &cmd, sizeof(cmd)) != sizeof(cmd)){ return -1; } } __DEBUG = !disable; if (disable) AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); return 0; }
void LeaveDebugSection(void) { if(AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE) == DEBUG_BUSY){ char msg = DEBUG_UNLOCK; /* signal to NRT for wakeup */ rt_pipe_write(&Debug_pipe, &msg, sizeof(msg), P_NORMAL); } }
void UnLockPython(void) { if(AtomicCompareExchange( &python_state, PYTHON_BUSY, PYTHON_FREE) == PYTHON_BUSY){ if(rt_task_self()){/*is that the real time task ?*/ char cmd = UNLOCK_PYTHON; rt_pipe_write(&Python_pipe, &cmd, sizeof(cmd), P_NORMAL); }/* otherwise, no signaling from non real time */ } /* as plc does not wait for lock. */ }
void LockPython(void) { char cmd = UNLOCK_PYTHON; if (PLC_shutdown) return; while(AtomicCompareExchange( &python_state, PYTHON_FREE, PYTHON_BUSY) != PYTHON_FREE && cmd == UNLOCK_PYTHON){ read(Python_pipe_fd, &cmd, sizeof(cmd)); } }
void OpenSLPlayer::pause() { lock(); accessTime = currentTimeMillis(); if (player == NULL) { unlock(); return; } AtomicCompareExchange(&state, SL_PLAYSTATE_PAUSED, SL_PLAYSTATE_PLAYING); //SLresult result; /*result = */(*player)->SetPlayState(player, SL_PLAYSTATE_PAUSED); unlock(); }
void resumeDebug(void) { AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE); }