1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_sync_threadx: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker=============== 4*61c4878aSAndroid Build Coastguard Workerpw_sync_threadx 5*61c4878aSAndroid Build Coastguard Worker=============== 6*61c4878aSAndroid Build Coastguard WorkerThis is a set of backends for pw_sync based on ThreadX. 7*61c4878aSAndroid Build Coastguard Worker 8*61c4878aSAndroid Build Coastguard WorkerIt is possible, if necessary, to use pw_sync_threadx without using the Pigweed 9*61c4878aSAndroid Build Coastguard Workerprovided pw_chrono_threadx in case the ThreadX time API (``tx_time_get()``)) is 10*61c4878aSAndroid Build Coastguard Workernot available (i.e. ``TX_NO_TIMER`` is set). You are responsible for ensuring 11*61c4878aSAndroid Build Coastguard Workerthat the chrono backend provided has counts which match the ThreadX tick based 12*61c4878aSAndroid Build Coastguard WorkerAPI. 13*61c4878aSAndroid Build Coastguard Worker 14*61c4878aSAndroid Build Coastguard Worker-------------------------------- 15*61c4878aSAndroid Build Coastguard WorkerCritical Section Lock Primitives 16*61c4878aSAndroid Build Coastguard Worker-------------------------------- 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard WorkerMutex & TimedMutex 19*61c4878aSAndroid Build Coastguard Worker================== 20*61c4878aSAndroid Build Coastguard WorkerThe ThreadX backend for the Mutex and TimedMutex use ``TX_MUTEX`` as the 21*61c4878aSAndroid Build Coastguard Workerunderlying type. It is created using ``tx_mutex_create`` as part of the 22*61c4878aSAndroid Build Coastguard Workerconstructors and cleaned up using ``tx_mutex_delete`` in the destructors. 23*61c4878aSAndroid Build Coastguard Worker 24*61c4878aSAndroid Build Coastguard WorkerInterruptSpinLock 25*61c4878aSAndroid Build Coastguard Worker================= 26*61c4878aSAndroid Build Coastguard WorkerThe ThreadX backend for InterruptSpinLock is backed by an ``enum class`` and 27*61c4878aSAndroid Build Coastguard Workertwo ``UINT`` which permits these objects to detect accidental recursive locking 28*61c4878aSAndroid Build Coastguard Workerand unlocking contexts. 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard WorkerThis object uses ``tx_interrupt_control`` to enable critical sections. In 31*61c4878aSAndroid Build Coastguard Workeraddition, ``tx_thread_preemption_change`` is used to prevent accidental thread 32*61c4878aSAndroid Build Coastguard Workercontext switches while the InterruptSpinLock is held by a thread. 33*61c4878aSAndroid Build Coastguard Worker 34*61c4878aSAndroid Build Coastguard Worker.. Warning:: 35*61c4878aSAndroid Build Coastguard Worker This backend does not support SMP yet as there's no internal lock to spin on. 36*61c4878aSAndroid Build Coastguard Worker 37*61c4878aSAndroid Build Coastguard Worker-------------------- 38*61c4878aSAndroid Build Coastguard WorkerSignaling Primitives 39*61c4878aSAndroid Build Coastguard Worker-------------------- 40*61c4878aSAndroid Build Coastguard Worker 41*61c4878aSAndroid Build Coastguard WorkerThreadNotification & TimedThreadNotification 42*61c4878aSAndroid Build Coastguard Worker============================================ 43*61c4878aSAndroid Build Coastguard WorkerPrefer using the binary semaphore backends for ThreadNotifications as 44*61c4878aSAndroid Build Coastguard Workerthe native ThreadX API covers direct thread signaling: 45*61c4878aSAndroid Build Coastguard Worker 46*61c4878aSAndroid Build Coastguard Worker- ``pw_sync:binary_semaphore_thread_notification_backend`` 47*61c4878aSAndroid Build Coastguard Worker- ``pw_sync:binary_semaphore_timed_thread_notification_backend`` 48*61c4878aSAndroid Build Coastguard Worker 49*61c4878aSAndroid Build Coastguard WorkerBackground Information 50*61c4878aSAndroid Build Coastguard Worker---------------------- 51*61c4878aSAndroid Build Coastguard WorkerAlthough one may be tempted to use ``tx_thread_sleep`` and 52*61c4878aSAndroid Build Coastguard Worker``tx_thread_wait_abort`` to implement direct thread notifications with ThreadX, 53*61c4878aSAndroid Build Coastguard Workerthis unfortunately cannot work. Between the blocking thread setting its 54*61c4878aSAndroid Build Coastguard Worker``TX_THREAD*`` handle and actually executing ``tx_thread_sleep`` there will 55*61c4878aSAndroid Build Coastguard Workeralways exist a race condition. Another thread and/or interrupt may attempt 56*61c4878aSAndroid Build Coastguard Workerto invoke ``tx_thread_wait_abort`` before the blocking thread has executed 57*61c4878aSAndroid Build Coastguard Worker``tx_thread_sleep`` meaning the wait abort would fail. 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard WorkerBinarySemaphore & CountingSemaphore 60*61c4878aSAndroid Build Coastguard Worker=================================== 61*61c4878aSAndroid Build Coastguard WorkerThe ThreadX backends for the BinarySemaphore and CountingSemaphore use 62*61c4878aSAndroid Build Coastguard Worker``TX_SEMAPHORE`` as the underlying type. It is created using 63*61c4878aSAndroid Build Coastguard Worker``tx_semaphore_create`` as part of the constructor and cleaned up using 64*61c4878aSAndroid Build Coastguard Worker``tx_semaphore_delete`` in the destructor. 65