-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Partially document timestamp class, still needs operators and maybe a couple other things. * Completely documented thread_event class as well as concurrency enums. * update datetime property examples to say "set thing" instead of "current thing," document julian_day property. * Documents timestamp_from_UTC_time function. * Documents thread_current_id and thread_yield. * documents sound_global_pack property. * Various minor polishing for a few functions in data manipulation, audio, and user interface.
- Loading branch information
Showing
38 changed files
with
253 additions
and
21 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
doc/src/references/builtin/Audio/Global Properties/sound_default_pack.md
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,4 @@ | ||
# sound_default_pack | ||
The default value passed to the second argument of sound::load, in other words, a handle to an open pack object that all future sounds will load from unless otherwise specified individually. | ||
|
||
`pack@ sound_default_pack = null;` |
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
36 changes: 36 additions & 0 deletions
36
doc/src/references/builtin/Concurrency/Classes/thread_event/!thread_event.nvgt
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,36 @@ | ||
/** | ||
This concurrency primative implements a method by which one or more threads can safely wait on another thread for the event to become signaled. | ||
thread_event(thread_event_type type = THREAD_EVENT_AUTO_RESET); | ||
## Arguments: | ||
thread_event_type type: The type of handling to perform when a waiting thread detects that the event has been set (see remarks). | ||
## Remarks: | ||
This primative can be used to make one thread inexpensively sleep until another thread wakes it up, or can more simply be used for some threads to monitor when a condition has been completed on another thread in a safe manner. | ||
It is not a good idea to just use standard booleans in multithreaded situations where you want one thread to know when another thread has completed it's work because threads could be reading from the boolean as it is being written to by a worker thread, causing an undefined result. The thread_event object is one way around this issue, as it can signal when a standard boolean is safe to access or sometimes avoid their usage entirely. | ||
Quite simply one thread can call the set() method on an event, and if another thread has previously called the wait() method on the same event, that wait method will return thus resuming the first thread. If the event was created with the THREAD_EVENT_AUTO_RESET type, the event will also be set to unsignaled as the waiting thread wakes up. Otherwise, the reset() method must be called manually. | ||
*/ | ||
|
||
// Example: | ||
// Globals | ||
thread_event program_event; | ||
bool exit_program; | ||
string message; | ||
void message_thread() { | ||
while (true) { | ||
program_event.wait(); | ||
if (exit_program) return; | ||
screen_reader_speak(message, true); | ||
} | ||
} | ||
void main() { | ||
show_window("press space to speak on another thread"); | ||
async<void>(message_thread); | ||
while (!key_pressed(KEY_ESCAPE)) { | ||
wait(5); | ||
if (key_repeating(KEY_SPACE)) { | ||
message = "the date and time is " + calendar().format(DATE_TIME_FORMAT_RFC1123); | ||
program_event.set(); | ||
} | ||
} | ||
exit_program = true; | ||
program_event.set(); | ||
} |
8 changes: 8 additions & 0 deletions
8
doc/src/references/builtin/Concurrency/Classes/thread_event/Methods/reset.md
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,8 @@ | ||
# reset | ||
Resets an event to an unsignaled state. | ||
`void reset();` | ||
|
||
## Remarks: | ||
This method is usually only needed if THREAD_EVENT_MANUAL_RESET was specified when the event was created, however you could also cancel the signaling of an event if another thread hasn't detected the signal yet. | ||
|
||
See the main event and mutex chapters for examples. |
6 changes: 6 additions & 0 deletions
6
doc/src/references/builtin/Concurrency/Classes/thread_event/Methods/set.md
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,6 @@ | ||
# set | ||
Causes an event to become signaled, waking up any threads waiting for this condition. | ||
`void set();` | ||
|
||
## Remarks: | ||
All existing examples that use events must call this method, so it will not be demonstrated in this chapter. |
25 changes: 25 additions & 0 deletions
25
doc/src/references/builtin/Concurrency/Classes/thread_event/Methods/try_wait.nvgt
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,25 @@ | ||
/** | ||
Wait a given number of milliseconds for an event to become signaled. | ||
bool try_wait(uint milliseconds); | ||
## Arguments: | ||
* uint milliseconds: The amount of time to wait, may be 0 to not wait at all. | ||
## Returns: | ||
bool: True if another thread has signaled the event, or false if the event is still unsignaled after the given number of milliseconds has elapsed. | ||
## Remarks: | ||
The semantics of this function are exactly the same as mutex::try_wait(), accept that this function waits on an event instead of a mutex. | ||
*/ | ||
|
||
// Example: | ||
thread_event g_wait; | ||
void test_thread() { | ||
screen_reader_speak("started", true); | ||
while (!g_wait.try_wait(1000)) screen_reader_speak("waiting...", true); | ||
screen_reader_speak("ah!", true); | ||
g_wait.set(); | ||
} | ||
void main() { | ||
async<void>(test_thread); | ||
wait(3500); | ||
g_wait.set(); | ||
g_wait.wait(); // So we'll know the other thread has finished speaking it's final message. | ||
} |
11 changes: 11 additions & 0 deletions
11
doc/src/references/builtin/Concurrency/Classes/thread_event/Methods/wait.md
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,11 @@ | ||
# wait | ||
waits for the event to become signaled, blocking indefinitely or for a given duration if required. | ||
|
||
1. `void wait();` | ||
2. `void wait(uint milliseconds);` | ||
|
||
## Arguments (2): | ||
* uint milliseconds: How long to wait for the event to become signaled before throwing an exception | ||
|
||
## Remarks: | ||
Beware that if you use the version of the wait function that takes a timeout argument, an exception will be thrown if the timeout expires without the event having become signaled. The version of the function taking 0 arguments waits forever for the event's set() method to be called. |
4 changes: 4 additions & 0 deletions
4
doc/src/references/builtin/Concurrency/Enums/thread_event_type.md
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,4 @@ | ||
# thread_event_type | ||
These are the possible event types that can be used to successfully construct thread_event objects. | ||
* THREAD_EVENT_MANUAL_RESET: Many threads can wait on this event because the `thread_event::reset()` method must be manually called. | ||
* THREAD_EVENT_AUTO_RESET: Only one thread can wait on this event because it will be automatically reset as soon as the waiting thread detects that the event has become signaled. |
7 changes: 7 additions & 0 deletions
7
doc/src/references/builtin/Concurrency/Enums/thread_priority.md
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,7 @@ | ||
# thread_priority | ||
It is possible to set a thread's priority to the following values in NVGT: | ||
* THREAD_PRIORITY_LOWEST | ||
* THREAD_PRIORITY_LOW | ||
* THREAD_PRIORITY_NORMAL | ||
* THREAD_PRIORITY_HIGH | ||
* THREAD_PRIORITY_HIGHEST |
11 changes: 11 additions & 0 deletions
11
doc/src/references/builtin/Concurrency/Functions/thread_current_id.nvgt
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,11 @@ | ||
/** | ||
Determine the operating system specific ID of the currently executing thread. | ||
uint thread_current_id(); | ||
## Returns: | ||
uint: The ID of the thread that this function was called on. | ||
*/ | ||
|
||
// Example | ||
void main() { | ||
alert("Current thread ID is", thread_current_id()); | ||
} |
6 changes: 6 additions & 0 deletions
6
doc/src/references/builtin/Concurrency/Functions/thread_yield.md
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,6 @@ | ||
# thread_yield | ||
Yields CPU to other threads. | ||
void thread_yield(); | ||
|
||
## Remarks: | ||
This is a little bit like executing `wait(0);` accept that it doesn't pull the window, and there is absolutely no sleeping. It will temporarily yield code execution to the next scheduled thread that is of the same or higher priority as the one that called this function. |
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
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
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
13 changes: 13 additions & 0 deletions
13
doc/src/references/builtin/Date and Time/Classes/datetime/Properties/julian_day.nvgt
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,13 @@ | ||
/** | ||
Represents the current timestamp held by the datetime object in julian days. | ||
const double julian_day; | ||
## Remarks: | ||
The [julian day](http://en.wikipedia.org/wiki/Julian_day) measures, including decimal fractions, the amount of time that has passed (in years) since Monday, January 1st, 4713 BC at 12 PM Universal Time. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
datetime d; | ||
d.set(2024, 5, 8, 16, 17, 18); | ||
alert("The julian day represented by this datetime object is", d.julian_day); | ||
} |
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
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
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
11 changes: 11 additions & 0 deletions
11
doc/src/references/builtin/Date and Time/Classes/timestamp/!timestamp.md
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,11 @@ | ||
# timestamp | ||
Stores a unix timestamp with microsecond accuracy and provides methods for comparing them. | ||
1. timestamp(); | ||
2. timestamp(int64 epoch_microseconds); | ||
|
||
## Arguments 2: | ||
* int64 epoch_microseconds: the initial value of the timestamp | ||
|
||
## Remarks: | ||
If a timestamp object is initialize with the default constructor, it will be set to the system's current date and time. | ||
The unix epoch began on January 1st, 1970 at 12 AM UTC. |
18 changes: 18 additions & 0 deletions
18
doc/src/references/builtin/Date and Time/Classes/timestamp/Methods/has_elapsed.nvgt
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,18 @@ | ||
/** | ||
determine whether the given number of microseconds has elapsed since the time point stored in this timestamp. | ||
bool has_elapsed(int64 microseconds); | ||
## Arguments: | ||
* int64 microseconds: the number of microseconds to check elapsed status of | ||
## Returns: | ||
bool: Whether the given number of milliseconds has elapsed | ||
## Remarks: | ||
This method serves as a shorthand version of executing `bool has_elapsed = timestamp() - this >= microseconds;` | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
timestamp ts; | ||
alert("test", "will you keep the alert box opened for 10 seconds?"); | ||
if (ts.has_elapsed(10 * SECONDS)) alert("good job", "You kept the alert box opened for 10 seconds!"); | ||
else alert("oh no", "looks like a bit of character development in regards to the trait of patience is in order..."); | ||
} |
13 changes: 13 additions & 0 deletions
13
doc/src/references/builtin/Date and Time/Classes/timestamp/Methods/update.nvgt
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,13 @@ | ||
/** | ||
Reset this timestamp to the system's current date and time. | ||
void update(); | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
timestamp ts; | ||
ts -= 60 * SECONDS; | ||
alert("timestamp before reset", ts / SECONDS); | ||
ts.update(); | ||
alert("current timestamp", ts / SECONDS); | ||
} |
3 changes: 3 additions & 0 deletions
3
doc/src/references/builtin/Date and Time/Classes/timestamp/Operators/opImplConv.md
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,3 @@ | ||
# opImplConv | ||
Implicitly convert the timestamp to a 64 bit integer containing a raw microsecond accuracy unix epoch. | ||
int64 opImplConv(); |
12 changes: 12 additions & 0 deletions
12
doc/src/references/builtin/Date and Time/Classes/timestamp/Properties/UTC_time.nvgt
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,12 @@ | ||
/** | ||
Determines a UTC based time point based on the value stored in the timestamp object. | ||
const int64 UTC_time; | ||
## Remarks: | ||
UTC based time begins on October 15, 1582 at 12 AM and uses an accuracy of 100 nanoseconds. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
timestamp ts; | ||
alert("example", "The current UTC time value is " + ts.UTC_time); | ||
} |
12 changes: 12 additions & 0 deletions
12
doc/src/references/builtin/Date and Time/Classes/timestamp/Properties/elapsed.nvgt
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,12 @@ | ||
/** | ||
Determine the difference of time in microseconds between this timestamp's value and now. | ||
const int64 elapsed; | ||
## Remarks: | ||
This property is a shorthand version of the expression `int64 elapsed = timestamp() - this;` | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
datetime dt(2013, 11, 29, 1, 2, 3); | ||
alert("example", dt.format(DATE_TIME_FORMAT_RFC850) + " was " + (dt.timestamp.elapsed / DAYS) + " days ago"); | ||
} |
19 changes: 19 additions & 0 deletions
19
doc/src/references/builtin/Date and Time/Functions/timestamp_from_UTC_time.nvgt
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,19 @@ | ||
/** | ||
Create a timestamp object from a UTC time point. | ||
timestamp timestamp_from_UTC_time(int64 UTC_time); | ||
## Arguments: | ||
* int64 UTC_time: The UTC time point (see remarks). | ||
## Returns: | ||
timestamp: A timestamp derived from the given value. | ||
## Remarks: | ||
UTC based time begins on October 15, 1582 at 12 AM and uses an accuracy of 100 nanoseconds. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
calendar c(2017, 2, 3, 4, 5, 6); | ||
alert("initial calendar", c.format(DATE_TIME_FORMAT_RFC1123)); | ||
timestamp ts = timestamp_from_UTC_time(c.UTC_time); | ||
calendar c2 = ts; | ||
alert("new calendar", c2.format(DATE_TIME_FORMAT_RFC1123)); | ||
} |
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
7 changes: 0 additions & 7 deletions
7
doc/src/references/builtin/User Interface/Functions/is_console_available.md
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
doc/src/references/builtin/User Interface/Functions/is_console_available.nvgt
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,14 @@ | ||
/** | ||
Determine if your application has access to a console window or not. | ||
bool is_console_available(); | ||
## Returns: | ||
bool: true if your application has access to a console window, false otherwise. | ||
## Remarks: | ||
If this function returns false, it is very likely that any output passed to the print or println functions or the cout/cerr datastreams will be silently dropped. | ||
*/ | ||
|
||
// Example: | ||
void main() { | ||
if (is_console_available()) println("hello from the console!"); | ||
else alert("console unavailable", "hello from the user interface!"); | ||
} |