Example #1
0
int pthread_rwlock_unlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control  *the_rwlock;
  Objects_Locations      location;
  CORE_RWLock_Status     status;

  if ( !rwlock )
    return EINVAL;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  switch ( location ) {

    case OBJECTS_LOCAL:
      status = _CORE_RWLock_Release( &the_rwlock->RWLock, _Thread_Executing );
      _Objects_Put( &the_rwlock->Object );
      return _POSIX_RWLock_Translate_core_RWLock_return_code( status );

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

  return EINVAL;
}
Example #2
0
int pthread_rwlock_tryrdlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control *the_rwlock;
  ISR_lock_Context      lock_context;
  Thread_Control       *executing;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context );

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

  executing = _Thread_Executing;
  _CORE_RWLock_Seize_for_reading(
    &the_rwlock->RWLock,
    executing,
    false,                  /* do not wait for the rwlock */
    0,
    &lock_context
  );
  return _POSIX_RWLock_Translate_core_RWLock_return_code(
    (CORE_RWLock_Status) executing->Wait.return_code
  );
}
int pthread_rwlock_unlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control  *the_rwlock;
  Objects_Locations      location;
  CORE_RWLock_Status     status;
  
  if ( !rwlock )
    return EINVAL;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  switch ( location ) {

    case OBJECTS_REMOTE:
    case OBJECTS_ERROR:
      return EINVAL;

    case OBJECTS_LOCAL:
      status = _CORE_RWLock_Release( &the_rwlock->RWLock );
      _Thread_Enable_dispatch();
      return _POSIX_RWLock_Translate_core_RWLock_return_code( status );
  }

  return POSIX_BOTTOM_REACHED();
}
int pthread_rwlock_timedrdlock(
  pthread_rwlock_t      *rwlock,
  const struct timespec *abstime
)
{
  POSIX_RWLock_Control                    *the_rwlock;
  Thread_queue_Context                     queue_context;
  Watchdog_Interval                        ticks;
  bool                                     do_wait;
  TOD_Absolute_timeout_conversion_results  timeout_status;
  Status_Control                           status;

  /*
   *  POSIX requires that blocking calls with timeouts that take
   *  an absolute timeout must ignore issues with the absolute
   *  time provided if the operation would otherwise succeed.
   *  So we check the abstime provided, and hold on to whether it
   *  is valid or not.  If it isn't correct and in the future,
   *  then we do a polling operation and convert the STATUS_UNAVAILABLE
   *  status into the appropriate error.
   *
   *  If the timeout status is TOD_ABSOLUTE_TIMEOUT_INVALID,
   *  TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
   *  then we should not wait.
   */
  timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );

  the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );

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

  status = _CORE_RWLock_Seize_for_reading(
    &the_rwlock->RWLock,
    _Thread_Executing,
    do_wait,
    ticks,
    &queue_context
  );

  if ( !do_wait && status == STATUS_UNAVAILABLE ) {
    if ( timeout_status == TOD_ABSOLUTE_TIMEOUT_INVALID ) {
      return EINVAL;
    }

    if (
      timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST
        || timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_NOW
    ) {
      return ETIMEDOUT;
    }
  }

  return _POSIX_Get_error( status );
}
Example #5
0
int pthread_rwlock_unlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control *the_rwlock;
  Status_Control        status;

  the_rwlock = _POSIX_RWLock_Get( rwlock );
  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );

  status = _CORE_RWLock_Surrender( &the_rwlock->RWLock );
  return _POSIX_Get_error( status );
}
Example #6
0
/**
 *  This directive allows a thread to delete a rwlock specified by
 *  the rwlock id.  The rwlock is freed back to the inactive
 *  rwlock chain.
 *
 *  @param[in] rwlock is the rwlock id
 *
 *  @return This method returns 0 if there was not an
 *  error. Otherwise, a status code is returned indicating the
 *  source of the error.
 */
