Public Member Functions | Public Attributes | Private Attributes

ACE_Thread_Control Class Reference

Used to keep track of a thread's activities within its entry point function. More...

#include <Thread_Control.h>

Collaboration diagram for ACE_Thread_Control:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ACE_Thread_Control (ACE_Thread_Manager *tm=0, int insert=0)
 ~ACE_Thread_Control (void)
ACE_THR_FUNC_RETURN exit (ACE_THR_FUNC_RETURN status, int do_thr_exit)
int insert (ACE_Thread_Manager *tm, int insert=0)
ACE_Thread_Managerthr_mgr (void)
 Returns the current <Thread_Manager>.
ACE_Thread_Managerthr_mgr (ACE_Thread_Manager *)
ACE_THR_FUNC_RETURN status (ACE_THR_FUNC_RETURN status)
 Set the exit status (and return existing status).
ACE_THR_FUNC_RETURN status (void)
 Get the current exit status.
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Private Attributes

ACE_Thread_Managertm_
 Pointer to the thread manager for this block of code.
ACE_THR_FUNC_RETURN status_
 Keeps track of the exit status for the thread.

Detailed Description

Used to keep track of a thread's activities within its entry point function.

A ACE_Thread_Manager uses this class to ensure that threads it spawns automatically register and unregister themselves with it. This class can be stored in thread-specific storage using the ACE_TSS wrapper. When a thread exits the <ACE_TSS::cleanup> function deletes this object, thereby ensuring that it gets removed from its associated ACE_Thread_Manager.

Definition at line 43 of file Thread_Control.h.


Constructor & Destructor Documentation

ACE_Thread_Control::ACE_Thread_Control ( ACE_Thread_Manager tm = 0,
int  insert = 0 
)

Initialize the thread control object. If insert != 0, then register the thread with the Thread_Manager.

Definition at line 48 of file Thread_Control.cpp.

  : tm_ (t),
    status_ (0)
{
  ACE_OS_TRACE ("ACE_Thread_Control::ACE_Thread_Control");

  if (this->tm_ != 0 && insert)
    {
      ACE_hthread_t t_id;
      ACE_OS::thr_self (t_id);
      this->tm_->insert_thr (ACE_OS::thr_self (), t_id);
    }
}

ACE_Thread_Control::~ACE_Thread_Control ( void   ) 

Remove the thread from its associated <Thread_Manager> and exit the thread if <do_thr_exit> is enabled.

Definition at line 65 of file Thread_Control.cpp.

{
  ACE_OS_TRACE ("ACE_Thread_Control::~ACE_Thread_Control");

#if defined (ACE_HAS_RECURSIVE_THR_EXIT_SEMANTICS) || defined (ACE_HAS_TSS_EMULATION) || defined (ACE_WIN32)
  this->exit (this->status_, 0);
#else
  this->exit (this->status_, 1);
#endif /* ACE_HAS_RECURSIVE_THR_EXIT_SEMANTICS */
}


Member Function Documentation

void ACE_Thread_Control::dump ( void   )  const

Dump the state of an object.

Definition at line 24 of file Thread_Control.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_OS_TRACE ("ACE_Thread_Control::dump");
#endif /* ACE_HAS_DUMP */
}

ACE_THR_FUNC_RETURN ACE_Thread_Control::exit ( ACE_THR_FUNC_RETURN  status,
int  do_thr_exit 
)

Remove this thread from its associated ACE_Thread_Manager and exit the thread if do_thr_exit is enabled.

Definition at line 79 of file Thread_Control.cpp.

{
  ACE_OS_TRACE ("ACE_Thread_Control::exit");

  if (this->tm_ != 0)
    return this->tm_->exit (exit_status, do_thr_exit);
  else
    {
#if !defined (ACE_HAS_TSS_EMULATION)
      // With ACE_HAS_TSS_EMULATION, we let ACE_Thread_Adapter::invoke ()
      // exit the thread after cleaning up TSS.
      ACE_OS::thr_exit (exit_status);
#endif /* ! ACE_HAS_TSS_EMULATION */
      return 0;
    }
}

int ACE_Thread_Control::insert ( ACE_Thread_Manager tm,
int  insert = 0 
)

Store the <Thread_Manager> and use it to register ourselves for correct shutdown.

Definition at line 32 of file Thread_Control.cpp.

{
  ACE_OS_TRACE ("ACE_Thread_Control::insert");

  ACE_hthread_t t_id;
  ACE_OS::thr_self (t_id);
  this->tm_ = tm;

  if (insert)
    return this->tm_->insert_thr (ACE_OS::thr_self (), t_id);
  else
    return 0;
}

ACE_THR_FUNC_RETURN ACE_Thread_Control::status ( ACE_THR_FUNC_RETURN  status  ) 

Set the exit status (and return existing status).

Definition at line 10 of file Thread_Control.inl.

{
  ACE_OS_TRACE ("ACE_Thread_Control::status");
  return this->status_ = s;
}

ACE_THR_FUNC_RETURN ACE_Thread_Control::status ( void   ) 

Get the current exit status.

Definition at line 19 of file Thread_Control.inl.

{
  ACE_OS_TRACE ("ACE_Thread_Control::status");
  return this->status_;
}

ACE_Thread_Manager * ACE_Thread_Control::thr_mgr ( ACE_Thread_Manager tm  ) 

Atomically set a new <Thread_Manager> and return the old <Thread_Manager>.

Definition at line 38 of file Thread_Control.inl.

{
  ACE_OS_TRACE ("ACE_Thread_Control::thr_mgr");
  ACE_Thread_Manager *o_tm = this->tm_;
  this->tm_ = tm;
  return o_tm;
}

ACE_Thread_Manager * ACE_Thread_Control::thr_mgr ( void   ) 

Returns the current <Thread_Manager>.

Definition at line 28 of file Thread_Control.inl.

{
  ACE_OS_TRACE ("ACE_Thread_Control::thr_mgr");
  return this->tm_;
}


Member Data Documentation

Declare the dynamic allocation hooks.

Definition at line 81 of file Thread_Control.h.

ACE_THR_FUNC_RETURN ACE_Thread_Control::status_ [private]

Keeps track of the exit status for the thread.

Definition at line 88 of file Thread_Control.h.

Pointer to the thread manager for this block of code.

Definition at line 85 of file Thread_Control.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines