Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Task_Base Class Reference

Direct base class for the ACE_Task template. More...

`#include <Task.h>`

Inheritance diagram for ACE_Task_Base:

[legend]
Collaboration diagram for ACE_Task_Base:

[legend]
List of all members.

## Public Methods
| ACE_Task_Base (ACE_Thread_Manager *=0)
| Constructor. More...
virtual | ~ACE_Task_Base (void)
| Destructor. More...
virtual int | open (void *args=0)
| Hook called to open a Task. <args> can be used to pass arbitrary information into <open>. More...
virtual int | close (u_long flags=0)
| Hook called from <ACE_Thread_Exit> when during thread exit and from the default implementation of <module_closed>. More...
virtual int | module_closed (void)
| Hook called during <ACE_Module::close>. More...
virtual int | put (ACE_Message_Block *, ACE_Time_Value *=0)
| A hook method that can be used to pass a message to a task, where it can be processed immediately or queued for subsequent processing in the <svc> hook method. More...
virtual int | svc (void)
| Run by a daemon thread to handle deferred processing. More...
virtual int | activate (long flags=THR_NEW_LWP|THR_JOINABLE, int n_threads=1, int force_active=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, ACE_Task_Base *task=0, ACE_hthread_t thread_handles[]=0, void *stack[]=0, size_t stack_size[]=0, ACE_thread_t thread_ids[]=0)
| Turn the task into an active object, i.e., having <n_threads> of control, all running at the <priority> level (see below) with the same <grp_id>, all of which invoke <Task::svc>. More...
virtual int | wait (void)
| Block until there are no more threads spawned by this task running . More...
virtual int | suspend (void)
| Suspend a task. More...
virtual int | resume (void)
| Resume a suspended task. More...
int | grp_id (void) const
| Get the current group id. More...
void | grp_id (int)
| Set the current group id. More...
ACE_Thread_Manager * | thr_mgr (void) const
| Get the thread manager associated with this Task. More...
void | thr_mgr (ACE_Thread_Manager *)
| Set the thread manager associated with this Task. More...
int | is_reader (void) const
| True if queue is a reader, else false. More...
int | is_writer (void) const
| True if queue is a writer, else false. More...
size_t | thr_count (void) const
| Returns the number of threads currently running within a task. More...
void | thr_count_dec (void)
| Atomically decrement the thread count by 1. This should only be called by the <ACE_Thread_Exit> class destructor. More...
## Static Public Methods
void * | svc_run (void *)
| Routine that runs the service routine as a daemon thread. More...
void | cleanup (void *object, void *params)
| Cleanup hook that is called when a thread exits to gracefully shutdown an <ACE_Task>. More...
## Public Attributes
size_t | thr_count_
| Count of the number of threads running within the task. More...
ACE_Thread_Manager * | thr_mgr_
| Multi-threading manager. More...
u_long | flags_
| ACE_Task flags. More...
int | grp_id_
| This maintains the group id of the Task. More...
## Private Methods
ACE_Task_Base & | operator= (const ACE_Task_Base &)
| ACE_Task_Base (const ACE_Task_Base &)

## Detailed Description

Direct base class for the ACE_Task template.

This class factors out the non-template code in order to reduce template bloat, as well as to make it possible for the <ACE_Thread_Manager> to store <ACE_Task_Base> *'s polymorphically.

## Constructor & Destructor Documentation

ACE_Task_Base::ACE_Task_Base | ( | ACE_Thread_Manager * | thr_man = 0 | ) |

| Constructor.

ACE_Task_Base::~ACE_Task_Base | ( | void |  | ) | `[virtual]`

| Destructor.

ACE_Task_Base::ACE_Task_Base | ( | const ACE_Task_Base & |  | ) | `[private]`

## Member Function Documentation

