From 98b52e35174496b49c5d81c6ef31018819165c36 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 4 Dec 2017 08:48:10 +0100 Subject: drvmgr: Use API mutex --- cpukit/libdrvmgr/drvmgr.c | 7 +------ cpukit/libdrvmgr/drvmgr_internal.h | 7 +++---- cpukit/libdrvmgr/drvmgr_lock.c | 19 ++----------------- 3 files changed, 6 insertions(+), 27 deletions(-) (limited to 'cpukit/libdrvmgr') diff --git a/cpukit/libdrvmgr/drvmgr.c b/cpukit/libdrvmgr/drvmgr.c index 0771c3576c..70bb9337ce 100644 --- a/cpukit/libdrvmgr/drvmgr.c +++ b/cpukit/libdrvmgr/drvmgr.c @@ -30,7 +30,7 @@ struct drvmgr drvmgr = { .level = 0, .initializing_objs = 0, - .lock = 0, + .lock = API_MUTEX_INITIALIZER("_Drvmgr"), .root_dev = {0}, .root_drv = NULL, @@ -96,11 +96,6 @@ void _DRV_Manager_initialization(void) { drvmgr_drv_reg_func *drvreg; - /* drvmgr is already initialized statically by compiler except - * the lock - */ - DRVMGR_LOCK_INIT(); - /* Call driver register functions. */ drvreg = &drvmgr_drivers[0]; while (*drvreg) { diff --git a/cpukit/libdrvmgr/drvmgr_internal.h b/cpukit/libdrvmgr/drvmgr_internal.h index 5061d926b5..78617e5a2b 100644 --- a/cpukit/libdrvmgr/drvmgr_internal.h +++ b/cpukit/libdrvmgr/drvmgr_internal.h @@ -7,6 +7,8 @@ * http://www.rtems.org/license/LICENSE. */ +#include + /* Structure hold all information the driver manager needs to know of. Used * internally by Driver Manager routines. */ @@ -15,7 +17,7 @@ struct drvmgr { int initializing_objs; /* Device tree Lock */ - rtems_id lock; + API_Mutex_Control lock; /* The first device - The root device and it's driver */ struct drvmgr_drv *root_drv; @@ -49,20 +51,17 @@ extern struct drvmgr drvmgr; extern void _DRV_Manager_Lock(void); extern void _DRV_Manager_Unlock(void); -extern int _DRV_Manager_Init_Lock(void); /* The best solution is to implement the locking with a RW lock, however there * is no such API available. Care must be taken so that dead-lock isn't created * for example in recursive functions. */ #if defined(DRVMGR_USE_LOCKS) && (DRVMGR_USE_LOCKS == 1) - #define DRVMGR_LOCK_INIT() _DRV_Manager_Init_Lock() #define DRVMGR_LOCK_WRITE() _DRV_Manager_Lock() #define DRVMGR_LOCK_READ() _DRV_Manager_Lock() #define DRVMGR_UNLOCK() _DRV_Manager_Unlock() #else /* no locking */ - #define DRVMGR_LOCK_INIT() #define DRVMGR_LOCK_WRITE() #define DRVMGR_LOCK_READ() #define DRVMGR_UNLOCK() diff --git a/cpukit/libdrvmgr/drvmgr_lock.c b/cpukit/libdrvmgr/drvmgr_lock.c index 196133012b..c7a1104eef 100644 --- a/cpukit/libdrvmgr/drvmgr_lock.c +++ b/cpukit/libdrvmgr/drvmgr_lock.c @@ -13,25 +13,10 @@ void _DRV_Manager_Lock(void) { - rtems_semaphore_obtain(drvmgr.lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + _API_Mutex_Lock(&drvmgr.lock); } void _DRV_Manager_Unlock(void) { - rtems_semaphore_release(drvmgr.lock); -} - -int _DRV_Manager_Init_Lock(void) -{ - int rc; - - rc = rtems_semaphore_create( - rtems_build_name('D', 'R', 'V', 'M'), - 1, - RTEMS_DEFAULT_ATTRIBUTES, - 0, - &drvmgr.lock); - if (rc != RTEMS_SUCCESSFUL) - return -1; - return 0; + _API_Mutex_Unlock(&drvmgr.lock); } -- cgit v1.2.3