Ejemplo n.º 1
0
rtems_status_code rtems_semaphore_obtain(
  rtems_id        id,
  rtems_option    option_set,
  rtems_interval  timeout
)
{
  register Semaphore_Control     *the_semaphore;
  Objects_Locations               location;
  ISR_Level                       level;
  Thread_Control                 *executing;

  the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
  switch ( location ) {

    case OBJECTS_LOCAL:
      executing = _Thread_Executing;
      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
        _CORE_mutex_Seize(
          &the_semaphore->Core_control.mutex,
          executing,
          id,
          ((_Options_Is_no_wait( option_set )) ? false : true),
          timeout,
          level
        );
        _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
        return _Semaphore_Translate_core_mutex_return_code(
                  executing->Wait.return_code );
      }

      /* must be a counting semaphore */
      _CORE_semaphore_Seize_isr_disable(
        &the_semaphore->Core_control.semaphore,
        executing,
        id,
        ((_Options_Is_no_wait( option_set )) ? false : true),
        timeout,
        level
      );
      _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
      return _Semaphore_Translate_core_semaphore_return_code(
                  executing->Wait.return_code );

#if defined(RTEMS_MULTIPROCESSING)
    case OBJECTS_REMOTE:
      return _Semaphore_MP_Send_request_packet(
          SEMAPHORE_MP_OBTAIN_REQUEST,
          id,
          option_set,
          timeout
      );
#endif

    case OBJECTS_ERROR:
      break;

  }

  return RTEMS_INVALID_ID;
}
Ejemplo n.º 2
0
rtems_status_code rtems_event_send(
  rtems_id        id,
  rtems_event_set event_in
)
{
  rtems_status_code  sc;
  Thread_Control    *thread;
  Objects_Locations  location;
  RTEMS_API_Control *api;
  ISR_lock_Context   lock_context;

  thread = _Thread_Get_interrupt_disable( id, &location, &lock_context );
  switch ( location ) {
    case OBJECTS_LOCAL:
      api = thread->API_Extensions[ THREAD_API_RTEMS ];
      _Event_Surrender(
        thread,
        event_in,
        &api->Event,
        THREAD_WAIT_CLASS_EVENT,
        &lock_context
      );
      _Objects_Put_for_get_isr_disable( &thread->Object );
      sc = RTEMS_SUCCESSFUL;
      break;
#ifdef RTEMS_MULTIPROCESSING
    case OBJECTS_REMOTE:
      sc = _Event_MP_Send_request_packet(
        EVENT_MP_SEND_REQUEST,
        id,
        event_in
      );
      break;
#endif
    default:
      sc = RTEMS_INVALID_ID;
      break;
  }

  return sc;
}
Ejemplo n.º 3
0
int _POSIX_Mutex_Lock_support(
  pthread_mutex_t           *mutex,
  bool                       blocking,
  Watchdog_Interval          timeout
)
{
  register POSIX_Mutex_Control *the_mutex;
  Objects_Locations             location;
  ISR_Level                     level;
  Thread_Control               *executing;

  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &location, &level );
  switch ( location ) {

    case OBJECTS_LOCAL:
      executing = _Thread_Executing;
      _CORE_mutex_Seize(
        &the_mutex->Mutex,
        executing,
        the_mutex->Object.id,
        blocking,
        timeout,
        level
      );
      _Objects_Put_for_get_isr_disable( &the_mutex->Object );
      return _POSIX_Mutex_Translate_core_mutex_return_code(
        (CORE_mutex_Status) executing->Wait.return_code
      );

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

  return EINVAL;
}
Ejemplo n.º 4
0
rtems_status_code rtems_semaphore_obtain(
  rtems_id        id,
  rtems_option    option_set,
  rtems_interval  timeout
)
{
  Semaphore_Control              *the_semaphore;
  Objects_Locations               location;
  ISR_Level                       level;
  Thread_Control                 *executing;
  rtems_attribute                 attribute_set;
  bool                            wait;

  the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
  switch ( location ) {

    case OBJECTS_LOCAL:
      executing = _Thread_Executing;
      attribute_set = the_semaphore->attribute_set;
      wait = !_Options_Is_no_wait( option_set );
#if defined(RTEMS_SMP)
      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
        MRSP_Status mrsp_status;

        _ISR_Enable( level );
        mrsp_status = _MRSP_Obtain(
          &the_semaphore->Core_control.mrsp,
          executing,
          wait,
          timeout
        );
        _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
        return _Semaphore_Translate_MRSP_status_code( mrsp_status );
      } else
#endif
      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
        _CORE_mutex_Seize(
          &the_semaphore->Core_control.mutex,
          executing,
          id,
          wait,
          timeout,
          level
        );
        _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
        return _Semaphore_Translate_core_mutex_return_code(
                  executing->Wait.return_code );
      }

      /* must be a counting semaphore */
      _CORE_semaphore_Seize_isr_disable(
        &the_semaphore->Core_control.semaphore,
        executing,
        id,
        wait,
        timeout,
        level
      );
      _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
      return _Semaphore_Translate_core_semaphore_return_code(
                  executing->Wait.return_code );

#if defined(RTEMS_MULTIPROCESSING)
    case OBJECTS_REMOTE:
      return _Semaphore_MP_Send_request_packet(
          SEMAPHORE_MP_OBTAIN_REQUEST,
          id,
          option_set,
          timeout
      );
#endif

    case OBJECTS_ERROR:
      break;

  }

  return RTEMS_INVALID_ID;
}