int ACE_Task_Base::activate | ( | long | flags = THR_NEW_LWP | THR_JOINABLE,
|  | int | n_threads = 1,
|  | int | force_active = 0,
|  | long | priority = ACE_DEFAULT_THREAD_PRIORITY,
|  | int | grp_id = -1,
|  | ACE_Task_Base * | task = 0,
|  | ACE_hthread_t | thread_handles[] = 0,
|  | void * | stack[] = 0,
|  | size_t | stack_size[] = 0,
|  | ACE_thread_t | thread_names[] = 0
| ) | `[virtual]`

| Turn the task into an active object, i.e., having <n_threads> of control, all running at the <priority> level (see below) with the same <grp_id>, all of which invoke <Task::svc>. Returns -1 if failure occurs, returns 1 if Task is already an active object and <force_active> is false (i.e., do *not* create a new thread in this case), and returns 0 if Task was not already an active object and a thread is created successfully or thread is an active object and <force_active> is true. Note that if <force_active> is true and there are already threads spawned in this <Task>, the <grp_id> parameter is ignored and the <grp_id> of any newly activated thread(s) will inherit the existing <grp_id> of the existing thread(s) in the <Task>. The <{flags}> are a bitwise-OR of the following: = BEGIN<INDENT> THR_CANCEL_DISABLE, THR_CANCEL_ENABLE, THR_CANCEL_DEFERRED, THR_CANCEL_ASYNCHRONOUS, THR_BOUND, THR_NEW_LWP, THR_DETACHED, THR_SUSPENDED, THR_DAEMON, THR_JOINABLE, THR_SCHED_FIFO, THR_SCHED_RR, THR_SCHED_DEFAULT, THR_EXPLICIT_SCHED, THR_SCOPE_SYSTEM, THR_SCOPE_PROCESS = END<INDENT> By default, or if <{priority}> is set to ACE_DEFAULT_THREAD_PRIORITY, an "appropriate" priority value for the given scheduling policy (specified in <{flags}>, e.g., <THR_SCHED_DEFAULT>) is used. This value is calculated dynamically, and is the median value between the minimum and maximum priority values for the given policy. If an explicit value is given, it is used. Note that actual priority values are EXTREMEMLY implementation-dependent, and are probably best avoided. If <thread_handles> != 0 it is assumed to be an array of <n> thread_handles that will be assigned the values of the thread handles being spawned. Returns -1 on failure (<errno> will explain...), otherwise returns the group id of the threads. Assigning <task> allows you to associate the newly spawned threads with an instance of ACE_Task_Base. If <task> == 0, then the new threads are associated automatically with <this> ACE_Task_Base. Setting the <task> argument to value other than <this> makes the thread manipulating methods, such as wait(), suspend(), resume(), useless. Threads spawned with user specified <task> value must therefore be manipulated thru ACE_Thread_Manager directly. If <stack> != 0 it is assumed to be an array of <n> pointers to the base of the stacks to use for the threads being spawned. Likewise, if <stack_size> != 0 it is assumed to be an array of <n> values indicating how big each of the corresponding <stack>s are. Reimplemented in ACE_Thread_Timer_Queue_Adapter.

void ACE_Task_Base::cleanup | ( | void * | object,
|  | void * | params
| ) | `[static]`

| Cleanup hook that is called when a thread exits to gracefully shutdown an <ACE_Task>.

ACE_INLINE int ACE_Task_Base::close | ( | u_long | flags = 0 | ) | `[virtual]`

| Hook called from <ACE_Thread_Exit> when during thread exit and from the default implementation of <module_closed>. In general, this method shouldn't be called directly by an application, particularly if the <Task> is running as an Active Object. Instead, a special message should be passed into the <Task> via the <put> method defined below, and the <svc> method should interpret this as a flag to shut down the <Task>. Reimplemented in ACE_Stream_Head, ACE_Stream_Tail, ACE_Thru_Task, ACE_Svc_Handler, and ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.

ACE_INLINE void ACE_Task_Base::grp_id | ( | int | id | ) |

| Set the current group id.

ACE_INLINE int ACE_Task_Base::grp_id | ( | void |  | ) | const

| Get the current group id.

