MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _futex_requeue

Function _futex_requeue

components/lwp/lwp_futex.c:666–731  ·  view source on GitHub ↗

* @brief Requeue threads from one futex waiting list to another * * @param[in] futex1 Source futex containing threads to wake/requeue * @param[in] futex2 Destination futex for requeued threads * @param[in] lwp Lightweight process structure * @param[in] nr_wake Maximum number of threads to wake from futex1 * @param[in] nr_requeue Maximum number of threads to requeue to futex2 * @param[in] op

Source from the content-addressed store, hash-verified

664 * on futex1 into the waiting queue of futex2.
665 */
666static long _futex_requeue(rt_futex_t futex1, rt_futex_t futex2,
667 struct rt_lwp *lwp, int nr_wake, int nr_requeue,
668 int opflags)
669{
670 long rtn;
671 long woken_cnt = 0;
672 int is_empty = 0;
673 rt_thread_t thread;
674
675 if (futex1 == futex2)
676 {
677 return -EINVAL;
678 }
679
680 /**
681 * Brief: Wakeup a suspended thread on the futex waiting thread list
682 *
683 * Note: Critical Section
684 * - the futex waiting_thread list (RW)
685 */
686 while (nr_wake && !is_empty)
687 {
688 if (rt_susp_list_dequeue(&futex1->waiting_thread, RT_EOK))
689 {
690 nr_wake--;
691 woken_cnt++;
692 is_empty = RT_FALSE;
693 }
694 else
695 {
696 is_empty = RT_TRUE;
697 }
698 }
699 rtn = woken_cnt;
700
701 /**
702 * Brief: Requeue
703 *
704 * Note: Critical Section
705 * - the futex waiting_thread list (RW)
706 */
707 while (!is_empty && nr_requeue)
708 {
709 rt_sched_lock_level_t slvl;
710 rt_sched_lock(&slvl);
711
712 /* moving from one susp list to another */
713 is_empty = rt_list_isempty(&(futex1->waiting_thread));
714
715 if (!is_empty)
716 {
717 thread = RT_THREAD_LIST_NODE_ENTRY(futex1->waiting_thread.next);
718 rt_list_remove(&RT_THREAD_LIST_NODE(thread));
719 rt_list_insert_before(&(futex2->waiting_thread),
720 &RT_THREAD_LIST_NODE(thread));
721 nr_requeue--;
722 rtn++;
723 }

Callers 1

lwp_futexFunction · 0.85

Calls 7

rt_susp_list_dequeueFunction · 0.85
rt_list_isemptyFunction · 0.85
rt_list_removeFunction · 0.85
rt_list_insert_beforeFunction · 0.85
rt_sched_lockFunction · 0.50
rt_sched_unlockFunction · 0.50
rt_scheduleFunction · 0.50

Tested by

no test coverage detected