| 34 | } |
| 35 | |
| 36 | void ProfilingStateMachine::TransitionToState(ProfilingState newState) |
| 37 | { |
| 38 | ProfilingState currentState = m_State.load(std::memory_order::memory_order_relaxed); |
| 39 | |
| 40 | switch (newState) |
| 41 | { |
| 42 | case ProfilingState::Uninitialised: |
| 43 | do |
| 44 | { |
| 45 | if (!IsOneOfStates(currentState, ProfilingState::Uninitialised)) |
| 46 | { |
| 47 | ThrowStateTransitionException(currentState, newState); |
| 48 | } |
| 49 | } |
| 50 | while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed)); |
| 51 | break; |
| 52 | case ProfilingState::NotConnected: |
| 53 | do |
| 54 | { |
| 55 | if (!IsOneOfStates(currentState, ProfilingState::Uninitialised, ProfilingState::NotConnected, |
| 56 | ProfilingState::Active, ProfilingState::WaitingForAck)) |
| 57 | { |
| 58 | ThrowStateTransitionException(currentState, newState); |
| 59 | } |
| 60 | } |
| 61 | while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed)); |
| 62 | break; |
| 63 | case ProfilingState::WaitingForAck: |
| 64 | do |
| 65 | { |
| 66 | if (!IsOneOfStates(currentState, ProfilingState::NotConnected, ProfilingState::WaitingForAck)) |
| 67 | { |
| 68 | ThrowStateTransitionException(currentState, newState); |
| 69 | } |
| 70 | } |
| 71 | while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed)); |
| 72 | break; |
| 73 | case ProfilingState::Active: |
| 74 | do |
| 75 | { |
| 76 | if (!IsOneOfStates(currentState, ProfilingState::WaitingForAck, ProfilingState::Active)) |
| 77 | { |
| 78 | ThrowStateTransitionException(currentState, newState); |
| 79 | } |
| 80 | } |
| 81 | while (!m_State.compare_exchange_strong(currentState, newState, std::memory_order::memory_order_relaxed)); |
| 82 | break; |
| 83 | default: |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void ProfilingStateMachine::Reset() |
| 89 | { |