![](/media/cache/profiles/altb_JGUSAOG.jpg.50x50_q85.jpg)
Simple program for introduction of mirror actuator.
ThreadFlag.cpp@13:1bf960928a93, 2021-05-01 (annotated)
- Committer:
- altb2
- Date:
- Sat May 01 20:08:24 2021 +0000
- Revision:
- 13:1bf960928a93
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 13:1bf960928a93 | 1 | /* |
altb2 | 13:1bf960928a93 | 2 | * ThreadFlag.cpp |
altb2 | 13:1bf960928a93 | 3 | * Copyright (c) 2019, ZHAW |
altb2 | 13:1bf960928a93 | 4 | * All rights reserved. |
altb2 | 13:1bf960928a93 | 5 | * |
altb2 | 13:1bf960928a93 | 6 | * Created on: 29.11.2019 |
altb2 | 13:1bf960928a93 | 7 | * Author: Marcel Honegger |
altb2 | 13:1bf960928a93 | 8 | */ |
altb2 | 13:1bf960928a93 | 9 | |
altb2 | 13:1bf960928a93 | 10 | #include "ThreadFlag.h" |
altb2 | 13:1bf960928a93 | 11 | |
altb2 | 13:1bf960928a93 | 12 | using namespace std; |
altb2 | 13:1bf960928a93 | 13 | |
altb2 | 13:1bf960928a93 | 14 | uint32_t ThreadFlag::threadFlags = 0; |
altb2 | 13:1bf960928a93 | 15 | |
altb2 | 13:1bf960928a93 | 16 | /** |
altb2 | 13:1bf960928a93 | 17 | * Creates a signal object and assignes a unique flag. |
altb2 | 13:1bf960928a93 | 18 | */ |
altb2 | 13:1bf960928a93 | 19 | ThreadFlag::ThreadFlag() { |
altb2 | 13:1bf960928a93 | 20 | |
altb2 | 13:1bf960928a93 | 21 | mutex.lock(); |
altb2 | 13:1bf960928a93 | 22 | |
altb2 | 13:1bf960928a93 | 23 | uint32_t n = 0; |
altb2 | 13:1bf960928a93 | 24 | while ((((1 << n) & threadFlags) > 0) && (n < 30)) n++; |
altb2 | 13:1bf960928a93 | 25 | threadFlag = (1 << n); |
altb2 | 13:1bf960928a93 | 26 | |
altb2 | 13:1bf960928a93 | 27 | mutex.unlock(); |
altb2 | 13:1bf960928a93 | 28 | } |
altb2 | 13:1bf960928a93 | 29 | |
altb2 | 13:1bf960928a93 | 30 | /** |
altb2 | 13:1bf960928a93 | 31 | * Deletes the signal object and releases the assigned flag. |
altb2 | 13:1bf960928a93 | 32 | */ |
altb2 | 13:1bf960928a93 | 33 | ThreadFlag::~ThreadFlag() { |
altb2 | 13:1bf960928a93 | 34 | |
altb2 | 13:1bf960928a93 | 35 | mutex.lock(); |
altb2 | 13:1bf960928a93 | 36 | |
altb2 | 13:1bf960928a93 | 37 | threadFlags &= ~threadFlag; |
altb2 | 13:1bf960928a93 | 38 | |
altb2 | 13:1bf960928a93 | 39 | mutex.unlock(); |
altb2 | 13:1bf960928a93 | 40 | } |
altb2 | 13:1bf960928a93 | 41 | |
altb2 | 13:1bf960928a93 | 42 | /** |
altb2 | 13:1bf960928a93 | 43 | * Gets the assigned thread flag. |
altb2 | 13:1bf960928a93 | 44 | */ |
altb2 | 13:1bf960928a93 | 45 | uint32_t ThreadFlag::read() { |
altb2 | 13:1bf960928a93 | 46 | |
altb2 | 13:1bf960928a93 | 47 | return threadFlag; |
altb2 | 13:1bf960928a93 | 48 | } |
altb2 | 13:1bf960928a93 | 49 | |
altb2 | 13:1bf960928a93 | 50 | /** |
altb2 | 13:1bf960928a93 | 51 | * The empty operator is a shorthand notation of the <code>read()</code> method. |
altb2 | 13:1bf960928a93 | 52 | */ |
altb2 | 13:1bf960928a93 | 53 | ThreadFlag::operator uint32_t() { |
altb2 | 13:1bf960928a93 | 54 | |
altb2 | 13:1bf960928a93 | 55 | return read(); |
altb2 | 13:1bf960928a93 | 56 | } |
altb2 | 13:1bf960928a93 | 57 |