|
| 1 | +From 08111f0f4f5034237181b8ac4b50ccdc84575fb9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Youngsik Yang <vacu9708@gmail.com> |
| 3 | +Date: Thu, 4 Jun 2026 18:09:17 +0900 |
| 4 | +Subject: [PATCH] Add ethosu_driver_is_registered() non-blocking availability |
| 5 | + check |
| 6 | + |
| 7 | +Expose whether ethosu_init() has been called by reading registered_drivers |
| 8 | +under the mutex. This allows callers to check driver availability without |
| 9 | +blocking, unlike ethosu_reserve_driver() which waits indefinitely. |
| 10 | + |
| 11 | +Signed-off-by: Youngsik Yang <vacu9708@gmail.com> |
| 12 | +--- |
| 13 | + include/ethosu_driver.h | 8 ++++++++ |
| 14 | + src/ethosu_driver.c | 8 ++++++++ |
| 15 | + 2 files changed, 16 insertions(+) |
| 16 | + |
| 17 | +diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h |
| 18 | +index 1d7a573..9f609c3 100644 |
| 19 | +--- a/include/ethosu_driver.h |
| 20 | ++++ b/include/ethosu_driver.h |
| 21 | +@@ -370,6 +370,14 @@ struct ethosu_driver *ethosu_reserve_driver(void); |
| 22 | + */ |
| 23 | + void ethosu_release_driver(struct ethosu_driver *drv); |
| 24 | + |
| 25 | ++/** |
| 26 | ++ * Returns true if at least one driver has been registered via ethosu_init(). |
| 27 | ++ * Non-blocking; safe to call before reserving a driver. |
| 28 | ++ * |
| 29 | ++ * @return true if a driver is registered, false otherwise. |
| 30 | ++ */ |
| 31 | ++bool ethosu_driver_is_registered(void); |
| 32 | ++ |
| 33 | + /** |
| 34 | + * Static inline for backwards-compatibility. |
| 35 | + * |
| 36 | +diff --git a/src/ethosu_driver.c b/src/ethosu_driver.c |
| 37 | +index 8f39a4b..1e1caaf 100644 |
| 38 | +--- a/src/ethosu_driver.c |
| 39 | ++++ b/src/ethosu_driver.c |
| 40 | +@@ -797,3 +797,11 @@ void ethosu_release_driver(struct ethosu_driver *drv) |
| 41 | + } |
| 42 | + ethosu_mutex_unlock(ethosu_mutex); |
| 43 | + } |
| 44 | ++ |
| 45 | ++bool ethosu_driver_is_registered(void) |
| 46 | ++{ |
| 47 | ++ ethosu_mutex_lock(ethosu_mutex); |
| 48 | ++ bool result = registered_drivers != NULL; |
| 49 | ++ ethosu_mutex_unlock(ethosu_mutex); |
| 50 | ++ return result; |
| 51 | ++} |
| 52 | +-- |
| 53 | +2.34.1 |
| 54 | + |
0 commit comments