BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /*
borlanic 0:fbdae7e6d805 2 * Signal.cpp
borlanic 0:fbdae7e6d805 3 * Copyright (c) 2017, ZHAW
borlanic 0:fbdae7e6d805 4 * All rights reserved.
borlanic 0:fbdae7e6d805 5 *
borlanic 0:fbdae7e6d805 6 * Created on: 08.02.2017
borlanic 0:fbdae7e6d805 7 * Author: Marcel Honegger
borlanic 0:fbdae7e6d805 8 */
borlanic 0:fbdae7e6d805 9
borlanic 0:fbdae7e6d805 10 #include "Signal.h"
borlanic 0:fbdae7e6d805 11
borlanic 0:fbdae7e6d805 12 using namespace std;
borlanic 0:fbdae7e6d805 13
borlanic 0:fbdae7e6d805 14 int32_t Signal::signals = 0;
borlanic 0:fbdae7e6d805 15
borlanic 0:fbdae7e6d805 16 /**
borlanic 0:fbdae7e6d805 17 * Creates a signal object and assignes a unique flag.
borlanic 0:fbdae7e6d805 18 */
borlanic 0:fbdae7e6d805 19 Signal::Signal() {
borlanic 0:fbdae7e6d805 20
borlanic 0:fbdae7e6d805 21 mutex.lock();
borlanic 0:fbdae7e6d805 22
borlanic 0:fbdae7e6d805 23 int32_t n = 0;
borlanic 0:fbdae7e6d805 24 while ((((1 << n) & signals) > 0) && (n < 30)) n++;
borlanic 0:fbdae7e6d805 25 signal = (1 << n);
borlanic 0:fbdae7e6d805 26
borlanic 0:fbdae7e6d805 27 mutex.unlock();
borlanic 0:fbdae7e6d805 28 }
borlanic 0:fbdae7e6d805 29
borlanic 0:fbdae7e6d805 30 /**
borlanic 0:fbdae7e6d805 31 * Deletes the signal object and releases the assigned flag.
borlanic 0:fbdae7e6d805 32 */
borlanic 0:fbdae7e6d805 33 Signal::~Signal() {
borlanic 0:fbdae7e6d805 34
borlanic 0:fbdae7e6d805 35 mutex.lock();
borlanic 0:fbdae7e6d805 36
borlanic 0:fbdae7e6d805 37 signals &= ~signal;
borlanic 0:fbdae7e6d805 38
borlanic 0:fbdae7e6d805 39 mutex.unlock();
borlanic 0:fbdae7e6d805 40 }
borlanic 0:fbdae7e6d805 41
borlanic 0:fbdae7e6d805 42 /**
borlanic 0:fbdae7e6d805 43 * Gets the assigned signal flag.
borlanic 0:fbdae7e6d805 44 */
borlanic 0:fbdae7e6d805 45 int32_t Signal::read() {
borlanic 0:fbdae7e6d805 46
borlanic 0:fbdae7e6d805 47 return signal;
borlanic 0:fbdae7e6d805 48 }
borlanic 0:fbdae7e6d805 49
borlanic 0:fbdae7e6d805 50 /**
borlanic 0:fbdae7e6d805 51 * The empty operator is a shorthand notation of the <code>read()</code> method.
borlanic 0:fbdae7e6d805 52 */
borlanic 0:fbdae7e6d805 53 Signal::operator int32_t() {
borlanic 0:fbdae7e6d805 54
borlanic 0:fbdae7e6d805 55 return read();
borlanic 0:fbdae7e6d805 56 }
borlanic 0:fbdae7e6d805 57
borlanic 0:fbdae7e6d805 58