Scopira
20080306
|
#include <context.h>
Friends | |
class | scopira::agent::send_msg |
class | scopira::agent::recv_msg |
The simplest run constext.
scopira::agent::task_context::task_context | ( | void | ) |
Constructor, for users.
scopira::agent::task_context::task_context | ( | taskmsg_reactor_i * | reac | ) |
A constrcutor, for users, that also registers a on-received-msg reactor. You would then do all your recv_msg stuff in that handler.
This is useful for gui programming and other places where you'd rather not pole or block for messages.
Note that your reactor will be called in one of the agent's threads. If you do any gui stuff, make sure to aquire any proper locks and such.
void scopira::agent::task_context::barrier_group | ( | void | ) |
A barrier for all the processes in this group (similar to MPI_Barrier)
|
inline |
Is the agent in a failed state?
References scopira::agent::agent_i::failed(), and scopira::agent::agent_i::instance().
int scopira::agent::task_context::find_services | ( | scopira::tool::uuid & | serviceid, |
scopira::basekit::narray< scopira::tool::uuid > & | out | ||
) |
Search for service providers. This function will find all the (usually) tasks that support the given serviceid.
In the future, this function may also accept distance and arch-querty critieria to further refine the search.
It will return the number of tasks found, which may be 0. The output list will be put into out. The resulting array may have some rough sorting, and if it does it'll be from more prefered (by what metric? usually network distance) to least.
|
inline |
Gets the UUID of current I'm running under agent.
References scopira::agent::agent_i::instance().
|
inline |
Your whole peer group.
|
inline |
Gets the size of my group. This will always be atleast 1.
|
inline |
Gets my UUID
|
inline |
Gets the UUID of the given peer by index. the index must be valid.
|
inline |
Gets my index within a group.
int scopira::agent::task_context::get_index | ( | scopira::tool::uuid | id | ) | const |
Gets the index of the given process UUID in my group. Returns -1 for not found.
|
inline |
Gets the source UUID of the last wait_msg trigger. This is not to be confused with the one in recv_msg::get_source: they're unrelated
bool scopira::agent::task_context::has_msg | ( | scopira::tool::uuid | src | ) |
Checks (polls) if there is a msg from the given peer in the event queue. A zero src is "from anyone". The actual source can be retrived with get_source().
bool scopira::agent::task_context::has_msg | ( | int | src = -1 | ) |
Checks if there a message from the given group peer. -1 is anyone in the GROUP. The actual source can be retrived with get_source().
bool scopira::agent::task_context::has_msg | ( | const scopira::agent::uuid_query & | Q | ) |
Checks if there a message that satisfies the given query. The actual source can be retrived with get_source().
|
inline |
Check if the given process exists.
References scopira::agent::agent_i::instance().
|
inline |
Has this task been "killed"? A task may "kill" another task with the kill_task method. When a task is killed, is_kill will return true for that task. Also, when the victum task returns from its run method, it will be destroyed. Note, this will return true when a task has been scheduled to die, but has not yet completed its run method. is_alive_task() on the otherhand, will only return fall (dead) when the specified task no longer exists.
References scopira::agent::agent_i::instance().
|
inline |
Kills a given process. If the process doesnt exit, nothing happens. If it does, a kill signal is queued for the process. The process will then be terminated at its next checkpoint.
References scopira::agent::agent_i::instance().
|
inline |
the core variant
Spawn the given master process as a group.
The given process will be the master process. numps-1 additional processes will be spawned. If numps is 0, then it numps will be the number of free processes in the system.
numps must be greater than 0. Use universe_size() to get a good idea of a size of group to launch.
The t must be registered for serialization.
References scopira::agent::agent_i::instance().
|
inline |
the core variant
Launch additional slave processes. The calling task/process will be the "master" (id 0) of this new group.
This is especially useful for master threads/ui threads/userland threads.
numps must be greater than 0. Use universe_size() to get a good idea of a size of group to launch. numps will include the already running caller/master, so the number of new slave tasks actually launched will be numps-1.
This cannot be called for processes that are already in process groups.
|
inline |
Spawn the given one task into the agent system. The UUID of the task is returned, useful for non-blocking spawns.
The UUID is your "handle" to the running task. You should "forgot" all your pointers to the given task object, as it will be absorbed into the agent system (and possibly moved between machines, etc).
The where parameter allows you to control where the new task is deployed. This can be:
References scopira::agent::agent_i::instance().
|
inline |
Returns the recommended/maximum number of full CPU-bound tasks to launch in a group/at once. Will always return >0.
References scopira::agent::agent_i::instance().
void scopira::agent::task_context::wait_group | ( | void | ) |
Waits until all the others in my group die (ie. wait_task on each of them)
bool scopira::agent::task_context::wait_msg | ( | scopira::tool::uuid | src, |
int | timeout = 0 |
||
) |
Waits for a msg from the given src. Make src zero for "anyone in the universe". Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().
Use has_msg to do instantaneous polling.
bool scopira::agent::task_context::wait_msg | ( | int | src = -1 , |
int | timeout = 0 |
||
) |
Waits for a msg from the given peer in my group. Make src -1 for "anyone in the GROUP" (and just the group). Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().
Use has_msg to do instantaneous polling.
bool scopira::agent::task_context::wait_msg | ( | const scopira::agent::uuid_query & | Q, |
int | timeout = 0 |
||
) |
Waits for a msg that satisfies the given query. Returns true if one came within the time out. Make timeout 0 for inifnity. The actual source can be retrived with get_source().
Use has_msg to do instantaneous polling.
|
inline |
Wait for the given process to die. Returns true if the process died/is dead/doesnt exist. False if the process still lives after the given time out. (1000 msec=second). A timeout of 0 msec means to wait indefinatly.
References scopira::agent::agent_i::instance().