Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: ThreadFlag.cpp
- Revision:
- 1:bba0ec7e075a
diff -r 0a667cdbf4c1 -r bba0ec7e075a ThreadFlag.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ThreadFlag.cpp Wed Apr 08 09:13:33 2020 +0000
@@ -0,0 +1,54 @@
+/*
+ * ThreadFlag.cpp
+ * Copyright (c) 2020, ZHAW
+ * All rights reserved.
+ */
+
+#include "ThreadFlag.h"
+
+using namespace std;
+
+unsigned int ThreadFlag::threadFlags = 0;
+
+/**
+ * Creates a signal object and assignes a unique flag.
+ */
+ThreadFlag::ThreadFlag() {
+
+ mutex.lock();
+
+ unsigned int n = 0;
+ while ((((1 << n) & threadFlags) > 0) && (n < 30)) n++;
+ threadFlag = (1 << n);
+
+ mutex.unlock();
+}
+
+/**
+ * Deletes the signal object and releases the assigned flag.
+ */
+ThreadFlag::~ThreadFlag() {
+
+ mutex.lock();
+
+ threadFlags &= ~threadFlag;
+
+ mutex.unlock();
+}
+
+/**
+ * Gets the assigned thread flag.
+ */
+unsigned int ThreadFlag::read() {
+
+ return threadFlag;
+}
+
+/**
+ * The empty operator is a shorthand notation of the <code>read()</code> method.
+ */
+ThreadFlag::operator unsigned int() {
+
+ return read();
+}
+