Skip to content

Commit a4278d9

Browse files
committed
Add Semaphore::Type, fix warnings, bump version to 0.9.2
1 parent cd9296f commit a4278d9

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018 Flössie <[email protected]>
1+
Copyright (c) 2018-2020 Flössie <[email protected]>
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ Semaphores synchronize actions like, "Proceed only when I told you so!" Thus, se
8989

9090
There are two kinds of semaphores:
9191
1. Binary semaphores, which only remember if they were posted but not how often. This is often sufficient and the default for a `frt::Semaphore`.
92-
2. Counting semaphores, that remember how often they were posted so that the waiting task can proceed exactly that many times without blocking. Such a semaphore is created by passing `true` to the constructor:
92+
2. Counting semaphores, that remember how often they were posted so that the waiting task can proceed exactly that many times without blocking. Such a semaphore is created by passing `frt::Semaphore::Type::COUNTING` to the constructor:
9393

9494
```c++
9595
frt::Semaphore my_binary_semaphore;
96-
frt::Semaphore my_counting_semaphore(true);
96+
frt::Semaphore my_counting_semaphore(frt::Semaphore::Type::COUNTING);
9797
```
9898
9999
If you want to share data via a buffer (and don't want to use `frt::Queue`), you need a mutex to protect the buffer and a semaphore to notify the consumer. When sharing between an ISR and a task, you can't use a mutex, but must employ a *critical section*.

keywords.txt

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Mutex KEYWORD1
55
Semaphore KEYWORD1
66
Queue KEYWORD1
77

8+
Type KEYWORD1
9+
810
start KEYWORD2
911
stop KEYWORD2
1012
stopFromIdleTask KEYWORD2
@@ -30,3 +32,6 @@ pop KEYWORD2
3032
preparePopFromInterrupt KEYWORD2
3133
popFromInterrupt KEYWORD2
3234
finalizePopFromInterrupt KEYWORD2
35+
36+
BINARY LITERAL1
37+
COUNTING LITERAL1

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=frt
2-
version=0.9.1
2+
version=0.9.2
33
author=Flössie <[email protected]>
44
maintainer=Flössie <[email protected]>
55
sentence=Lightweight, easy-to-use wrapper around the Arduino_FreeRTOS_Library.

src/frt.h

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 Flössie <[email protected]>
2+
* Copyright (c) 2018-2020 Flössie <[email protected]>
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining
55
* a copy of this software and associated documentation files (the
@@ -155,7 +155,7 @@ namespace frt
155155
{
156156
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
157157

158-
vTaskDelay(max(1, ticks));
158+
vTaskDelay(max(1U, ticks));
159159
}
160160

161161
void msleep(unsigned int msecs, unsigned int& remainder)
@@ -164,7 +164,7 @@ namespace frt
164164
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
165165
remainder = msecs % portTICK_PERIOD_MS * static_cast<bool>(ticks);
166166

167-
vTaskDelay(max(1, ticks));
167+
vTaskDelay(max(1U, ticks));
168168
}
169169

170170
void wait()
@@ -176,7 +176,7 @@ namespace frt
176176
{
177177
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
178178

179-
return ulTaskNotifyTake(pdTRUE, max(1, ticks));
179+
return ulTaskNotifyTake(pdTRUE, max(1U, ticks));
180180
}
181181

182182
bool wait(unsigned int msecs, unsigned int& remainder)
@@ -185,7 +185,7 @@ namespace frt
185185
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
186186
remainder = msecs % portTICK_PERIOD_MS * static_cast<bool>(ticks);
187187

188-
if (ulTaskNotifyTake(pdTRUE, max(1, ticks))) {
188+
if (ulTaskNotifyTake(pdTRUE, max(1U, ticks))) {
189189
remainder = 0;
190190
return true;
191191
}
@@ -306,16 +306,21 @@ namespace frt
306306
class Semaphore final
307307
{
308308
public:
309-
Semaphore(bool counting = false) :
309+
enum class Type {
310+
BINARY,
311+
COUNTING
312+
};
313+
314+
Semaphore(Type type = Type::BINARY) :
310315
handle(
311316
#if configSUPPORT_STATIC_ALLOCATION > 0
312-
counting
313-
? xSemaphoreCreateCountingStatic(static_cast<UBaseType_t>(-1), 0, &buffer)
314-
: xSemaphoreCreateBinaryStatic(&buffer)
317+
type == Type::BINARY
318+
? xSemaphoreCreateBinaryStatic(&buffer)
319+
: xSemaphoreCreateCountingStatic(static_cast<UBaseType_t>(-1), 0, &buffer)
315320
#else
316-
counting
317-
? xSemaphoreCreateCounting(static_cast<UBaseType_t>(-1), 0)
318-
: xSemaphoreCreateBinary()
321+
type == Type::BINARY
322+
? xSemaphoreCreateBinary()
323+
: xSemaphoreCreateCounting(static_cast<UBaseType_t>(-1), 0)
319324
#endif
320325
)
321326
{
@@ -338,7 +343,7 @@ namespace frt
338343
{
339344
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
340345

341-
return xSemaphoreTake(handle, max(1, ticks)) == pdTRUE;
346+
return xSemaphoreTake(handle, max(1U, ticks)) == pdTRUE;
342347
}
343348

344349
bool wait(unsigned int msecs, unsigned int& remainder)
@@ -347,7 +352,7 @@ namespace frt
347352
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
348353
remainder = msecs % portTICK_PERIOD_MS * static_cast<bool>(ticks);
349354

350-
if (xSemaphoreTake(handle, max(1, ticks)) == pdTRUE) {
355+
if (xSemaphoreTake(handle, max(1U, ticks)) == pdTRUE) {
351356
remainder = 0;
352357
return true;
353358
}
@@ -422,7 +427,7 @@ namespace frt
422427
{
423428
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
424429

425-
return xQueueSend(handle, &item, max(1, ticks)) == pdTRUE;
430+
return xQueueSend(handle, &item, max(1U, ticks)) == pdTRUE;
426431
}
427432

428433
bool push(const T& item, unsigned int msecs, unsigned int& remainder)
@@ -431,7 +436,7 @@ namespace frt
431436
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
432437
remainder = msecs % portTICK_PERIOD_MS * static_cast<bool>(ticks);
433438

434-
if (xQueueSend(handle, &item, max(1, ticks)) == pdTRUE) {
439+
if (xQueueSend(handle, &item, max(1U, ticks)) == pdTRUE) {
435440
remainder = 0;
436441
return true;
437442
}
@@ -465,7 +470,7 @@ namespace frt
465470
{
466471
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
467472

468-
return xQueueReceive(handle, &item, max(1, ticks)) == pdTRUE;
473+
return xQueueReceive(handle, &item, max(1U, ticks)) == pdTRUE;
469474
}
470475

471476
bool pop(T& item, unsigned int msecs, unsigned int& remainder)
@@ -474,7 +479,7 @@ namespace frt
474479
const TickType_t ticks = msecs / portTICK_PERIOD_MS;
475480
remainder = msecs % portTICK_PERIOD_MS * static_cast<bool>(ticks);
476481

477-
if (xQueueReceive(handle, &item, max(1, ticks)) == pdTRUE) {
482+
if (xQueueReceive(handle, &item, max(1U, ticks)) == pdTRUE) {
478483
remainder = 0;
479484
return true;
480485
}

0 commit comments

Comments
 (0)