source: rtems/cpukit/posix/src/pthreadgetattrnp.c @ c0d602e

5
Last change on this file since c0d602e was c0d602e, checked in by Sebastian Huber <sebastian.huber@…>, on 11/21/17 at 05:19:25

posix: _POSIX_Threads_Get_sched_param_sporadic()

Remove api parameter to simplify the calling functions.

Update #2514.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Pthread Get Attribute
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#define  _GNU_SOURCE
22#include <pthread.h>
23#include <errno.h>
24#include <string.h>
25
26#include <rtems/posix/pthreadimpl.h>
27#include <rtems/posix/pthreadattrimpl.h>
28#include <rtems/posix/priorityimpl.h>
29#include <rtems/score/schedulerimpl.h>
30#include <rtems/score/threadimpl.h>
31
32int pthread_getattr_np(
33  pthread_t       thread,
34  pthread_attr_t *attr
35)
36{
37  Thread_Control               *the_thread;
38  ISR_lock_Context              lock_context;
39  Thread_CPU_budget_algorithms  budget_algorithm;
40  const Scheduler_Control      *scheduler;
41  bool                          ok;
42
43  if ( attr == NULL ) {
44    return EINVAL;
45  }
46
47  attr = memset( attr, 0, sizeof( *attr ) );
48
49  the_thread = _Thread_Get( thread, &lock_context );
50
51  if ( the_thread == NULL ) {
52    return ESRCH;
53  }
54
55  _Thread_State_acquire_critical( the_thread, &lock_context );
56
57  attr->stackaddr = the_thread->Start.Initial_stack.area;
58  attr->stacksize = the_thread->Start.Initial_stack.size;
59
60  if ( the_thread->was_created_with_inherited_scheduler ) {
61    attr->inheritsched = PTHREAD_INHERIT_SCHED;
62  } else {
63    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
64  }
65
66  scheduler = _Thread_Scheduler_get_home( the_thread );
67  attr->schedparam.sched_priority = _POSIX_Priority_From_core(
68    scheduler,
69    _Thread_Get_priority( the_thread )
70  );
71  _POSIX_Threads_Get_sched_param_sporadic(
72    the_thread,
73    scheduler,
74    &attr->schedparam
75  );
76
77  if ( _Thread_Is_joinable( the_thread ) ) {
78    attr->detachstate = PTHREAD_CREATE_JOINABLE;
79  } else {
80    attr->detachstate = PTHREAD_CREATE_DETACHED;
81  }
82
83  attr->affinityset = &attr->affinitysetpreallocated;
84  attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
85  ok = _Scheduler_Get_affinity(
86    the_thread,
87    attr->affinitysetsize,
88    attr->affinityset
89  );
90
91  budget_algorithm = the_thread->budget_algorithm;
92
93  _Thread_State_release( the_thread, &lock_context );
94
95  attr->is_initialized = true;
96  attr->contentionscope = PTHREAD_SCOPE_PROCESS;
97  attr->cputime_clock_allowed = 1;
98  attr->schedpolicy =
99    _POSIX_Thread_Translate_to_sched_policy( budget_algorithm );
100
101  return ok ? 0 : EINVAL;
102}
Note: See TracBrowser for help on using the repository browser.