Compare commits

...

12 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 8b7690f596 Event
- Fixed incorrect argument in `ensure(Thread)`'s call to `pipeExistenceEnsure(Thread)`
2023-06-24 15:07:40 +02:00
Tristan B. Velloza Kildaire ee5482400e Merge branch 'feature/interruptible' into feature/ensurable_parameter 2023-06-24 15:06:45 +02:00
Tristan B. Velloza Kildaire ebc2fd5a28 - Update documentation link 2023-06-24 14:46:23 +02:00
Tristan B. Velloza Kildaire 6c91c098e2
Merge pull request #7 from deavmi/bufix/unlock_on_error
Use scope guards
2023-06-24 14:44:34 +02:00
Tristan B. Velloza Kildaire 35bf862000 Event
- Updated documentation for `ensure()`
2023-06-24 14:43:00 +02:00
Tristan B. Velloza Kildaire 0dfce9a850 Event
- Removed recursive locking startergy in `ensure()` when calling `pipeExistenceEnsure(Thread)`
- Removed now-completed TODO regarding `pipeExistenceEnsure(Thread)`
- No need to store the `pipePair` onto the stack
2023-06-24 14:40:36 +02:00
Tristan B. Velloza Kildaire b2e29bfa1c Event
- Removed now-completed TODO
2023-06-24 14:39:29 +02:00
Tristan B. Velloza Kildaire 39b69e09b9 Event
- Removed uneeded recursive locking startergy in `wouldWait()`
- Removed now-completed TODO in `wouldWait()` regarding the call to `pipeExistenceEnsure(Thread)`
2023-06-24 14:38:11 +02:00
Tristan B. Velloza Kildaire 50ba8dd9d3 Event
- No need to do a recursive locking stratergy in `wait(timeval*)` when calling `pipeExistenceEnsure(Thread)` as it already locks for us
- Also, removed the now-completed TODO in `wait(timeval*)` regarding the exception handling as we now use scope guards
2023-06-24 14:34:46 +02:00
Tristan B. Velloza Kildaire a58fb584e6 Event
- `pipeExistenceEnsure(Thread)` now uses scope guards
- Removed now-completed TODOs in `pipeExistenceEnsure(Thread)`
2023-06-24 14:30:15 +02:00
Tristan B. Velloza Kildaire 2f724d6ef0 Event
- Typo fix in `newPipe()`
- Documented `pipeExistenceEnsure(Thread)`
2023-06-24 14:28:00 +02:00
Tristan B. Velloza Kildaire 9c74aed733 Event
- Documented `newPipe()`
2023-06-24 14:24:21 +02:00
2 changed files with 37 additions and 34 deletions

View File

@ -9,7 +9,7 @@
## API
To see the full documentation (which is always up-to-date) check it out on [DUB](https://libsnooze.dpldocs.info/1.0.16-beta/).
To see the full documentation (which is always up-to-date) check it out on [DUB](https://libsnooze.dpldocs.info/1.1.0-beta/).
## Usage

View File

@ -93,8 +93,11 @@ public class Event
* threads that should be able to all be notified and wake up
* on their first call to wait instead of having `wait()`
* ensure the pipe is created on first call.
*
* Throws:
* `FatalException` on creating the pipe-pair
* if needs be
*/
// TODO: DOcument exceptions
public final void ensure()
{
/* Get the thread object (TID) for the calling thread */
@ -104,8 +107,6 @@ public class Event
ensure(callingThread);
}
// TODO: DOcument exceptions
/**
* Ensures the existence of a pipe-pair for the provided
* thread. This is normally called before the thread in
@ -115,22 +116,28 @@ public class Event
*
* Params:
* thread = the `Thread` to ensure a pipe entry for
* Throws:
* `FatalException` on creating the pipe-pair
* if needs be
*/
public final void ensure(Thread thread)
{
/* Lock the pipe-pairs */
pipesLock.lock();
/* Checks if a pipe-pair exists, if not creates it */
// TODO: Add a catch here, then unlock, rethrow
int[2] pipePair = pipeExistenceEnsure(thread);
/* Unlock the pipe-pairs */
pipesLock.unlock();
pipeExistenceEnsure(thread);
}
// TODO: Make this a method we can call actually
/**
* Returns the pipe-pair for the mapped `Thread`
* provided. if one does not exist then it is
* created first and then returned.
*
* Throws:
* `FatalException` on creating the pipe-pair
* if needs be
* Params:
* thread = the `Thread` to ensure for
* Returns: the pipe-pair as an `int[]`
*/
private int[2] pipeExistenceEnsure(Thread thread)
{
int[2] pipePair;
@ -138,19 +145,22 @@ public class Event
/* Lock the pipe-pairs */
pipesLock.lock();
/* On successful return or error */
scope(exit)
{
/* Unlock the pipe-pairs */
pipesLock.unlock();
}
/* If it is not in the pair, create a pipe-pair and save it */
if(!(thread in pipes))
{
// TODO: Add a catch here, then unlock then rethrow
pipes[thread] = newPipe(); //TODO: If bad (exception) use scopre guard too
pipes[thread] = newPipe();
}
/* Grab the pair */
pipePair = pipes[thread];
/* Unlock the pipe-pairs */
pipesLock.unlock();
return pipePair;
}
@ -175,16 +185,9 @@ public class Event
/* Get the thread object (TID) for the calling thread */
Thread callingThread = Thread.getThis();
/* Lock the pipe-pairs */
pipesLock.lock();
/* Checks if a pipe-pair exists, if not creates it */
// TODO: Add a catch here, then unlock, rethrow
int[2] pipePair = pipeExistenceEnsure(callingThread);
/* Unlock the pipe-pairs */
pipesLock.unlock();
/* Get the read-end of the pipe fd */
int readFD = pipePair[0];
@ -297,16 +300,9 @@ public class Event
/* Get the thread object (TID) for the calling thread */
Thread callingThread = Thread.getThis();
/* Lock the pipe-pairs */
pipesLock.lock();
/* Checks if a pipe-pair exists, if not creates it */
// TODO: Add a catch here, then unlock, rethrow
int[2] pipePair = pipeExistenceEnsure(callingThread);
/* Unlock the pipe-pairs */
pipesLock.unlock();
/* Get the read-end of the pipe fd */
int readFD = pipePair[0];
@ -460,12 +456,19 @@ public class Event
pipesLock.unlock();
}
/**
* Creates a new pipe-pair and returns it
*
* Throws:
* `FatalException` on error creating the pipe
* Returns: the pipe-pair as an `int[]`
*/
private int[2] newPipe()
{
/* Allocate space for the two FDs */
int[2] pipePair;
// /* Create a new pipe and put the fd of the read end in [0] and write end in [1] */
/* Create a new pipe and put the fd of the read end in [0] and write end in [1] */
int status = pipe(pipePair.ptr);
/* If the pipe creation failed */