mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 15:35:05 +00:00
Fixes
This commit is contained in:
parent
2d867ac17a
commit
10cc269d9d
@ -24,8 +24,12 @@ class Semaphore final : public Lock {
|
|||||||
assert(initialAvailable <= maxCount);
|
assert(initialAvailable <= maxCount);
|
||||||
|
|
||||||
if (maxCount == 1U) {
|
if (maxCount == 1U) {
|
||||||
assert(initialAvailable == maxCount); // TODO: Consider supporting this deviation
|
auto result = xSemaphoreCreateBinary();
|
||||||
return xSemaphoreCreateBinary();
|
if (initialAvailable != 0U) {
|
||||||
|
auto give_result = xSemaphoreGive(result);
|
||||||
|
assert(give_result == pdPASS);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return xSemaphoreCreateCounting(maxCount, initialAvailable);
|
return xSemaphoreCreateCounting(maxCount, initialAvailable);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,13 @@ using namespace tt;
|
|||||||
|
|
||||||
TEST_CASE("TimerType::Periodic timers can be stopped and restarted") {
|
TEST_CASE("TimerType::Periodic timers can be stopped and restarted") {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; });
|
auto* timer = new Timer(Timer::Type::Periodic, 1, [&counter] { counter++; });
|
||||||
timer->start(1);
|
CHECK_EQ(timer->start(), true);
|
||||||
kernel::delayTicks(10);
|
kernel::delayTicks(10);
|
||||||
timer->stop();
|
CHECK_EQ(timer->stop(), true);
|
||||||
timer->start(1);
|
CHECK_EQ(timer->start(), true);
|
||||||
kernel::delayTicks(10);
|
kernel::delayTicks(10);
|
||||||
timer->stop();
|
CHECK_EQ(timer->stop(), true);
|
||||||
delete timer;
|
delete timer;
|
||||||
|
|
||||||
CHECK_GE(counter, 2);
|
CHECK_GE(counter, 2);
|
||||||
@ -20,10 +20,10 @@ TEST_CASE("TimerType::Periodic timers can be stopped and restarted") {
|
|||||||
TEST_CASE("TimerType::Periodic calls the callback periodically") {
|
TEST_CASE("TimerType::Periodic calls the callback periodically") {
|
||||||
int ticks_to_run = 10;
|
int ticks_to_run = 10;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; });
|
auto* timer = new Timer(Timer::Type::Periodic, 1, [&counter] { counter++; });
|
||||||
timer->start(1);
|
CHECK_EQ(timer->start(), true);
|
||||||
kernel::delayTicks(ticks_to_run);
|
kernel::delayTicks(ticks_to_run);
|
||||||
timer->stop();
|
CHECK_EQ(timer->stop(), true);
|
||||||
delete timer;
|
delete timer;
|
||||||
|
|
||||||
CHECK_EQ(counter, ticks_to_run);
|
CHECK_EQ(counter, ticks_to_run);
|
||||||
@ -31,13 +31,13 @@ TEST_CASE("TimerType::Periodic calls the callback periodically") {
|
|||||||
|
|
||||||
TEST_CASE("restarting TimerType::Once timers calls the callback again") {
|
TEST_CASE("restarting TimerType::Once timers calls the callback again") {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
auto* timer = new Timer(Timer::Type::Once, [&counter]() { counter++; });
|
auto* timer = new Timer(Timer::Type::Once, 1, [&counter] { counter++; });
|
||||||
timer->start(1);
|
CHECK_EQ(timer->start(), true);
|
||||||
kernel::delayTicks(10);
|
kernel::delayTicks(10);
|
||||||
timer->stop();
|
CHECK_EQ(timer->stop(), true);
|
||||||
timer->start(1);
|
CHECK_EQ(timer->start(), true);
|
||||||
kernel::delayTicks(10);
|
kernel::delayTicks(10);
|
||||||
timer->stop();
|
CHECK_EQ(timer->stop(), true);
|
||||||
delete timer;
|
delete timer;
|
||||||
|
|
||||||
CHECK_EQ(counter, 2);
|
CHECK_EQ(counter, 2);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user