summaryrefslogtreecommitdiff
path: root/ace/Thread_Control.h
blob: fbf8f0f213ff40667cb3380ec0726aca3b3ab229 (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

//=============================================================================
/**
 *  @file    Thread_Control.h
 *
 *  $Id$
 *
 *  @author Carlos O'Ryan <coryan@uci.edu>
 */
//=============================================================================


#ifndef ACE_THREAD_CONTROL_H
#define ACE_THREAD_CONTROL_H
#include "ace/pre.h"

#include "ace/config-all.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#if !defined (ACE_LEGACY_MODE)
#  include "ace/OS.h"
#endif  /* ACE_LEGACY_MODE */

class ACE_Thread_Manager;

/**
 * @class ACE_Thread_Control
 *
 * @brief 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>.
 */
class ACE_Export ACE_Thread_Control
{
public:
  /// Initialize the thread control object.  If <insert> != 0, then
  /// register the thread with the Thread_Manager.
  ACE_Thread_Control (ACE_Thread_Manager *tm = 0,
                      int insert = 0);

  /// Remove the thread from its associated <Thread_Manager> and exit
  /// the thread if <do_thr_exit> is enabled.
  ~ACE_Thread_Control (void);

  /// Remove this thread from its associated <Thread_Manager> and exit
  /// the thread if <do_thr_exit> is enabled.
  void *exit (void *status,
              int do_thr_exit);

  /// Store the <Thread_Manager> and use it to register ourselves for
  /// correct shutdown.
  int insert (ACE_Thread_Manager *tm, int insert = 0);

  /// Returns the current <Thread_Manager>.
  ACE_Thread_Manager *thr_mgr (void);

  /// Atomically set a new <Thread_Manager> and return the old
  /// <Thread_Manager>.
  ACE_Thread_Manager *thr_mgr (ACE_Thread_Manager *);

  /// Set the exit status (and return existing status).
  void *status (void *status);

  /// Get the current exit status.
  void *status (void);

  /// Dump the state of an object.
  void dump (void) const;

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Pointer to the thread manager for this block of code.
  ACE_Thread_Manager *tm_;

  /// Keeps track of the exit status for the thread.
  void *status_;
};

# if defined (ACE_HAS_INLINED_OSCALLS)
#   if defined (ACE_INLINE)
#     undef ACE_INLINE
#   endif /* ACE_INLINE */
#   define ACE_INLINE inline
#   include "ace/Thread_Control.inl"
# endif /* ACE_HAS_INLINED_OSCALLS */

#include "ace/post.h"
#endif /* ACE_THREAD_CONTROL_H */