summaryrefslogtreecommitdiff
path: root/ACE/apps/JAWS2/JAWS/Waiter.cpp
blob: 4b6b1aec4b80794312a2e7c486c9d45416f69c3e (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
// $Id$

#include "ace/Proactor.h"

#include "JAWS/Waiter.h"
#include "JAWS/IO_Handler.h"



JAWS_Waiter::JAWS_Waiter (void)
  : iter_ (*this)
{
}

JAWS_Waiter::~JAWS_Waiter (void)
{
}

JAWS_Waiter_Base_Iterator &
JAWS_Waiter::iter (void)
{
  return this->iter_;
}

int
JAWS_Waiter::index (void)
{
#if 0
  // A future version of ACE will support this.
  ACE_Thread_ID tid = ACE_OS::thr_self ();
#else
  // Do it this way for now
  ACE_thread_t thr_name;
  thr_name = ACE_OS::thr_self ();

  JAWS_Thread_ID tid (thr_name);
#endif /* 0 */

  return JAWS_Waiter_Base::index (tid);
}

JAWS_IO_Handler *
JAWS_Waiter::wait_for_completion (int i)
{
  JAWS_IO_Handler *ioh;
  JAWS_IO_Handler **iohptr;

  iohptr = (i >= 0) ? this->find_by_index (i) : this->find_by_index (this->index ());

  while (*iohptr == 0)
    if (ACE_Proactor::instance ()->handle_events () == -1)
      {
        ACE_ERROR ((LM_ERROR, "%p\n", "JAWS_Waiter::wait_for_completion"));
        return 0;
      }

  ioh = *iohptr;
  *iohptr = 0;

  ioh->lock ();
  ioh->release ();
  return ioh;
}