You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/08/23 18:36:25 UTC

incubator-mynewt-core git commit: add flag to check if device is already open. mutex protection not sufficient, as a task can open a device multiple times.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/sterly_refactor 5768f08b9 -> 927702139


add flag to check if device is already open.  mutex protection not sufficient, as a task can open a device multiple times.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/92770213
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/92770213
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/92770213

Branch: refs/heads/sterly_refactor
Commit: 927702139196406b5c4cb8acd7baf456f287484c
Parents: 5768f08
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Aug 23 11:36:06 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 23 11:36:06 2016 -0700

----------------------------------------------------------------------
 drivers/adc/adc_nrf52/src/adc_nrf52.c | 6 ++++++
 libs/os/include/os/os_dev.h           | 1 +
 libs/os/src/os_dev.c                  | 4 ++++
 3 files changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/92770213/drivers/adc/adc_nrf52/src/adc_nrf52.c
----------------------------------------------------------------------
diff --git a/drivers/adc/adc_nrf52/src/adc_nrf52.c b/drivers/adc/adc_nrf52/src/adc_nrf52.c
index 60a9228..1788998 100644
--- a/drivers/adc/adc_nrf52/src/adc_nrf52.c
+++ b/drivers/adc/adc_nrf52/src/adc_nrf52.c
@@ -107,6 +107,12 @@ nrf52_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
         }
     }
 
+    if (dev->od_status & OS_DEV_STATUS_OPEN) {
+        os_mutex_release(&dev->ad_lock);
+        rc = EALREADY;
+        goto err;
+    }
+
     /* Initialize the device */
     rc = nrf_drv_saadc_init((nrf_drv_saadc_config_t *) arg,
             nrf52_saadc_event_handler);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/92770213/libs/os/include/os/os_dev.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_dev.h b/libs/os/include/os/os_dev.h
index d7e2680..7cffd5e 100644
--- a/libs/os/include/os/os_dev.h
+++ b/libs/os/include/os/os_dev.h
@@ -47,6 +47,7 @@ struct os_dev;
 #define OS_DEV_STATUS_BASE    (1 << 0)
 #define OS_DEV_STATUS_INITING (1 << 1)
 #define OS_DEV_STATUS_READY   (1 << 2)
+#define OS_DEV_STATUS_OPEN    (1 << 3)
 
 typedef int (*os_dev_init_func_t)(struct os_dev *, void *);
 typedef int (*os_dev_open_func_t)(struct os_dev *, uint32_t,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/92770213/libs/os/src/os_dev.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_dev.c b/libs/os/src/os_dev.c
index acfdf45..7c9a935 100644
--- a/libs/os/src/os_dev.c
+++ b/libs/os/src/os_dev.c
@@ -204,6 +204,8 @@ os_dev_open(char *devname, uint32_t timo, void *arg)
         }
     }
 
+    dev->od_status |= OS_DEV_STATUS_OPEN;
+
     return (dev);
 err:
     return (NULL);
@@ -228,6 +230,8 @@ os_dev_close(struct os_dev *dev)
         }
     }
 
+    dev->od_status &= ~OS_DEV_STATUS_OPEN;
+
     return (0);
 err:
     return (rc);