File: RunOn.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (49 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Core/StrBuf.h"
#include "NamedThread.h"

namespace storm {
	STORM_PKG(core.lang);

	/**
	 * Specifies on which thread a specific function is to be run.
	 */
	class RunOn {
		STORM_VALUE;
	public:
		enum State {
			// Run anywhere. This is used when no threading constraint has been declared, and is the
			// default value of this class.
			any,

			// The thread to run on is decided at runtime. For example, when a class has been
			// declared to run on a thread provided runtime.
			runtime,

			// The thread is known compile-time. Find the thread in the 'thread' member.
			named,
		};

		// State.
		State state;

		// Thread. Only valid if 'state == named'.
		MAYBE(NamedThread *) thread;

		// Create.
		STORM_CTOR RunOn();
		STORM_CTOR RunOn(State s);
		STORM_CTOR RunOn(NamedThread *thread);

		// Assuming we're running on a thread represented by 'this', may we run a function declared
		// to run on 'other' without sending messages?
		Bool STORM_FN canRun(RunOn other) const;

		// Output.
		void STORM_FN toS(StrBuf *to) const;
	};

	// Output.
	wostream &operator <<(wostream &to, const RunOn &v);

}