-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnvironment.kt
More file actions
39 lines (33 loc) · 1021 Bytes
/
Environment.kt
File metadata and controls
39 lines (33 loc) · 1021 Bytes
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
package mutex
/**
* Environment interface for communication with other processes.
*/
interface Environment {
/**
* Identifier of this process (from 1 to [nProcesses]).
*/
val processId: Int
/**
* The total number of processes in the system.
*/
val nProcesses: Int
/**
* Sends the specified [message] to the process [destId] (from 1 to [nProcesses]).
*/
fun send(destId: Int, message: Message)
/**
* Indicates that the process had entered critical section.
* It should be only called after locking was requested via [Process.onLockRequest].
*/
fun locked()
/**
* Indicates that the process had exited critical section.
* It should be only called after unlocking was requested via [Process.onUnlockRequest].
*/
fun unlocked()
}
/**
* Builds the message and sends it to the process [destId].
*/
inline fun Environment.send(destId: Int, builder: MessageBuilder.() -> Unit = {}) =
send(destId, Message(builder))