diff options
author | Jennifer Averett <jennifer.averett@oarcorp.com> | 2012-05-30 13:42:49 -0500 |
---|---|---|
committer | Jennifer Averett <jennifer.averett@oarcorp.com> | 2012-05-30 13:42:49 -0500 |
commit | 3bc5984ea60ff177a9c60644ee69791f2a2192f2 (patch) | |
tree | 2ba026fa23fab40812c4de7e1e00902e6563dabb | |
parent | Resolved an initialization order issue in link01.exe (diff) | |
download | rtems-libbsd-3bc5984ea60ff177a9c60644ee69791f2a2192f2.tar.bz2 |
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.
-rw-r--r-- | rtemsbsd/src/rtems-bsd-rwlock.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/rtemsbsd/src/rtems-bsd-rwlock.c b/rtemsbsd/src/rtems-bsd-rwlock.c index 49efc9c4..1f848357 100644 --- a/rtemsbsd/src/rtems-bsd-rwlock.c +++ b/rtemsbsd/src/rtems-bsd-rwlock.c @@ -39,6 +39,8 @@ /* Necessary to obtain some internal functions */ #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <pthread.h> +#include <rtems/posix/rwlock.h> #include <freebsd/machine/rtems-bsd-config.h> @@ -48,7 +50,6 @@ #include <freebsd/sys/systm.h> #include <freebsd/sys/lock.h> #include <freebsd/sys/rwlock.h> -#include <pthread.h> #ifndef INVARIANTS #define _rw_assert(rw, what, file, line) @@ -191,23 +192,43 @@ rw_sysinit_flags(void *arg) rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags); } +/* XXX add pthread_rwlock_is_wlocked_np( id, &wlocked ) + * XXX returns 0 or -1 w/error + * XXX wlocked = 1 if write locked + * XXX +/* XXX add pthread_rwlock_is_rlocked_np( id, &wlocked ) + * XXX similar behavior + * XXX probably want to add "unlocked" state to RTEMS SuperCore rwlock + * XXX + * XXX Rationale: This violates the API layering BADLY!!!!! + * XXX Consider: Adding pthread_np.h to hold np methods like FreeBSD + * XXX This would avoid polluting pthread.h + */ int rw_wowned(struct rwlock *rw) { - Objects_Locations location; - Semaphore_Control *sema = _Semaphore_Get(rw->lock_object.lo_id, &location); - - if (location == OBJECTS_LOCAL && !_Attributes_Is_counting_semaphore(sema->attribute_set)) { - int owned = sema->Core_control.mutex.holder_id == rtems_task_self(); + int is_locked_for_write = 0; + Objects_Locations location; + POSIX_RWLock_Control *the_rwlock; - _Thread_Enable_dispatch(); + the_rwlock = _POSIX_RWLock_Get(&rw->lock_object.lo_id, &location); + switch ( location ) { - return owned; - } else { - _Thread_Enable_dispatch(); + case OBJECTS_LOCAL: + if (the_rwlock->RWLock.current_state == CORE_RWLOCK_LOCKED_FOR_WRITING) + is_locked_for_write = 1; + _Thread_Enable_dispatch(); + return is_locked_for_write; - BSD_PANIC("unexpected semaphore location or attributes"); +#if defined(RTEMS_MULTIPROCESSING) + case OBJECTS_REMOTE: +#endif + case OBJECTS_ERROR: + break; } + _Thread_Enable_dispatch(); + + BSD_PANIC("unexpected semaphore location or attributes"); } void |