Skip to content

Commit

Permalink
Add constants MAX_INT32_VALUE and MIN_INT32_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
havelessbemore committed May 13, 2024
1 parent f748ede commit 9044a76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/mutexes/recursiveMutex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const LOCK_BIT = 1;
* 1. {@link https://en.cppreference.com/w/cpp/thread/recursive_mutex | C++ std::recursive_mutex}
*/
export class RecursiveMutex implements Lockable, SharedResource {
/**
* The maximum levels of recursive ownership.
*/
static readonly MAX = Number.MAX_SAFE_INTEGER;

/**
* The number of locks acquired by the agent.
*/
Expand All @@ -45,11 +50,6 @@ export class RecursiveMutex implements Lockable, SharedResource {
*/
protected _mem: Int32Array;

/**
* The maximum levels of recursive ownership.
*/
static readonly MAX = Number.MAX_SAFE_INTEGER;

constructor();
/**
* @param sharedBuffer The {@link SharedArrayBuffer} that backs the mutex.
Expand Down
14 changes: 7 additions & 7 deletions src/semaphores/countingSemaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { CV_TIMED_OUT } from "../types/cvStatus";
import type { SharedResource } from "../types/sharedResource";
import type { TimedLockable } from "../types/timedLockable";

import { ConditionVariable } from "../condVars/conditionVariable";
import { ERR_SEM_NEG_COUNT, ERR_SEM_OVERFLOW } from "../errors/constants";
import { lockGuard } from "../locks/lockGuard";

import { ConditionVariable } from "../condVars/conditionVariable";
import { TimedMutex } from "../mutexes/timedMutex";
import { MAX_INT32_VALUE } from "../utils/constants";

/**
* A counting semaphore based on shared memory and atomics, allowing for
Expand All @@ -16,14 +16,14 @@ import { TimedMutex } from "../mutexes/timedMutex";
* 1. {@link https://en.cppreference.com/w/cpp/thread/counting_semaphore | C++ std::counting_semaphore}
*/
export class CountingSemaphore implements SharedResource {
private _gate: ConditionVariable;
private _mem: Int32Array;
private _mutex: TimedLockable;

/**
* The maximum possible value of the internal counter
*/
static readonly MAX = ~(1 << 31);
static readonly MAX = MAX_INT32_VALUE;

private _gate: ConditionVariable;
private _mem: Int32Array;
private _mutex: TimedLockable;

constructor();
/**
Expand Down
3 changes: 3 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const MAX_INT32_VALUE = 2147483647; // (2**31) - 1

export const MIN_INT32_VALUE = -2147483648; // -(2**31)

0 comments on commit 9044a76

Please sign in to comment.