summaryrefslogtreecommitdiff
path: root/ace/Base_Thread_Adapter.cpp
blob: 23e3556fd9a72729b3bad9f621ceca1d0117129a (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// $Id$

#include "ace/Base_Thread_Adapter.h"

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

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

#if defined (ACE_HAS_TSS_EMULATION)
#  include "ace/OS_NS_Thread.h"
#endif /* ACE_HAS_TSS_EMULATION */

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_INIT_LOG_MSG_HOOK     ACE_Base_Thread_Adapter::init_log_msg_hook_ = 0;
ACE_INHERIT_LOG_MSG_HOOK  ACE_Base_Thread_Adapter::inherit_log_msg_hook_ = 0;
ACE_CLOSE_LOG_MSG_HOOK    ACE_Base_Thread_Adapter::close_log_msg_hook_ = 0;
ACE_SYNC_LOG_MSG_HOOK     ACE_Base_Thread_Adapter::sync_log_msg_hook_ = 0;
ACE_THR_DESC_LOG_MSG_HOOK ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_ = 0;

ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter (
     ACE_THR_FUNC user_func,
     void *arg,
     ACE_THR_C_FUNC entry_point,
     ACE_OS_Thread_Descriptor *td
#if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
     , ACE_SEH_EXCEPT_HANDLER selector
     , ACE_SEH_EXCEPT_HANDLER handler
#endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
   )
  : user_func_ (user_func)
  , arg_ (arg)
  , entry_point_ (entry_point)
  , thr_desc_ (td)
{
  ACE_OS_TRACE ("ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter");

  if (ACE_Base_Thread_Adapter::init_log_msg_hook_ != 0)
    (*ACE_Base_Thread_Adapter::init_log_msg_hook_) (
          this->log_msg_attributes_
# if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
          , selector
          , handler
# endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */
          );
#ifdef ACE_USES_GPROF
  getitimer (ITIMER_PROF, &itimer_);
#endif // ACE_USES_GPROF
}

ACE_Base_Thread_Adapter::~ACE_Base_Thread_Adapter (void)
{
}

void
ACE_Base_Thread_Adapter::inherit_log_msg (void)
{
  if (ACE_Base_Thread_Adapter::inherit_log_msg_hook_ != 0)
    (*ACE_Base_Thread_Adapter::inherit_log_msg_hook_)(
           this->thr_desc_,
           this->log_msg_attributes_);
}

void
ACE_Base_Thread_Adapter::close_log_msg (void)
{
  if (ACE_Base_Thread_Adapter::close_log_msg_hook_ != 0)
    (*ACE_Base_Thread_Adapter::close_log_msg_hook_) ();
}

void
ACE_Base_Thread_Adapter::sync_log_msg (const ACE_TCHAR *prg)
{
  if (ACE_Base_Thread_Adapter::sync_log_msg_hook_ != 0)
    (*ACE_Base_Thread_Adapter::sync_log_msg_hook_) (prg);
}

ACE_OS_Thread_Descriptor *
ACE_Base_Thread_Adapter::thr_desc_log_msg (void)
{
  if (ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_ != 0)
    return (*ACE_Base_Thread_Adapter::thr_desc_log_msg_hook_) ();
  return 0;
}

ACE_END_VERSIONED_NAMESPACE_DECL

// Run the thread entry point for the <ACE_Thread_Adapter>.  This must
// be an extern "C" to make certain compilers happy...

#if defined (ACE_PSOS)
extern "C" void
ACE_THREAD_ADAPTER_NAME (unsigned long args)
{
  ACE_OS_TRACE ("ACE_THREAD_ADAPTER_NAME");

#if defined (ACE_HAS_TSS_EMULATION)
  // As early as we can in the execution of the new thread, allocate
  // its local TS storage.  Allocate it on the stack, to save dynamic
  // allocation/dealloction.
  void *ts_storage[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX];
  ACE_TSS_Emulation::tss_open (ts_storage);
#endif /* ACE_HAS_TSS_EMULATION */

  ACE_Base_Thread_Adapter * const thread_args =
    static_cast<ACE_Base_Thread_Adapter *> (args);

  // Invoke the user-supplied function with the args.
  thread_args->invoke ();
}
#else /* ! defined (ACE_PSOS) */
extern "C" ACE_THR_FUNC_RETURN
ACE_THREAD_ADAPTER_NAME (void *args)
{
  ACE_OS_TRACE ("ACE_THREAD_ADAPTER_NAME");

#if defined (ACE_HAS_TSS_EMULATION)
  // As early as we can in the execution of the new thread, allocate
  // its local TS storage.  Allocate it on the stack, to save dynamic
  // allocation/dealloction.
  void *ts_storage[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX];
  ACE_TSS_Emulation::tss_open (ts_storage);
#endif /* ACE_HAS_TSS_EMULATION */

  ACE_Base_Thread_Adapter * const thread_args =
    static_cast<ACE_Base_Thread_Adapter *> (args);

#ifdef ACE_USES_GPROF
  setitimer (ITIMER_PROF, thread_args->timerval (), 0);
#endif // ACE_USES_GPROF

  // Invoke the user-supplied function with the args.
  ACE_THR_FUNC_RETURN status = thread_args->invoke ();

  return status;
}
#endif /* ACE_PSOS */