forked from source-academy/js-slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add grammar for mutexes * feat: add pointer tag for mutexes * feat: add types for mutex ops and edit new to accommodate mutexes * feat: implement Mutex data structure * feat: implement Mutex Add and Lock * chore: format files * fix: undefined action bug
- Loading branch information
Showing
8 changed files
with
312 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ export enum PointerTag { | |
PopSOp, | ||
BufferedChannel, | ||
UnbufferedChannel, | ||
WaitGroup | ||
WaitGroup, | ||
Mutex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export class Mutex { | ||
protected memory: DataView | ||
protected LOCKED_OFFSET = 7 | ||
|
||
toString(): string { | ||
return `Mutex { isLocked: ${this.getisLocked()} }` | ||
} | ||
|
||
constructor(memory: DataView) { | ||
this.memory = memory | ||
} | ||
|
||
protected getisLocked(): boolean { | ||
return this.memory.getUint8(this.LOCKED_OFFSET) === 1 | ||
} | ||
|
||
protected setisLocked(value: boolean): void { | ||
this.memory.setUint8(this.LOCKED_OFFSET, value ? 1 : 0) | ||
} | ||
|
||
public isLocked(): boolean { | ||
return this.getisLocked() | ||
} | ||
|
||
public lock(): void { | ||
this.setisLocked(true) | ||
} | ||
|
||
public unlock(): void { | ||
this.setisLocked(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters