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; }
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; }