/* Unlock a read-write lock object. 
See IEEE 1003.1  */
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
/* Unlock a read-write lock object. 
See IEEE 1003.1  */
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
{
	struct posix_rwlock *rwl;
	rwl = get_posix_rwlock(*rwlock);
	if (rwl == NULL) {
		return EINVAL;
	}
	if (k_current_get() == rwl->wr_owner) {
		rwl->wr_owner = NULL;
		k_sem_give(&rwl->reader_active);
		k_sem_give(&rwl->wr_sem);
	} else {
		k_sem_give(&rwl->rd_sem);
		if (k_sem_count_get(&rwl->rd_sem) == CONCURRENT_READER_LIMIT) {
			k_sem_give(&rwl->reader_active);
		}
	}
	return 0;
}