![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PES2_mbed_os_6
ThreadFlag.cpp@0:5d4d21d56334, 2021-03-12 (annotated)
- Committer:
- boro
- Date:
- Fri Mar 12 13:04:33 2021 +0000
- Revision:
- 0:5d4d21d56334
controller added;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 0:5d4d21d56334 | 1 | /* |
boro | 0:5d4d21d56334 | 2 | * ThreadFlag.cpp |
boro | 0:5d4d21d56334 | 3 | * Copyright (c) 2020, ZHAW |
boro | 0:5d4d21d56334 | 4 | * All rights reserved. |
boro | 0:5d4d21d56334 | 5 | */ |
boro | 0:5d4d21d56334 | 6 | |
boro | 0:5d4d21d56334 | 7 | #include "ThreadFlag.h" |
boro | 0:5d4d21d56334 | 8 | |
boro | 0:5d4d21d56334 | 9 | using namespace std; |
boro | 0:5d4d21d56334 | 10 | |
boro | 0:5d4d21d56334 | 11 | unsigned int ThreadFlag::threadFlags = 0; |
boro | 0:5d4d21d56334 | 12 | |
boro | 0:5d4d21d56334 | 13 | /** |
boro | 0:5d4d21d56334 | 14 | * Creates a signal object and assignes a unique flag. |
boro | 0:5d4d21d56334 | 15 | */ |
boro | 0:5d4d21d56334 | 16 | ThreadFlag::ThreadFlag() { |
boro | 0:5d4d21d56334 | 17 | |
boro | 0:5d4d21d56334 | 18 | mutex.lock(); |
boro | 0:5d4d21d56334 | 19 | |
boro | 0:5d4d21d56334 | 20 | unsigned int n = 0; |
boro | 0:5d4d21d56334 | 21 | while ((((1 << n) & threadFlags) > 0) && (n < 30)) n++; |
boro | 0:5d4d21d56334 | 22 | threadFlag = (1 << n); |
boro | 0:5d4d21d56334 | 23 | |
boro | 0:5d4d21d56334 | 24 | mutex.unlock(); |
boro | 0:5d4d21d56334 | 25 | } |
boro | 0:5d4d21d56334 | 26 | |
boro | 0:5d4d21d56334 | 27 | /** |
boro | 0:5d4d21d56334 | 28 | * Deletes the signal object and releases the assigned flag. |
boro | 0:5d4d21d56334 | 29 | */ |
boro | 0:5d4d21d56334 | 30 | ThreadFlag::~ThreadFlag() { |
boro | 0:5d4d21d56334 | 31 | |
boro | 0:5d4d21d56334 | 32 | mutex.lock(); |
boro | 0:5d4d21d56334 | 33 | |
boro | 0:5d4d21d56334 | 34 | threadFlags &= ~threadFlag; |
boro | 0:5d4d21d56334 | 35 | |
boro | 0:5d4d21d56334 | 36 | mutex.unlock(); |
boro | 0:5d4d21d56334 | 37 | } |
boro | 0:5d4d21d56334 | 38 | |
boro | 0:5d4d21d56334 | 39 | /** |
boro | 0:5d4d21d56334 | 40 | * Gets the assigned thread flag. |
boro | 0:5d4d21d56334 | 41 | */ |
boro | 0:5d4d21d56334 | 42 | unsigned int ThreadFlag::read() { |
boro | 0:5d4d21d56334 | 43 | |
boro | 0:5d4d21d56334 | 44 | return threadFlag; |
boro | 0:5d4d21d56334 | 45 | } |
boro | 0:5d4d21d56334 | 46 | |
boro | 0:5d4d21d56334 | 47 | /** |
boro | 0:5d4d21d56334 | 48 | * The empty operator is a shorthand notation of the <code>read()</code> method. |
boro | 0:5d4d21d56334 | 49 | */ |
boro | 0:5d4d21d56334 | 50 | ThreadFlag::operator unsigned int() { |
boro | 0:5d4d21d56334 | 51 | |
boro | 0:5d4d21d56334 | 52 | return read(); |
boro | 0:5d4d21d56334 | 53 | } |
boro | 0:5d4d21d56334 | 54 |