summaryrefslogtreecommitdiff
path: root/ace/Thread_Control.cpp
blob: 13a4c063795dababaac3273d12efbd67c689ca06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// $Id$

#include "ace/Thread_Control.h"
#include "ace/Thread_Manager.h"

ACE_RCSID(ace, Thread_Control, "$Id$")

#if !defined (ACE_HAS_INLINED_OSCALLS)
# include "ace/Thread_Control.inl"
#endif /* ACE_HAS_INLINED_OS_CALLS */

void
ACE_Thread_Control::dump (void) const
{
  ACE_OS_TRACE ("ACE_Thread_Control::dump");
}

int
ACE_Thread_Control::insert (ACE_Thread_Manager *tm, int insert)
{
  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;
}

// Initialize the thread controller.

ACE_Thread_Control::ACE_Thread_Control (ACE_Thread_Manager *t,
                                        int insert)
  : 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);
    }
}

// Automatically kill thread on exit.

ACE_Thread_Control::~ACE_Thread_Control (void)
{
  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 */
}

// Exit from thread (but clean up first).

void *
ACE_Thread_Control::exit (void *exit_status, int do_thr_exit)
{
  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;
    }
}