int pthread_rwlock_destroy(
  pthread_rwlock_t *rwlock
)
{
  POSIX_RWLock_Control *the_rwlock = NULL;
  Objects_Locations      location;

  if ( !rwlock )
    return EINVAL;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  switch ( location ) {

    case OBJECTS_LOCAL:
      /*
       *  If there is at least one thread waiting, then do not delete it.
       */
      if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
        _Objects_Put( &the_rwlock->Object );
        return EBUSY;
      }

      /*
       *  POSIX doesn't require behavior when it is locked.
       */

      _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );

      _POSIX_RWLock_Free( the_rwlock );

      _Objects_Put( &the_rwlock->Object );
      return 0;

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

  return EINVAL;
}
Example #7
0
int pthread_rwlock_tryrdlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control *the_rwlock;
  Thread_queue_Context  queue_context;
  Status_Control        status;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );

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

  status = _CORE_RWLock_Seize_for_reading(
    &the_rwlock->RWLock,
    _Thread_Executing,
    false,                  /* do not wait for the rwlock */
    &queue_context
  );
  return _POSIX_Get_error( status );
}
Example #8
0
int pthread_rwlock_wrlock(
  pthread_rwlock_t  *rwlock
)
{
  POSIX_RWLock_Control  *the_rwlock;
  Objects_Locations      location;

  if ( !rwlock )
    return EINVAL;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  switch ( location ) {

    case OBJECTS_LOCAL:

      _CORE_RWLock_Obtain_for_writing(
	&the_rwlock->RWLock,
	*rwlock,
	true,          /* do not timeout -- wait forever */
	0,
	NULL
      );

      _Thread_Enable_dispatch();
      return _POSIX_RWLock_Translate_core_RWLock_return_code(
        (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
      );

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

  return EINVAL;
}
Example #9
0
int pthread_rwlock_destroy(
  pthread_rwlock_t *rwlock
)
{
  POSIX_RWLock_Control *the_rwlock;
  ISR_lock_Context      lock_context;

  _Objects_Allocator_lock();
  the_rwlock = _POSIX_RWLock_Get( rwlock, &lock_context );

  if ( the_rwlock == NULL ) {
    _Objects_Allocator_unlock();
    return EINVAL;
  }

  _CORE_RWLock_Acquire_critical( &the_rwlock->RWLock, &lock_context );

  /*
   *  If there is at least one thread waiting, then do not delete it.
   */

  if ( !_Thread_queue_Is_empty( &the_rwlock->RWLock.Wait_queue.Queue ) ) {
    _CORE_RWLock_Release( &the_rwlock->RWLock, &lock_context );
    _Objects_Allocator_unlock();
    return EBUSY;
  }

  /*
   *  POSIX doesn't require behavior when it is locked.
   */

  _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
  _CORE_RWLock_Release( &the_rwlock->RWLock, &lock_context );
  _POSIX_RWLock_Free( the_rwlock );
  _Objects_Allocator_unlock();
  return 0;
}
Example #10
0
int pthread_rwlock_timedwrlock(
  pthread_rwlock_t      *rwlock,
  const struct timespec *abstime
)
{
  POSIX_RWLock_Control *the_rwlock;
  Thread_queue_Context  queue_context;
  Status_Control        status;

  the_rwlock = _POSIX_RWLock_Get( rwlock );
  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );

  _Thread_queue_Context_initialize( &queue_context );
  _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
    &queue_context,
    abstime
  );
  status = _CORE_RWLock_Seize_for_writing(
    &the_rwlock->RWLock,
    true,
    &queue_context
  );
  return _POSIX_Get_error( status );
}
Example #11
0
int pthread_rwlock_timedwrlock(
  pthread_rwlock_t      *rwlock,
  const struct timespec *abstime
)
{
  POSIX_RWLock_Control                        *the_rwlock;
  Objects_Locations                            location;
  Watchdog_Interval                            ticks;
  bool                                         do_wait = true;
  TOD_Absolute_timeout_conversion_results  status;
  Thread_Control                              *executing;

  /*
   *  POSIX requires that blocking calls with timeouts that take
   *  an absolute timeout must ignore issues with the absolute
   *  time provided if the operation would otherwise succeed.
   *  So we check the abstime provided, and hold on to whether it
   *  is valid or not.  If it isn't correct and in the future,
   *  then we do a polling operation and convert the UNSATISFIED
   *  status into the appropriate error.
   *
   *  If the status is TOD_ABSOLUTE_TIMEOUT_INVALID,
   *  TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
   *  then we should not wait.
   */
  status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
  if ( status != TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
    do_wait = false;

  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
  switch ( location ) {

    case OBJECTS_LOCAL:

      executing = _Thread_Executing;
      _CORE_RWLock_Obtain_for_writing(
        &the_rwlock->RWLock,
        executing,
        *rwlock,
        do_wait,
        ticks,
        NULL
      );

      _Objects_Put( &the_rwlock->Object );
      if ( !do_wait &&
           (executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
        if ( status == TOD_ABSOLUTE_TIMEOUT_INVALID )
          return EINVAL;
        if ( status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
             status == TOD_ABSOLUTE_TIMEOUT_IS_NOW )
          return ETIMEDOUT;
      }

      return _POSIX_RWLock_Translate_core_RWLock_return_code(
        (CORE_RWLock_Status) executing->Wait.return_code
      );

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

  return EINVAL;
}