/* Allocate a thread structure from the global free list.  Global
   mutex lock must be held by caller.  The thread is moved to
   the active list. */
struct thread_node *
__timer_thread_alloc (const pthread_attr_t *desired_attr, clockid_t clock_id)
{
  struct list_links *node = list_first (&thread_free_list);

  if (node != list_null (&thread_free_list))
    {
      struct thread_node *thread = thread_links2ptr (node);
      list_unlink (node);
      thread_init (thread, desired_attr, clock_id);
      list_append (&thread_active_list, node);
      return thread;
    }

  return 0;
}
Beispiel #2
0
/* Search the list of active threads and find one which has matching
   attributes.  Global mutex lock must be held by caller.  */
struct thread_node *
__timer_thread_find_matching (const pthread_attr_t *desired_attr,
			      clockid_t desired_clock_id)
{
  struct list_head *iter = list_first (&thread_active_list);

  while (iter != list_null (&thread_active_list))
    {
      struct thread_node *candidate = thread_links2ptr (iter);

      if (thread_attr_compare (desired_attr, &candidate->attr)
	  && desired_clock_id == candidate->clock_id)
	return candidate;

      iter = list_next (iter);
    }

  return NULL;
}