Menu

#197 Problems with scheduler locking in QP/C/C++ ports to ThreadX

QP
closed
None
1
2024-08-01
2018-01-09
No

The QFSchedLock_() implementation in the QP/C/C++ port to ThreadX might change thread preemption threshold with lower priority than the one of the thread itself. This causes an error in ThreadX and assertion in the QP port.
--MMS

Discussion

  • Quantum Leaps

    Quantum Leaps - 2018-01-16
    • status: open --> closed
     
  • Quantum Leaps

    Quantum Leaps - 2018-01-16

    Fixed in QP/C/C++ 6.0.4. The selective scheduler locking for ThreadX is implemented as follows:

    void QFSchedLock_(QFSchedLock * const lockStat, uint_fast8_t prio) {
        UINT tx_err;
    
        lockStat->lockHolder = tx_thread_identify();
    
        /* this must be thread level, so current TX thread must be valid */
        Q_REQUIRE_ID(800, lockStat->lockHolder != (TX_THREAD *)0);
    
        /* change the preemption threshold of the current thread */
        tx_err = tx_thread_preemption_change(lockStat->lockHolder,
                         (QF_TX_PRIO_OFFSET + QF_MAX_ACTIVE - prio),
                         &lockStat->prevThre);
    
        if (tx_err == TX_SUCCESS) {
            QS_CRIT_STAT_
            lockStat->lockPrio = prio;
            . . .
        }
        else if (tx_err == TX_THRESH_ERROR) {
            /* threshold was greater than (lower prio) than the current prio */
            lockStat->lockPrio = (uint_fast8_t)0; /* threshold not changed */
        }
        else {
            /* no other errors are tolerated */
            Q_ERROR_ID(810);
        }
    }
    
     

Anonymous
Anonymous

Add attachments
Cancel