ACE_INLINE int ACE_Task_Base::is_reader | ( | void |  | ) | const

| True if queue is a reader, else false.

ACE_INLINE int ACE_Task_Base::is_writer | ( | void |  | ) | const

| True if queue is a writer, else false.

int ACE_Task_Base::module_closed | ( | void |  | ) | `[virtual]`

| Hook called during <ACE_Module::close>. The default implementation calls forwards the call to close(1). Please notice the changed value of the default argument of <close>. This allows tasks to differ between the call has been originated from <ACE_Thread_Exit> or from <module_closed>. Be aware that close(0) will be also called when a thread associated with the ACE_Task instance exits.

ACE_INLINE int ACE_Task_Base::open | ( | void * | a = 0 | ) | `[virtual]`

| Hook called to open a Task. <args> can be used to pass arbitrary information into <open>. Reimplemented in ACE_NT_Service, ACE_Stream_Head, ACE_Stream_Tail, ACE_Thru_Task, ACE_Svc_Handler, and ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.

ACE_Task_Base& ACE_Task_Base::operator= | ( | const ACE_Task_Base & |  | ) | `[private]`

ACE_INLINE int ACE_Task_Base::put | ( | ACE_Message_Block * | msg,
|  | ACE_Time_Value * | tv = 0
| ) | `[virtual]`

| A hook method that can be used to pass a message to a task, where it can be processed immediately or queued for subsequent processing in the <svc> hook method. Reimplemented in ACE_Stream_Head, ACE_Stream_Tail, ACE_Thru_Task, and ACE_Buffered_Svc_Handler.

int ACE_Task_Base::resume | ( | void |  | ) | `[virtual]`

| Resume a suspended task. Reimplemented from ACE_Service_Object.

int ACE_Task_Base::suspend | ( | void |  | ) | `[virtual]`

| Suspend a task. Reimplemented from ACE_Service_Object.

ACE_INLINE int ACE_Task_Base::svc | ( | void |  | ) | `[virtual]`

| Run by a daemon thread to handle deferred processing. Reimplemented in ACE_Asynch_Pseudo_Task, ACE_NT_Service, ACE_Proactor_Timer_Handler, ACE_Stream_Head, ACE_Stream_Tail, ACE_Thru_Task, and ACE_Thread_Timer_Queue_Adapter.

void * ACE_Task_Base::svc_run | ( | void * | args | ) | `[static]`

| Routine that runs the service routine as a daemon thread.

ACE_INLINE size_t ACE_Task_Base::thr_count | ( | void |  | ) | const

| Returns the number of threads currently running within a task. If we're a passive object this value is 0, else it's greater than 0.

ACE_INLINE void ACE_Task_Base::thr_count_dec | ( | void |  | ) |

| Atomically decrement the thread count by 1. This should only be called by the <ACE_Thread_Exit> class destructor.

ACE_INLINE void ACE_Task_Base::thr_mgr | ( | ACE_Thread_Manager * | thr_mgr | ) |

| Set the thread manager associated with this Task.

ACE_INLINE ACE_Thread_Manager * ACE_Task_Base::thr_mgr | ( | void |  | ) | const

| Get the thread manager associated with this Task.

int ACE_Task_Base::wait | ( | void |  | ) | `[virtual]`

| Block until there are no more threads spawned by this task running . Returns 0 on success and -1 on failure. Note that this method will not wait on detached threads.

## Member Data Documentation

u_long ACE_Task_Base::flags_

| ACE_Task flags.

int ACE_Task_Base::grp_id_

| This maintains the group id of the Task.

size_t ACE_Task_Base::thr_count_

| Count of the number of threads running within the task. If this value is great than 0 then we're an active object and the value of <thr_count_> is the number of active threads at this instant. If the value == 0, then we're a passive object.

ACE_Thread_Manager* ACE_Task_Base::thr_mgr_

| Multi-threading manager.

The documentation for this class was generated from the following files:

- Task.h
- Task.cpp
- Task.i