summaryrefslogtreecommitdiffstats
path: root/raul/Command.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-12-04 23:02:14 +0000
committerDavid Robillard <d@drobilla.net>2007-12-04 23:02:14 +0000
commitfeab87ff3c9dce87ef127c8c7e42e6d51950aa2e (patch)
tree384de5815f2da11fb4079209fd186e6a361fad52 /raul/Command.hpp
parent6bb9c35360b3919236ed1df997e2021f817f3d19 (diff)
downloadraul-feab87ff3c9dce87ef127c8c7e42e6d51950aa2e.tar.gz
raul-feab87ff3c9dce87ef127c8c7e42e6d51950aa2e.tar.bz2
raul-feab87ff3c9dce87ef127c8c7e42e6d51950aa2e.zip
Added 'has_waiter' method for Semaphore.
Added new Command class, for e.g. coarse GUI->Engine RT safe events. git-svn-id: http://svn.drobilla.net/lad/raul@947 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/Command.hpp')
-rw-r--r--raul/Command.hpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/raul/Command.hpp b/raul/Command.hpp
new file mode 100644
index 0000000..296af10
--- /dev/null
+++ b/raul/Command.hpp
@@ -0,0 +1,54 @@
+/* This file is part of Raul.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Raul is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef RAUL_COMMAND_HPP
+#define RAUL_COMMAND_HPP
+
+#include <raul/Semaphore.hpp>
+#include <boost/utility.hpp>
+
+namespace Raul {
+
+
+/** A blocking command to be executed in the audio thread.
+ *
+ * This is useful for calling simple parameterless commands from another thread
+ * (OSC, GUI, etc) and waiting on the result. Works well for coarsely timed
+ * events. Realtime safe on the commend executing side.
+ *
+ * \ingroup raul
+ */
+class Command : boost::noncopyable {
+public:
+
+ inline Command() : _sem(0) {}
+
+ /** Caller context */
+ inline void operator()() { _sem.wait(); }
+
+ /** Execution context */
+ inline bool pending() { return _sem.has_waiter(); }
+ inline void finish() { _sem.post(); }
+
+private:
+ Semaphore _sem;
+};
+
+
+} // namespace Raul
+
+#endif // RAUL_COMMAND_HPP