Exemplo n.º 1
0
int pthread_mutex_getprioceiling(
    pthread_mutex_t   *mutex,
    int               *prioceiling
)
{
    register POSIX_Mutex_Control *the_mutex;
    Objects_Locations             location;

    if ( !prioceiling )
        return EINVAL;

    the_mutex = _POSIX_Mutex_Get( mutex, &location );
    switch ( location ) {

    case OBJECTS_LOCAL:
        *prioceiling = _POSIX_Priority_From_core(
                           the_mutex->Mutex.Attributes.priority_ceiling
                       );
        _Thread_Enable_dispatch();
        return 0;

#if defined(RTEMS_MULTIPROCESSING)
    case OBJECTS_REMOTE:
#endif
    case OBJECTS_ERROR:
        break;
    }

    return EINVAL;
}
int pthread_mutex_setprioceiling(
  pthread_mutex_t   *mutex,
  int                prioceiling,
  int               *old_ceiling
)
{
  register POSIX_Mutex_Control *the_mutex;
  Objects_Locations             location;
  Priority_Control              the_priority;
  int                           status;

  if ( !old_ceiling )
    return EINVAL;

  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
    return EINVAL;

  the_priority = _POSIX_Priority_To_core( prioceiling );

  /*
   *  Must acquire the mutex before we can change it's ceiling
   */

  status = pthread_mutex_lock( mutex );
  if ( status )
    return status;

  the_mutex = _POSIX_Mutex_Get( mutex, &location );
  switch ( location ) {
    case OBJECTS_REMOTE:
#if defined(RTEMS_MULTIPROCESSING)
      /*  XXX It feels questionable to set the ceiling on a remote mutex. */
      return EINVAL;
#endif
    case OBJECTS_ERROR:
      return EINVAL;        /* impossible to get here */
    case OBJECTS_LOCAL:
      *old_ceiling = _POSIX_Priority_From_core(
        the_mutex->Mutex.Attributes.priority_ceiling
      );
      the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
      _CORE_mutex_Surrender(
        &the_mutex->Mutex,
        the_mutex->Object.id,
#if defined(RTEMS_MULTIPROCESSING)
        _POSIX_Threads_mutex_MP_support
#else
        NULL
#endif
      );
      _Thread_Enable_dispatch();
      return 0;
  }
  return POSIX_BOTTOM_REACHED();
}
Exemplo n.º 3
0
int pthread_mutex_setprioceiling(
  pthread_mutex_t   *mutex,
  int                prioceiling,
  int               *old_ceiling
)
{
  register POSIX_Mutex_Control *the_mutex;
  Priority_Control              the_priority;
  ISR_lock_Context              lock_context;

  if ( !old_ceiling )
    return EINVAL;

  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
    return EINVAL;

  the_priority = _POSIX_Priority_To_core( prioceiling );

  /*
   *  Must acquire the mutex before we can change it's ceiling.
   *  POSIX says block until we acquire it.
   */
  (void) pthread_mutex_lock( mutex );

  /*
   *  Do not worry about the return code from this.  The Get operation
   *  will also fail if it is a bad id or was deleted between the two
   *  operations.
   *
   *  NOTE: This makes it easier to get 100% binary coverage since the
   *        bad Id case is handled by the switch.
   */
  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );

  if ( the_mutex == NULL ) {
    return EINVAL;
  }

  *old_ceiling = _POSIX_Priority_From_core(
    the_mutex->Mutex.Attributes.priority_ceiling
  );
  the_mutex->Mutex.Attributes.priority_ceiling = the_priority;

  /*
   *  We are required to unlock the mutex before we return.
   */
  _CORE_mutex_Surrender(
    &the_mutex->Mutex,
    NULL,
    0,
    &lock_context
  );
  return 0;
}
Exemplo n.º 4
0
int pthread_getschedparam(
    pthread_t           thread,
    int                *policy,
    struct sched_param *param
)
{
    Objects_Locations        location;
    POSIX_API_Control       *api;
    register Thread_Control *the_thread;

    if ( !policy || !param  )
        return EINVAL;

    the_thread = _Thread_Get( thread, &location );
    switch ( location ) {

    case OBJECTS_LOCAL:
        api = the_thread->API_Extensions[ THREAD_API_POSIX ];
        if ( policy )
            *policy = api->schedpolicy;
        if ( param ) {
            *param  = api->schedparam;
            param->sched_priority =
                _POSIX_Priority_From_core( the_thread->current_priority );
        }
        _Objects_Put( &the_thread->Object );
        return 0;

#if defined(RTEMS_MULTIPROCESSING)
    case OBJECTS_REMOTE:
#endif
    case OBJECTS_ERROR:
        break;
    }

    return ESRCH;

}
Exemplo n.º 5
0
int pthread_getschedparam(
  pthread_t           thread,
  int                *policy,
  struct sched_param *param
)
{
  Thread_Control          *the_thread;
  Thread_queue_Context     queue_context;
  POSIX_API_Control       *api;
  const Scheduler_Control *scheduler;
  Priority_Control         priority;

  if ( policy == NULL || param == NULL ) {
    return EINVAL;
  }

  the_thread = _Thread_Get( thread, &queue_context.Lock_context );

  if ( the_thread == NULL ) {
    return ESRCH;
  }

  api = the_thread->API_Extensions[ THREAD_API_POSIX ];

  _Thread_Wait_acquire_critical( the_thread, &queue_context );

  *policy = api->Attributes.schedpolicy;
  *param  = api->Attributes.schedparam;

  scheduler = _Scheduler_Get_own( the_thread );
  priority = the_thread->real_priority;

  _Thread_Wait_release( the_thread, &queue_context );

  param->sched_priority = _POSIX_Priority_From_core( scheduler, priority );
  return 0;
}
Exemplo n.º 6
0
int pthread_mutex_setprioceiling(
  pthread_mutex_t   *mutex,
  int                prioceiling,
  int               *old_ceiling
)
{
  register POSIX_Mutex_Control *the_mutex;
  Objects_Locations             location;
  Priority_Control              the_priority;
  ISR_lock_Context              lock_context;

  if ( !old_ceiling )
    return EINVAL;

  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
    return EINVAL;

  the_priority = _POSIX_Priority_To_core( prioceiling );

  /*
   *  Must acquire the mutex before we can change it's ceiling.
   *  POSIX says block until we acquire it.
   */
  (void) pthread_mutex_lock( mutex );

  /*
   *  Do not worry about the return code from this.  The Get operation
   *  will also fail if it is a bad id or was deleted between the two
   *  operations.
   *
   *  NOTE: This makes it easier to get 100% binary coverage since the
   *        bad Id case is handled by the switch.
   */
  the_mutex = _POSIX_Mutex_Get_interrupt_disable(
    mutex,
    &location,
    &lock_context
  );
  switch ( location ) {

    case OBJECTS_LOCAL:
      *old_ceiling = _POSIX_Priority_From_core(
        the_mutex->Mutex.Attributes.priority_ceiling
      );
      the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
      /*
       *  We are required to unlock the mutex before we return.
       */
      _CORE_mutex_Surrender(
        &the_mutex->Mutex,
        the_mutex->Object.id,
        NULL,
        &lock_context
      );

      return 0;

#if defined(RTEMS_MULTIPROCESSING)
    case OBJECTS_REMOTE:  /* impossible to get here */
#endif
    case OBJECTS_ERROR:
      break;
  }

  return EINVAL;
}
Exemplo n.º 7
0
    Thread_Control *executing RTEMS_UNUSED,
    Thread_Control *created
)
{
    POSIX_API_Control *api;
    POSIX_API_Control *executing_api;

    api = created->API_Extensions[ THREAD_API_POSIX ];

    /* XXX check all fields are touched */
    _POSIX_Threads_Initialize_attributes( &api->Attributes );
    api->detachstate = _POSIX_Threads_Default_attributes.detachstate;
    api->schedpolicy = _POSIX_Threads_Default_attributes.schedpolicy;
    api->schedparam  = _POSIX_Threads_Default_attributes.schedparam;
    api->schedparam.sched_priority =
        _POSIX_Priority_From_core( created->current_priority );

    /*
     *  POSIX 1003.1 1996, 18.2.2.2
     */
    api->cancelation_requested = 0;
    api->cancelability_state = PTHREAD_CANCEL_ENABLE;
    api->cancelability_type = PTHREAD_CANCEL_DEFERRED;
#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT
    _Chain_Initialize_empty (&api->Cancellation_Handlers);
#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */
    api->last_cleanup_context = NULL;
#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */

    /*
     *  If the thread is not a posix thread, then all posix signals are blocked