Change mutex and semaphore handling weak functions prototype
Changed mutex lock/unlock and semaphore take/give functions to return
an int value instead of void.
Change-Id: I619327b9e14a3c37697617cbe0cba358102bd6a0
diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h
index bf6a578..053b529 100644
--- a/include/ethosu_driver.h
+++ b/include/ethosu_driver.h
@@ -120,11 +120,16 @@
* ethosu_driver.c.
*/
void *ethosu_mutex_create(void);
-void ethosu_mutex_lock(void *mutex);
-void ethosu_mutex_unlock(void *mutex);
void *ethosu_semaphore_create(void);
-void ethosu_semaphore_take(void *sem);
-void ethosu_semaphore_give(void *sem);
+/*
+ * Returns:
+ * -1 on error
+ * 0 on success
+ */
+int ethosu_mutex_lock(void *mutex);
+int ethosu_mutex_unlock(void *mutex);
+int ethosu_semaphore_take(void *sem);
+int ethosu_semaphore_give(void *sem);
/*
* Callbacks for begin/end of inference. user_data pointer is passed to the
diff --git a/src/ethosu_driver.c b/src/ethosu_driver.c
index 9175991..316ed4d 100644
--- a/src/ethosu_driver.c
+++ b/src/ethosu_driver.c
@@ -163,14 +163,16 @@
UNUSED(mutex);
}
-void __attribute__((weak)) ethosu_mutex_lock(void *mutex)
+int __attribute__((weak)) ethosu_mutex_lock(void *mutex)
{
UNUSED(mutex);
+ return 0;
}
-void __attribute__((weak)) ethosu_mutex_unlock(void *mutex)
+int __attribute__((weak)) ethosu_mutex_unlock(void *mutex)
{
UNUSED(mutex);
+ return 0;
}
// Baremetal implementation of creating a semaphore
@@ -187,7 +189,7 @@
}
// Baremetal simulation of waiting/sleeping for and then taking a semaphore using intrisics
-void __attribute__((weak)) ethosu_semaphore_take(void *sem)
+int __attribute__((weak)) ethosu_semaphore_take(void *sem)
{
struct ethosu_semaphore_t *s = sem;
while (s->count == 0)
@@ -195,14 +197,16 @@
__WFE();
}
s->count = 0;
+ return 0;
}
// Baremetal simulation of giving a semaphore and waking up processes using intrinsics
-void __attribute__((weak)) ethosu_semaphore_give(void *sem)
+int __attribute__((weak)) ethosu_semaphore_give(void *sem)
{
struct ethosu_semaphore_t *s = sem;
s->count = 1;
__SEV();
+ return 0;
}
/******************************************************************************
@@ -369,6 +373,7 @@
{
drv->status_error = true;
}
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_semaphore_give(drv->semaphore);
}
@@ -475,6 +480,7 @@
case ETHOSU_JOB_DONE:
// Wait for interrupt in blocking mode. In non-blocking mode
// the interrupt has already triggered
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_semaphore_take(drv->semaphore);
// Inference done callback
@@ -689,8 +695,10 @@
do
{
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_mutex_lock(ethosu_mutex);
drv = ethosu_find_and_reserve_driver();
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_mutex_unlock(ethosu_mutex);
if (drv != NULL)
@@ -699,6 +707,7 @@
}
LOG_INFO("Waiting for NPU driver handle to become available...");
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_semaphore_take(ethosu_semaphore);
} while (1);
@@ -708,6 +717,7 @@
void ethosu_release_driver(struct ethosu_driver *drv)
{
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_mutex_lock(ethosu_mutex);
if (drv != NULL && drv->reserved)
{
@@ -720,6 +730,7 @@
ethosu_dev_soft_reset(drv->dev);
ethosu_reset_job(drv);
drv->status_error = false;
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_semaphore_give(drv->semaphore);
(void)set_clock_and_power_request(
drv, ETHOSU_INFERENCE_REQUEST, ETHOSU_CLOCK_Q_ENABLE, ETHOSU_POWER_Q_ENABLE);
@@ -728,8 +739,10 @@
drv->reserved = false;
LOG_DEBUG("NPU driver handle %p released", drv);
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_semaphore_give(ethosu_semaphore);
}
+ /* TODO: feedback needed aout how to handle error (-1) return value */
ethosu_mutex_unlock(ethosu_mutex);
}