#include "threaddef.h"
#include <stdlib.h>
Functions | |
void VMCALL | hythread_shutdown (void) |
Shut down the Hy threading library associated with the current thread. | |
void VMCALL | hythread_init (hythread_library_t lib) |
Initialize a Hy threading library. | |
hythread_t VMCALL | hythread_self (void) |
Return the hythread_t for the current thread. | |
IDATA VMCALL | hythread_create (hythread_t *handle, UDATA stacksize, UDATA priority, UDATA suspend, hythread_entrypoint_t entrypoint, void *entryarg) |
Create a new OS thread. | |
IDATA VMCALL | hythread_attach (hythread_t *handle) |
Attach an OS thread to the threading library. | |
void VMCALL | hythread_suspend (void) |
Suspend the current thread. | |
void VMCALL | hythread_resume (hythread_t thread) |
Resume a thread. | |
void VMCALL | hythread_yield (void) |
Yield the processor. | |
IDATA VMCALL | hythread_monitor_destroy (hythread_monitor_t monitor) |
Destroy a monitor. | |
IDATA VMCALL | hythread_monitor_enter (hythread_monitor_t monitor) |
Enter a monitor. | |
IDATA VMCALL | hythread_monitor_exit (hythread_monitor_t monitor) |
Exit a monitor. | |
IDATA VMCALL | hythread_monitor_wait (hythread_monitor_t monitor) |
Wait on a monitor until notified. | |
IDATA VMCALL | hythread_monitor_notify (hythread_monitor_t monitor) |
Notify a single thread waiting on a monitor. | |
IDATA VMCALL | hythread_monitor_notify_all (hythread_monitor_t monitor) |
Notify all threads waiting on a monitor. | |
IDATA VMCALL | hythread_tls_alloc (hythread_tls_key_t *handle) |
Allocate a thread local storage (TLS) key. | |
IDATA VMCALL | hythread_tls_free (hythread_tls_key_t key) |
Release a TLS key. | |
IDATA VMCALL | hythread_tls_set (hythread_t thread, hythread_tls_key_t key, void *value) |
Set a thread's TLS value. | |
IDATA VMCALL | hythread_set_priority (hythread_t thread, UDATA priority) |
Set a thread's execution priority. | |
void VMCALL | hythread_interrupt (hythread_t thread) |
Interrupt a thread. | |
UDATA VMCALL | hythread_interrupted (hythread_t thread) |
Return the value of a thread's interrupted flag. | |
UDATA VMCALL | hythread_clear_interrupted (void) |
Clear the interrupted flag of the current thread and return its previous value. | |
IDATA VMCALL | hythread_sleep_interruptable (I_64 millis, IDATA nanos) |
Suspend the current thread from executing for at least the specified time. | |
IDATA VMCALL | hythread_sleep (I_64 millis) |
Suspend the current thread from executing for at least the specified time. | |
void VMCALL | hythread_cancel (hythread_t thread) |
Terminate a running thread. | |
void VMCALL | hythread_detach (hythread_t thread) |
Detaches the current thread from the threading library. | |
void VMCALL NORETURN | hythread_exit (hythread_monitor_t monitor) |
Exit the current thread. | |
void VMCALL | hythread_priority_interrupt (hythread_t thread) |
Priority interrupt a thread. | |
UDATA VMCALL | hythread_priority_interrupted (hythread_t thread) |
Return the value of a thread's priority interrupted flag. | |
UDATA VMCALL | hythread_clear_priority_interrupted (void) |
Clear the priority interrupted flag of the current thread and return its previous value. | |
IDATA VMCALL | hythread_monitor_try_enter (hythread_monitor_t monitor) |
Attempt to enter a monitor without blocking. | |
IDATA VMCALL | hythread_monitor_wait_timed (hythread_monitor_t monitor, I_64 millis, IDATA nanos) |
Wait on a monitor until notified or timed out. | |
UDATA *VMCALL | hythread_global (char *name) |
Fetch or create a 'named global'. | |
IDATA VMCALL | hythread_monitor_wait_interruptable (hythread_monitor_t monitor, I_64 millis, IDATA nanos) |
Wait on a monitor until notified, interrupted (priority or normal), or timed out. | |
UDATA VMCALL | hythread_monitor_num_waiting (hythread_monitor_t monitor) |
Returns how many threads are currently waiting on a monitor. | |
IDATA VMCALL | hythread_monitor_exit_using_threadId (hythread_monitor_t monitor, hythread_t threadId) |
Exit a monitor. | |
IDATA VMCALL | hythread_monitor_enter_using_threadId (hythread_monitor_t monitor, hythread_t threadId) |
Enter a monitor. | |
IDATA VMCALL | hythread_monitor_try_enter_using_threadId (hythread_monitor_t monitor, hythread_t threadId) |
Attempt to enter a monitor without blocking. | |
UDATA VMCALL | hythread_lib_get_flags () |
Get threading library global flags. | |
UDATA VMCALL | hythread_lib_set_flags (UDATA flags) |
Set threading library global flags. | |
UDATA VMCALL | hythread_lib_clear_flags (UDATA flags) |
Clear specified threading library global flags. | |
IDATA VMCALL | hythread_monitor_init_with_name (hythread_monitor_t *handle, UDATA flags, char *name) |
Acquire and initialize a new monitor from the threading library. | |
void VMCALL | hythread_lib_lock (hythread_t self) |
Acquire the threading library's global lock. | |
void VMCALL | hythread_lib_unlock (hythread_t self) |
Release the threading library's global lock. | |
IDATA VMCALL | hythread_park (I_64 millis, IDATA nanos) |
'Park' the current thread. | |
void VMCALL | hythread_unpark (hythread_t thread) |
'Unpark' the specified thread. | |
IDATA VMCALL | hythread_tls_alloc_with_finalizer (hythread_tls_key_t *handle, hythread_tls_finalizer_t finalizer) |
Allocate a thread local storage (TLS) key. | |
UDATA VMCALL | hythread_current_stack_free (void) |
Return the remaining useable bytes of the current thread's OS stack. |
IDATA VMCALL hythread_attach | ( | hythread_t * | handle | ) |
Attach an OS thread to the threading library.
Create a new hythread_t to represent the existing OS thread. Attaching a thread is required when a thread was created outside of the Hy threading library wants to use any of the Hy threading library functionality.
If the OS thread is already attached, handle is set to point to the existing hythread_t.
[out] | handle | pointer to a hythread_t to be set (will be ignored if null) |
void VMCALL hythread_cancel | ( | hythread_t | thread | ) |
Terminate a running thread.
[in] | thread | a thread to be terminated |
UDATA VMCALL hythread_clear_interrupted | ( | void | ) |
Clear the interrupted flag of the current thread and return its previous value.
UDATA VMCALL hythread_clear_priority_interrupted | ( | void | ) |
Clear the priority interrupted flag of the current thread and return its previous value.
IDATA VMCALL hythread_create | ( | hythread_t * | handle, | |
UDATA | stacksize, | |||
UDATA | priority, | |||
UDATA | suspend, | |||
hythread_entrypoint_t | entrypoint, | |||
void * | entryarg | |||
) |
Create a new OS thread.
The created thread is attached to the threading library.
Unlike POSIX, this doesn't require an attributes structure. Instead, any interesting attributes (e.g. stacksize) are passed in with the arguments.
[out] | handle | a pointer to a hythread_t which will point to the thread (if successfully created) |
[in] | stacksize | the size of the new thread's stack (bytes) 0 indicates use default size |
[in] | priority | priorities range from HYTHREAD_PRIORITY_MIN to HYTHREAD_PRIORITY_MAX (inclusive) |
[in] | suspend | set to non-zero to create the thread in a suspended state. |
[in] | entrypoint | pointer to the function which the thread will run |
[in] | entryarg | a value to pass to the entrypoint function |
UDATA VMCALL hythread_current_stack_free | ( | void | ) |
Return the remaining useable bytes of the current thread's OS stack.
void VMCALL hythread_detach | ( | hythread_t | thread | ) |
Detaches the current thread from the threading library.
Detach must only be called by an attached thread. The actual parameter must be the the current thread's hythread_t, or NULL (in which case this function retrieves and uses the current thread's hythread_t). This function cannot be used to detach an arbitrary thread.
When detached, internal resources associated with the thread are freed and the hythread_t structure becomes invalid.
[in] | thread | the hythread_t of the current thread to be detached, or NULL meaning the current thread struct is looked-up and detached. |
void VMCALL NORETURN hythread_exit | ( | hythread_monitor_t | monitor | ) |
Exit the current thread.
If the thread has been detached, it is destroyed.
If monitor is not NULL, the monitor will be exited before the thread terminates. This is useful if the thread wishes to signal its termination to a watcher, since it exits the monitor and terminates the thread without ever returning control to the thread's routine, which might be running in a DLL which is about to be closed.
[in] | monitor | monitor to be exited before exiting (ignored if NULL) |
UDATA* VMCALL hythread_global | ( | char * | name | ) |
Fetch or create a 'named global'.
Return a pointer to the data associated with a named global with the specified name.
A new named global is created if a named global with the specified name can't be found.
[in] | name | name of named global to read/create |
void VMCALL hythread_init | ( | hythread_library_t | lib | ) |
Initialize a Hy threading library.
[in] | lib | pointer to the Hy thread library to be initialized (non-NULL) |
void VMCALL hythread_interrupt | ( | hythread_t | thread | ) |
Interrupt a thread.
If the thread is currently blocked (i.e. waiting on a monitor_wait or sleeping) resume the thread and cause it to return from the blocking function with HYTHREAD_INTERRUPTED.
[in] | thread | a thead to be interrupted |
UDATA VMCALL hythread_interrupted | ( | hythread_t | thread | ) |
Return the value of a thread's interrupted flag.
[in] | thread | thread to be queried |
UDATA VMCALL hythread_lib_clear_flags | ( | UDATA | flags | ) |
Clear specified threading library global flags.
[in] | flags | flags to be cleared (bit vector: 1 means clear the flag, 0 means ignore) |
UDATA VMCALL hythread_lib_get_flags | ( | ) |
Get threading library global flags.
Returns the flags for the threading library associated with the current thread.
void VMCALL hythread_lib_lock | ( | hythread_t | self | ) |
Acquire the threading library's global lock.
[in] | self | hythread_t for the current thread |
UDATA VMCALL hythread_lib_set_flags | ( | UDATA | flags | ) |
Set threading library global flags.
Sets the flags for the threading library associated with the current thread.
[in] | flags | flags to be set (bit vector: 1 means set the flag, 0 means ignore) |
void VMCALL hythread_lib_unlock | ( | hythread_t | self | ) |
Release the threading library's global lock.
[in] | self | hythread_t for the current thread |
IDATA VMCALL hythread_monitor_destroy | ( | hythread_monitor_t | monitor | ) |
Destroy a monitor.
Destroying a monitor frees the internal resources associated with it.
[in] | monitor | a monitor to be destroyed |
IDATA VMCALL hythread_monitor_enter | ( | hythread_monitor_t | monitor | ) |
Enter a monitor.
A thread may re-enter a monitor it owns multiple times, but must exit the monitor the same number of times before any other thread wanting to enter the monitor is permitted to continue.
[in] | monitor | a monitor to be entered |
IDATA VMCALL hythread_monitor_enter_using_threadId | ( | hythread_monitor_t | monitor, | |
hythread_t | threadId | |||
) |
Enter a monitor.
This is a slightly faster version of hythread_monitor_enter because the hythread_t for the current thread doesn't have to be looked up
[in] | monitor | a monitor to be entered |
[in] | threadId | hythread_t for the current thread |
IDATA VMCALL hythread_monitor_exit | ( | hythread_monitor_t | monitor | ) |
Exit a monitor.
Exit a monitor, and if the owning count is zero, release it.
[in] | monitor | a monitor to be exited |
IDATA VMCALL hythread_monitor_exit_using_threadId | ( | hythread_monitor_t | monitor, | |
hythread_t | threadId | |||
) |
Exit a monitor.
This is a slightly faster version of hythread_monitor_exit because the hythread_t for the current thread doesn't have to be looked up
[in] | monitor | a monitor to be exited |
[in] | threadId | hythread_t for the current thread |
IDATA VMCALL hythread_monitor_init_with_name | ( | hythread_monitor_t * | handle, | |
UDATA | flags, | |||
char * | name | |||
) |
Acquire and initialize a new monitor from the threading library.
[out] | handle | pointer to a hythread_monitor_t to be set to point to the new monitor |
[in] | flags | initial flag values for the monitor |
[in] | name | pointer to a C string with a description of how the monitor will be used (may be NULL) If non-NULL, the C string must be valid for the entire life of the monitor |
IDATA VMCALL hythread_monitor_notify | ( | hythread_monitor_t | monitor | ) |
Notify a single thread waiting on a monitor.
A thread is considered to be waiting on the monitor if it is currently blocked while executing hythread_monitor_wait on the monitor.
If no threads are waiting, no action is taken.
[in] | monitor | a monitor to be signaled |
IDATA VMCALL hythread_monitor_notify_all | ( | hythread_monitor_t | monitor | ) |
Notify all threads waiting on a monitor.
A thread is considered to be waiting on the monitor if it is currently blocked while executing hythread_monitor_wait on the monitor.
If no threads are waiting, no action is taken.
[in] | monitor | a monitor to be signaled |
UDATA VMCALL hythread_monitor_num_waiting | ( | hythread_monitor_t | monitor | ) |
Returns how many threads are currently waiting on a monitor.
[in] | monitor | a monitor |
IDATA VMCALL hythread_monitor_try_enter | ( | hythread_monitor_t | monitor | ) |
Attempt to enter a monitor without blocking.
If the thread must block before it enters the monitor this function returns immediately with a negative value to indicate failure.
[in] | monitor | a monitor |
IDATA VMCALL hythread_monitor_try_enter_using_threadId | ( | hythread_monitor_t | monitor, | |
hythread_t | threadId | |||
) |
Attempt to enter a monitor without blocking.
If the thread must block before it enters the monitor this function returns immediately with a negative value to indicate failure.
This is a slightly faster version of hythread_monitor_try_enter because the current thread's hythread_t doesn't have to be looked up.
[in] | monitor | a monitor |
[in] | threadId | the current thread |
IDATA VMCALL hythread_monitor_wait | ( | hythread_monitor_t | monitor | ) |
Wait on a monitor until notified.
Release the monitor, wait for a signal (notification), then re-acquire the monitor.
[in] | monitor | a monitor to be waited on |
IDATA VMCALL hythread_monitor_wait_interruptable | ( | hythread_monitor_t | monitor, | |
I_64 | millis, | |||
IDATA | nanos | |||
) |
Wait on a monitor until notified, interrupted (priority or normal), or timed out.
A timeout of 0 (0ms, 0ns) indicates wait indefinitely.
If 'interruptable' is non-zero, the wait may be interrupted by one of the interrupt functions. (i.e. hythread_interrupt, hythread_priority_interrupt);
[in] | monitor | a monitor to be waited on |
[in] | millis | >=0 |
[in] | nanos | >=0 |
[in] | interruptable | non-zero if the wait is to be interruptable |
IDATA VMCALL hythread_monitor_wait_timed | ( | hythread_monitor_t | monitor, | |
I_64 | millis, | |||
IDATA | nanos | |||
) |
Wait on a monitor until notified or timed out.
A timeout of 0 (0ms, 0ns) indicates wait indefinitely.
[in] | monitor | a monitor to be waited on |
[in] | millis | >=0 |
[in] | nanos | >=0 |
IDATA VMCALL hythread_park | ( | I_64 | millis, | |
IDATA | nanos | |||
) |
'Park' the current thread.
Stop the current thread from executing until it is unparked, interrupted, or the specified timeout elapses.
Unlike wait or sleep, the interrupted flag is NOT cleared by this API.
[in] | millis | |
[in] | nanos |
void VMCALL hythread_priority_interrupt | ( | hythread_t | thread | ) |
Priority interrupt a thread.
If the thread is currently blocked (i.e. waiting on a monitor_wait or sleeping) resume the thread and return from the blocking function with HYTHREAD_PRIORITY_INTERRUPTED
[in] | thread | a thead to be priority interrupted |
UDATA VMCALL hythread_priority_interrupted | ( | hythread_t | thread | ) |
Return the value of a thread's priority interrupted flag.
[in] | thread | thread to be queried |
void VMCALL hythread_resume | ( | hythread_t | thread | ) |
Resume a thread.
Take a threads out of the suspended state.
If the thread is not suspended, no action is taken.
[in] | thread | a thread to be resumed |
hythread_t VMCALL hythread_self | ( | void | ) |
Return the hythread_t for the current thread.
IDATA VMCALL hythread_set_priority | ( | hythread_t | thread, | |
UDATA | priority | |||
) |
Set a thread's execution priority.
[in] | thread | a thread |
[in] | priority | Use the following symbolic constants for priorities: HYTHREAD_PRIORITY_MAX HYTHREAD_PRIORITY_USER_MAX HYTHREAD_PRIORITY_NORMAL HYTHREAD_PRIORITY_USER_MIN HYTHREAD_PRIORITY_MIN |
void VMCALL hythread_shutdown | ( | void | ) |
Shut down the Hy threading library associated with the current thread.
IDATA VMCALL hythread_sleep | ( | I_64 | millis | ) |
Suspend the current thread from executing for at least the specified time.
[in] | millis | minimum number of milliseconds to sleep |
IDATA VMCALL hythread_sleep_interruptable | ( | I_64 | millis, | |
IDATA | nanos | |||
) |
Suspend the current thread from executing for at least the specified time.
[in] | millis | |
[in] | nanos |
void VMCALL hythread_suspend | ( | void | ) |
Suspend the current thread.
Stop the current thread from executing until it is resumed.
IDATA VMCALL hythread_tls_alloc | ( | hythread_tls_key_t * | handle | ) |
Allocate a thread local storage (TLS) key.
Create and return a new, unique key for thread local storage.
[out] | handle | pointer to a key to be initialized with a key value |
IDATA VMCALL hythread_tls_alloc_with_finalizer | ( | hythread_tls_key_t * | handle, | |
hythread_tls_finalizer_t | finalizer | |||
) |
Allocate a thread local storage (TLS) key.
Create and return a new, unique key for thread local storage.
[out] | handle | pointer to a key to be initialized with a key value |
[in] | a | finalizer function which will be invoked when a thread is detached or terminates if the thread's TLS entry for this key is non-NULL |
IDATA VMCALL hythread_tls_free | ( | hythread_tls_key_t | key | ) |
Release a TLS key.
Release a TLS key previously allocated by hythread_tls_alloc.
[in] | key | TLS key to be freed |
IDATA VMCALL hythread_tls_set | ( | hythread_t | thread, | |
hythread_tls_key_t | key, | |||
void * | value | |||
) |
Set a thread's TLS value.
[in] | thread | a thread |
[in] | key | key to have TLS value set (any value returned by hythread_alloc) |
[in] | value | value to be stored in TLS |
void VMCALL hythread_unpark | ( | hythread_t | thread | ) |
'Unpark' the specified thread.
If the thread is parked, it will return from park. If the thread is not parked, its 'UNPARKED' flag will be set, and it will return immediately the next time it is parked.
Note that unparks are not counted. Unparking a thread once is the same as unparking it n times.
void VMCALL hythread_yield | ( | void | ) |
Yield the processor.
Genereated on Tue Dec 9 14:13:00 2008 by Doxygen.
(c) Copyright 2005, 2008 The Apache Software Foundation or its licensors, as applicable.