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

5
Last change on this file since af9115f3 was af9115f3, checked in by Sebastian Huber <sebastian.huber@…>, on 10/06/17 at 08:07:38

posix: Simplify POSIX_API_Control

Return stack area via pthread_getattr_np().

Simplify

  • pthread_attr_setaffinity_np(), and
  • pthread_attr_getaffinity_np()

and let the scheduler do the more sophisticated error checks.

Make

  • pthread_setaffinity_np(),
  • pthread_getaffinity_np(),
  • pthread_attr_setaffinity_np(), and
  • pthread_attr_getaffinity_np()

available in all configurations.

Update #2514.
Close #3145.
Close #3168.

  • Property mode set to 100644
File size: 2.0 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/score/schedulerimpl.h>
28#include <rtems/score/threadimpl.h>
29
30int pthread_getattr_np(
31  pthread_t       thread,
32  pthread_attr_t *attr
33)
34{
35  Thread_Control    *the_thread;
36  ISR_lock_Context   lock_context;
37  POSIX_API_Control *api;
38  bool               ok;
39
40  if ( attr == NULL ) {
41    return EINVAL;
42  }
43
44  attr = memset( attr, 0, sizeof( *attr ) );
45
46  the_thread = _Thread_Get( thread, &lock_context );
47
48  if ( the_thread == NULL ) {
49    return ESRCH;
50  }
51
52  _Thread_State_acquire_critical( the_thread, &lock_context );
53
54  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
55
56  attr->is_initialized = true;
57  attr->stackaddr = the_thread->Start.Initial_stack.area;
58  attr->stacksize = the_thread->Start.Initial_stack.size;
59  attr->contentionscope = PTHREAD_SCOPE_PROCESS;
60
61  if ( api->created_with_explicit_scheduler ) {
62    attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
63  } else {
64    attr->inheritsched = PTHREAD_INHERIT_SCHED;
65  }
66
67  attr->schedpolicy = api->schedpolicy;
68  attr->schedparam = api->schedparam;
69  attr->cputime_clock_allowed = 1;
70
71  if ( _Thread_Is_joinable( the_thread ) ) {
72    attr->detachstate = PTHREAD_CREATE_JOINABLE;
73  } else {
74    attr->detachstate = PTHREAD_CREATE_DETACHED;
75  }
76
77  attr->affinityset = &attr->affinitysetpreallocated;
78  attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
79  ok = _Scheduler_Get_affinity(
80    the_thread,
81    attr->affinitysetsize,
82    attr->affinityset
83  );
84
85  _Thread_State_release( the_thread, &lock_context );
86  return ok ? 0 : EINVAL;
87}
Note: See TracBrowser for help on using the repository browser.