AzureMXChip/MXCHIPAZ3166/core/lib/threadx/ports_smp/linux/gnu/src/tx_thread_schedule.c
void _tx_linux_mutex_obtain(TX_LINUX_MUTEX *mutex)
{

TX_THREAD       *thread_ptr;
pthread_t       current_thread_id;
UINT            i;

    /* Pickup the current thread ID.  */
    current_thread_id =  pthread_self();

    /* Is the protection owned?  */
    if (mutex -> tx_linux_mutex_owner == current_thread_id)
    {

        /* Simply increment the nested counter.  */
        mutex -> tx_linux_mutex_nested_count++;
    }
    else
    {

        /* Loop to find a thread matching this ID.  */
        i =  0;
        do
        {

            /* Pickup the thread pointer.  */
            thread_ptr =  _tx_thread_current_ptr[i];

            /* Is this thread obtaining the mutex?  */
            if ((thread_ptr) && (thread_ptr -> tx_thread_linux_thread_id == current_thread_id))
            {

                /* We have found the thread, get out of the loop.  */
                break;
            }

            /* Look at next core.  */
            i++;

        } while (i < TX_THREAD_SMP_MAX_CORES);

        /* Determine if we found a thread.  */
        if (i >= TX_THREAD_SMP_MAX_CORES)
        {

            /* Set the thread pointer to NULL to indicate a thread was not found.  */
            thread_ptr =  TX_NULL;
        }

        /* If a thread was found, indicate the thread is attempting to access the mutex.  */
        if (thread_ptr)
        {

            /* Yes, current ThreadX thread attempting to get the mutex - set the flag.  */
            thread_ptr -> tx_thread_linux_mutex_access =  TX_TRUE;
        }

        /* Get the Linux mutex.  */
        pthread_mutex_lock(&mutex -> tx_linux_mutex);

        /* At this point we have the mutex.  */

        /* Clear the mutex access flag for the thread.  */
        if (thread_ptr)
        {

            /* Yes, clear the current ThreadX thread attempting to get the mutex.  */
            thread_ptr -> tx_thread_linux_mutex_access =  TX_FALSE;
        }

        /* Increment the nesting counter.  */
        mutex -> tx_linux_mutex_nested_count =  1;

        /* Remember the owner.  */
        mutex -> tx_linux_mutex_owner = pthread_self();
    }
}
/* Define the ThreadX Linux mutex get, release, and release all functions.  */
Define the ThreadX Linux mutex get, release, and release all functions.
Define the ThreadX Linux mutex get release and release all functions .
void _tx_linux_mutex_obtain(TX_LINUX_MUTEX *mutex)
{
TX_THREAD       *thread_ptr;
pthread_t       current_thread_id;
UINT            i;
    current_thread_id =  pthread_self();
    if (mutex -> tx_linux_mutex_owner == current_thread_id)
    {
        mutex -> tx_linux_mutex_nested_count++;
    }
    else
    {
        i =  0;
        do
        {
            thread_ptr =  _tx_thread_current_ptr[i];
            if ((thread_ptr) && (thread_ptr -> tx_thread_linux_thread_id == current_thread_id))
            {
                break;
            }
            i++;
        } while (i < TX_THREAD_SMP_MAX_CORES);
        if (i >= TX_THREAD_SMP_MAX_CORES)
        {
            thread_ptr =  TX_NULL;
        }
        if (thread_ptr)
        {
            thread_ptr -> tx_thread_linux_mutex_access =  TX_TRUE;
        }
        pthread_mutex_lock(&mutex -> tx_linux_mutex);
        if (thread_ptr)
        {
            thread_ptr -> tx_thread_linux_mutex_access =  TX_FALSE;
        }
        mutex -> tx_linux_mutex_nested_count =  1;
        mutex -> tx_linux_mutex_owner = pthread_self();
    }
}
void _tx_linux_mutex_obtain ( TX_LINUX_MUTEX * mutex ) { TX_THREAD * thread_ptr ; pthread_t current_thread_id ; UINT i ; current_thread_id = pthread_self ( ) ; if ( mutex -> tx_linux_mutex_owner == current_thread_id ) { mutex -> tx_linux_mutex_nested_count ++ ; } else { i = 0 ; do { thread_ptr = _tx_thread_current_ptr [ i ] ; if ( ( thread_ptr ) && ( thread_ptr -> tx_thread_linux_thread_id == current_thread_id ) ) { break ; } i ++ ; } while ( i < TX_THREAD_SMP_MAX_CORES ) ; if ( i >= TX_THREAD_SMP_MAX_CORES ) { thread_ptr = TX_NULL ; } if ( thread_ptr ) { thread_ptr -> tx_thread_linux_mutex_access = TX_TRUE ; } pthread_mutex_lock ( & mutex -> tx_linux_mutex ) ; if ( thread_ptr ) { thread_ptr -> tx_thread_linux_mutex_access = TX_FALSE ; } mutex -> tx_linux_mutex_nested_count = 1 ; mutex -> tx_linux_mutex_owner = pthread_self ( ) ; } }
Define the ThreadX Linux mutex get, release, and release all functions.
Define the ThreadX Linux mutex get release and release all functions .
/* Pickup the current thread ID.  */ /* Is the protection owned?  */ /* Simply increment the nested counter.  */ /* Loop to find a thread matching this ID.  */ /* Pickup the thread pointer.  */ /* Is this thread obtaining the mutex?  */ /* We have found the thread, get out of the loop.  */ /* Look at next core.  */ /* Determine if we found a thread.  */ /* Set the thread pointer to NULL to indicate a thread was not found.  */ /* If a thread was found, indicate the thread is attempting to access the mutex.  */ /* Yes, current ThreadX thread attempting to get the mutex - set the flag.  */ /* Get the Linux mutex.  */ /* At this point we have the mutex.  */ /* Clear the mutex access flag for the thread.  */ /* Yes, clear the current ThreadX thread attempting to get the mutex.  */ /* Increment the nesting counter.  */ /* Remember the owner.  */