Changeset 3bc5984 in rtems-libbsd


Ignore:
Timestamp:
May 30, 2012, 6:42:49 PM (8 years ago)
Author:
Jennifer Averett <jennifer.averett@…>
Branches:
4.11, a8f29d695e152575479ad1a97fa354f661bebd4d, freebsd-9.3, d892051f37c2c4ad7f345f6a817ea3d38e56a431
Children:
569ce65
Parents:
8aecdc0
Message:

Debug of rw_wowned()
This implementation violates the API layer and we should
add a pthread_rwlock_is_rlocked_np() method to the API layer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/src/rtems-bsd-rwlock.c

    r8aecdc0 r3bc5984  
    4040/* Necessary to obtain some internal functions */
    4141#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
     42#include <pthread.h>
     43#include <rtems/posix/rwlock.h>
    4244
    4345#include <freebsd/machine/rtems-bsd-config.h>
     
    4951#include <freebsd/sys/lock.h>
    5052#include <freebsd/sys/rwlock.h>
    51 #include <pthread.h>
    5253
    5354#ifndef INVARIANTS
     
    192193}
    193194
     195/* XXX add pthread_rwlock_is_wlocked_np( id, &wlocked )
     196 * XXX    returns 0 or -1 w/error
     197 * XXX    wlocked = 1 if write locked
     198 * XXX
     199/* XXX add pthread_rwlock_is_rlocked_np( id, &wlocked )
     200 * XXX    similar behavior
     201 * XXX probably want to add "unlocked" state to RTEMS SuperCore rwlock
     202 * XXX
     203 * XXX Rationale: This violates the API layering BADLY!!!!!
     204 * XXX Consider: Adding pthread_np.h to hold np methods like FreeBSD
     205 * XXX           This would avoid polluting pthread.h
     206 */
    194207int
    195208rw_wowned(struct rwlock *rw)
    196209{
    197   Objects_Locations location;
    198   Semaphore_Control *sema = _Semaphore_Get(rw->lock_object.lo_id, &location);
    199 
    200   if (location == OBJECTS_LOCAL && !_Attributes_Is_counting_semaphore(sema->attribute_set)) {
    201     int owned = sema->Core_control.mutex.holder_id == rtems_task_self();
    202 
    203     _Thread_Enable_dispatch();
    204 
    205     return owned;
    206   } else {
    207     _Thread_Enable_dispatch();
    208 
    209     BSD_PANIC("unexpected semaphore location or attributes");
    210   }
     210  int                   is_locked_for_write = 0;
     211  Objects_Locations     location;
     212  POSIX_RWLock_Control *the_rwlock;
     213
     214  the_rwlock = _POSIX_RWLock_Get(&rw->lock_object.lo_id, &location);
     215  switch ( location ) {
     216
     217    case OBJECTS_LOCAL:
     218      if (the_rwlock->RWLock.current_state == CORE_RWLOCK_LOCKED_FOR_WRITING)
     219        is_locked_for_write = 1;
     220      _Thread_Enable_dispatch();
     221      return is_locked_for_write;
     222
     223#if defined(RTEMS_MULTIPROCESSING)
     224    case OBJECTS_REMOTE:
     225#endif
     226    case OBJECTS_ERROR:
     227      break;
     228  }
     229  _Thread_Enable_dispatch();
     230
     231  BSD_PANIC("unexpected semaphore location or attributes");
    211232}
    212233
Note: See TracChangeset for help on using the changeset viewer.