Skip to content

Commit 27505b8

Browse files
PR feedback
1 parent fab0e6d commit 27505b8

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

TactilityFreeRtos/Include/Tactility/Dispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Dispatcher final {
8787
}
8888

8989
/**
90-
* Consume 1 or more dispatched function (if any) until the queue is empty.
90+
* Consume 1 or more dispatched functions (if any) until the queue is empty.
9191
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
9292
* @param[in] timeout the ticks to wait for a message
9393
* @return the amount of messages that were consumed

TactilityFreeRtos/Include/Tactility/EventGroup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ class EventGroup final {
7070
return false;
7171
}
7272
portYIELD_FROM_ISR(pdTRUE);
73-
return true;
7473
} else {
75-
return xEventGroupClearBits(handle.get(), flags) == pdTRUE;
74+
xEventGroupClearBits(handle.get(), flags);
7675
}
76+
return true;
7777
}
7878

7979
/**

TactilityKernel/Include/Tactility/concurrent/Dispatcher.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
#pragma once
77

8-
#include <stdbool.h>
9-
108
#include <Tactility/Error.h>
119
#include <Tactility/FreeRTOS/FreeRTOS.h>
1210

@@ -17,7 +15,7 @@ extern "C" {
1715
typedef void (*DispatcherCallback)(void* context);
1816
typedef void* DispatcherHandle_t;
1917

20-
DispatcherHandle_t dispatcher_alloc();
18+
DispatcherHandle_t dispatcher_alloc(void);
2119

2220
void dispatcher_free(DispatcherHandle_t dispatcher);
2321

@@ -49,7 +47,7 @@ static inline error_t dispatcher_dispatch(DispatcherHandle_t dispatcher, void* c
4947
}
5048

5149
/**
52-
* Consume 1 or more dispatched function (if any) until the queue is empty.
50+
* Consume 1 or more dispatched functions (if any) until the queue is empty.
5351
*
5452
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
5553
*
@@ -62,7 +60,7 @@ static inline error_t dispatcher_dispatch(DispatcherHandle_t dispatcher, void* c
6260
error_t dispatcher_consume_timed(DispatcherHandle_t dispatcher, TickType_t timeout);
6361

6462
/**
65-
* Consume 1 or more dispatched function (if any) until the queue is empty.
63+
* Consume 1 or more dispatched functions (if any) until the queue is empty.
6664
*
6765
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
6866
*

TactilityKernel/Source/Driver.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
struct DriverInternalData {
1616
Mutex mutex { 0 };
1717
int use_count = 0;
18+
bool destroying = false;
1819

1920
DriverInternalData() {
2021
mutex_construct(&mutex);
@@ -92,10 +93,13 @@ error_t driver_construct(Driver* driver) {
9293
}
9394

9495
error_t driver_destruct(Driver* driver) {
95-
// Check if in use
96-
if (driver_internal_data(driver)->use_count != 0) {
96+
driver_lock(driver);
97+
if (driver_internal_data(driver)->use_count != 0 || driver_internal_data(driver)->destroying) {
98+
driver_unlock(driver);
9799
return ERROR_INVALID_STATE;
98100
}
101+
driver_internal_data(driver)->destroying = true;
102+
driver_unlock(driver);
99103

100104
if (driver_remove(driver) != ERROR_NONE) {
101105
LOG_W(TAG, "Failed to remove driver from ledger: %s", driver->name);
@@ -137,7 +141,7 @@ error_t driver_bind(Driver* driver, Device* device) {
137141
driver_lock(driver);
138142

139143
error_t error = ERROR_NONE;
140-
if (!device_is_added(device)) {
144+
if (driver_internal_data(driver)->destroying || !device_is_added(device)) {
141145
error = ERROR_INVALID_STATE;
142146
goto error;
143147
}
@@ -164,15 +168,15 @@ error_t driver_bind(Driver* driver, Device* device) {
164168
error_t driver_unbind(Driver* driver, Device* device) {
165169
driver_lock(driver);
166170

167-
error_t err = ERROR_NONE;
168-
if (!device_is_added(device)) {
169-
err = ERROR_INVALID_STATE;
171+
error_t error = ERROR_NONE;
172+
if (driver_internal_data(driver)->destroying || !device_is_added(device)) {
173+
error = ERROR_INVALID_STATE;
170174
goto error;
171175
}
172176

173177
if (driver->stopDevice != nullptr) {
174-
err = driver->stopDevice(device);
175-
if (err != ERROR_NONE) {
178+
error = driver->stopDevice(device);
179+
if (error != ERROR_NONE) {
176180
goto error;
177181
}
178182
}
@@ -187,7 +191,7 @@ error_t driver_unbind(Driver* driver, Device* device) {
187191
error:
188192

189193
driver_unlock(driver);
190-
return err;
194+
return error;
191195
}
192196

193197
} // extern "C"

TactilityKernel/Source/concurrent/Dispatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct DispatcherData {
4242

4343
extern "C" {
4444

45-
DispatcherHandle_t dispatcher_alloc() {
45+
DispatcherHandle_t dispatcher_alloc(void) {
4646
return new DispatcherData();
4747
}
4848

TactilityKernel/Source/concurrent/EventGroup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ error_t event_group_clear(EventGroupHandle_t eventGroup, uint32_t flags) {
2727
}
2828
portYIELD_FROM_ISR(pdTRUE);
2929
} else {
30-
if (xEventGroupClearBits(eventGroup, flags) == pdFAIL) {
31-
return ERROR_RESOURCE;
32-
}
30+
xEventGroupClearBits(eventGroup, flags);
3331
}
3432
return ERROR_NONE;
3533
}

0 commit comments

Comments
 (0)