#include <ace/Task.h>
class ACE_Task_Base : public ACE_Service_Object {
public:
ACE_Task_Base (ACE_Thread_Manager * = 0);
virtual ~ACE_Task_Base (void);
virtual int open (void *args = 0);
virtual int close (u_long flags = 0);
virtual int module_closed (void);
virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0);
virtual int svc (void);
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 );
virtual int wait (void);
virtual int suspend (void);
virtual int resume (void);
int grp_id (void) const;
void grp_id (int);
ACE_Thread_Manager *thr_mgr (void) const;
void thr_mgr (ACE_Thread_Manager *);
int is_reader (void) const;
int is_writer (void) const;
size_t thr_count (void) const;
void thr_count_dec (void);
static void *svc_run (void *);
static void cleanup (void *object, void *params);
size_t thr_count_;
ACE_Thread_Manager *thr_mgr_;
u_long flags_;
int grp_id_;
ACE_Thread_Mutex lock_;
private:
ACE_Task_Base &operator= (const ACE_Task_Base &);
ACE_Task_Base (const ACE_Task_Base &);
};
ACE_Thread_Manager
to store ACE_Task_Base
*'s
polymorphically.
ACE_Task_Base (ACE_Thread_Manager * = 0);
virtual ~ACE_Task_Base (void);
Task
-specific initialization and termination behavior.
virtual int open (void *args = 0);
args
can be used to pass arbitrary
information into open
.
virtual int close (u_long flags = 0);
ACE_Thread_Exit
when during thread exit and from
the default implemenation 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
.
virtual int module_closed (void);
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.
Task
-specific message processing behavior.
virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0);
virtual int svc (void);
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
);
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:
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.
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.
virtual int wait (void);
virtual int suspend (void);
virtual int resume (void);
int grp_id (void) const;
void grp_id (int);
ACE_Thread_Manager *thr_mgr (void) const;
void thr_mgr (ACE_Thread_Manager *);
int is_reader (void) const;
int is_writer (void) const;
size_t thr_count (void) const;
void thr_count_dec (void);
ACE_Thread_Exit
class destructor.
static void *svc_run (void *);
static void cleanup (void *object, void *params);
ACE_Task
.
size_t thr_count_;
thr_count_
is the number of active threads at this instant. If
the value == 0, then we're a passive object.
ACE_Thread_Manager *thr_mgr_;
u_long flags_;
int grp_id_;
ACE_Thread_Mutex lock_;
ACE_Task_Base &operator= (const ACE_Task_Base &);
ACE_Task_Base (const ACE_Task_Base &);