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

5
Last change on this file since dbb30e26 was 3f3f4248, checked in by Sebastian Huber <sebastian.huber@…>, on 10/17/17 at 07:20:20

posix: Remove POSIX_API_Control::schedparam

Move sporadic server scheduler parameters to
POSIX_API_Control::Sporadic. Remove redundant scheduler priority
parameter.

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  POSIX_API_Control       *api;
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  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
58
59  attr->is_initialized = true;
60  attr->stackaddr = the_thread->Start.Initial_stack.area;
61  attr->stacksize = the_thread->Start.Initial_stack.size;
62  attr->contentionscope = PTHREAD_SCOPE_PROCESS;
63
64  if ( api->created_with_explicit_scheduler ) {
65    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
66  } else {
67    attr->inheritsched = PTHREAD_INHERIT_SCHED;
68  }
69
70  attr->schedpolicy = api->schedpolicy;
71
72  scheduler = _Thread_Scheduler_get_home( the_thread );
73  attr->schedparam.sched_priority = _POSIX_Priority_From_core(
74    scheduler,
75    _Thread_Get_priority( the_thread )
76  );
77  _POSIX_Threads_Get_sched_param_sporadic(
78    the_thread,
79    api,
80    scheduler,
81    &attr->schedparam
82  );
83  attr->cputime_clock_allowed = 1;
84
85  if ( _Thread_Is_joinable( the_thread ) ) {
86    attr->detachstate = PTHREAD_CREATE_JOINABLE;
87  } else {
88    attr->detachstate = PTHREAD_CREATE_DETACHED;
89  }
90
91  attr->affinityset = &attr->affinitysetpreallocated;
92  attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
93  ok = _Scheduler_Get_affinity(
94    the_thread,
95    attr->affinitysetsize,
96    attr->affinityset
97  );
98
99  _Thread_State_release( the_thread, &lock_context );
100  return ok ? 0 : EINVAL;
101}
Note: See TracBrowser for help on using the repository browser.