summaryrefslogtreecommitdiff
path: root/TAO/tao/CSD_ThreadPool/CSD_TP_Synch_Helper.h
blob: 2056f1ab032158dda8fd7c4d44ac253e5b44af06 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    CSD_TP_Synch_Helper.h
 *
 *  $Id$
 *
 *  @author  Tim Bradley <bradley_t@ociweb.com>
 */
//=============================================================================

#ifndef TAO_CSD_TP_SYNCH_HELPER_H
#define TAO_CSD_TP_SYNCH_HELPER_H

#include /**/ "ace/pre.h"

#include "tao/CSD_ThreadPool/CSD_TP_Export.h"
#include "tao/Condition.h"

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

#include "ace/Synch.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  namespace CSD
  {

    /**
     * @class TP_Synch_Helper
     *
     * @brief Helper class for synchronous requests to block the requesting
     *        thread until the appropriate time (when it will be un-blocked).
     *
     * TBD - Description here
     *
     */
    class TAO_CSD_TP_Export TP_Synch_Helper
    {
    public:

      /// Constructor.  Sets initial state to PENDING.
      TP_Synch_Helper();

      /// Destructor.
      ~TP_Synch_Helper();

      /// Returns true if the helper state is DISPATCHED, and false if
      /// the helper state is CANCELLED.  However, if the helper state
      /// is PENDING, then this method will block the calling thread
      /// until the state changes to something other than PENDING
      /// (ie, DISPATCHED or CANCELLED).
      bool wait_while_pending();

      /// Change the state of this helper to DISPATCHED, which will cause
      /// wait_while_pending() to unblock.
      void dispatched();

      /// Change the state of this helper to CANCELLED, which will cause
      /// wait_while_pending() to unblock.
      void cancelled();


    private:

      /// Enumeration Type for all possible states of this helper object.
      enum HelperState
      {
        PENDING,
        DISPATCHED,
        CANCELLED
      };

      /// Thread lock type
      typedef ACE_SYNCH_MUTEX LockType;

      /// Thread guard type
      typedef ACE_Guard<LockType> GuardType;

      /// Thread condition type
      typedef TAO_Condition<LockType> ConditionType;

      /// Lock used to protect the state and condition.
      LockType lock_;

      /// Used to denote the state of the request dispatching.
      HelperState state_;

      /// The condition used to block the calling thread until the
      /// state is something other than the PENDING state.
      ConditionType condition_;
    };

  }
}

TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
# include "tao/CSD_ThreadPool/CSD_TP_Synch_Helper.inl"
#endif /* __ACE_INLINE__ */

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

#endif /* TAO_CSD_TP_SYNCH_HELPER_H */