PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
ThreadFlag.cpp@23:1926540ebbec, 2022-03-23 (annotated)
- Committer:
- pmic
- Date:
- Wed Mar 23 09:46:07 2022 +0000
- Revision:
- 23:1926540ebbec
- Parent:
- 4:9c003c402033
Renamed ReEnalbe function to Enable in Servo class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 0:86129f1b4a93 | 1 | /* |
pmic | 0:86129f1b4a93 | 2 | * ThreadFlag.cpp |
pmic | 0:86129f1b4a93 | 3 | * Copyright (c) 2020, ZHAW |
pmic | 0:86129f1b4a93 | 4 | * All rights reserved. |
pmic | 0:86129f1b4a93 | 5 | */ |
pmic | 0:86129f1b4a93 | 6 | |
pmic | 0:86129f1b4a93 | 7 | #include "ThreadFlag.h" |
pmic | 0:86129f1b4a93 | 8 | |
pmic | 0:86129f1b4a93 | 9 | using namespace std; |
pmic | 0:86129f1b4a93 | 10 | |
pmic | 0:86129f1b4a93 | 11 | unsigned int ThreadFlag::threadFlags = 0; |
pmic | 0:86129f1b4a93 | 12 | |
pmic | 0:86129f1b4a93 | 13 | /** |
pmic | 0:86129f1b4a93 | 14 | * Creates a signal object and assignes a unique flag. |
pmic | 0:86129f1b4a93 | 15 | */ |
pmic | 4:9c003c402033 | 16 | ThreadFlag::ThreadFlag() |
pmic | 4:9c003c402033 | 17 | { |
pmic | 0:86129f1b4a93 | 18 | mutex.lock(); |
pmic | 4:9c003c402033 | 19 | |
pmic | 0:86129f1b4a93 | 20 | unsigned int n = 0; |
pmic | 0:86129f1b4a93 | 21 | while ((((1 << n) & threadFlags) > 0) && (n < 30)) n++; |
pmic | 0:86129f1b4a93 | 22 | threadFlag = (1 << n); |
pmic | 4:9c003c402033 | 23 | |
pmic | 0:86129f1b4a93 | 24 | mutex.unlock(); |
pmic | 0:86129f1b4a93 | 25 | } |
pmic | 0:86129f1b4a93 | 26 | |
pmic | 0:86129f1b4a93 | 27 | /** |
pmic | 0:86129f1b4a93 | 28 | * Deletes the signal object and releases the assigned flag. |
pmic | 0:86129f1b4a93 | 29 | */ |
pmic | 4:9c003c402033 | 30 | ThreadFlag::~ThreadFlag() |
pmic | 4:9c003c402033 | 31 | { |
pmic | 0:86129f1b4a93 | 32 | mutex.lock(); |
pmic | 4:9c003c402033 | 33 | |
pmic | 0:86129f1b4a93 | 34 | threadFlags &= ~threadFlag; |
pmic | 4:9c003c402033 | 35 | |
pmic | 0:86129f1b4a93 | 36 | mutex.unlock(); |
pmic | 0:86129f1b4a93 | 37 | } |
pmic | 0:86129f1b4a93 | 38 | |
pmic | 0:86129f1b4a93 | 39 | /** |
pmic | 0:86129f1b4a93 | 40 | * Gets the assigned thread flag. |
pmic | 0:86129f1b4a93 | 41 | */ |
pmic | 4:9c003c402033 | 42 | unsigned int ThreadFlag::read() |
pmic | 4:9c003c402033 | 43 | { |
pmic | 0:86129f1b4a93 | 44 | return threadFlag; |
pmic | 0:86129f1b4a93 | 45 | } |
pmic | 0:86129f1b4a93 | 46 | |
pmic | 0:86129f1b4a93 | 47 | /** |
pmic | 0:86129f1b4a93 | 48 | * The empty operator is a shorthand notation of the <code>read()</code> method. |
pmic | 0:86129f1b4a93 | 49 | */ |
pmic | 4:9c003c402033 | 50 | ThreadFlag::operator unsigned int() |
pmic | 4:9c003c402033 | 51 | { |
pmic | 0:86129f1b4a93 | 52 | return read(); |
pmic | 0:86129f1b4a93 | 53 | } |
pmic | 0:86129f1b4a93 | 54 |