[PATCH 1/2] drvmgr: Use API mutex

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Dec 5 07:01:58 UTC 2017


---
 cpukit/libdrvmgr/drvmgr.c          |  7 +------
 cpukit/libdrvmgr/drvmgr_internal.h |  7 +++----
 cpukit/libdrvmgr/drvmgr_lock.c     | 19 ++-----------------
 cpukit/sapi/include/confdefs.h     | 11 +----------
 4 files changed, 7 insertions(+), 37 deletions(-)

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 <rtems/score/apimutex.h>
+
 /*  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);
 }
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 8066d9a426..8204f0559f 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -150,15 +150,6 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
  */
 #define _CONFIGURE_LIBIO_POSIX_KEYS 1
 
-/*
- *  Driver Manager Configuration
- */
-#ifdef RTEMS_DRVMGR_STARTUP
-  #define _CONFIGURE_DRVMGR_SEMAPHORES 1
-#else
-  #define _CONFIGURE_DRVMGR_SEMAPHORES 0
-#endif
-
 #ifdef CONFIGURE_INIT
   rtems_libio_t rtems_libio_iops[CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS];
 
@@ -2132,7 +2123,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     (CONFIGURE_MAXIMUM_SEMAPHORES + _CONFIGURE_LIBIO_SEMAPHORES + \
       _CONFIGURE_TERMIOS_SEMAPHORES + _CONFIGURE_LIBBLOCK_SEMAPHORES + \
       _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
-      _CONFIGURE_NETWORKING_SEMAPHORES + _CONFIGURE_DRVMGR_SEMAPHORES)
+      _CONFIGURE_NETWORKING_SEMAPHORES)
 
   /*
    * This macro is calculated to specify the memory required for
-- 
2.12.3



More information about the devel mailing list