~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to ace/Future_Set.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Future.cpp
2
 
// Future_Set.cpp,v 4.12 2000/05/17 23:31:05 brunsch Exp
3
 
 
4
 
#ifndef ACE_FUTURE_SET_CPP
5
 
#define ACE_FUTURE_SET_CPP
6
 
 
7
 
#include "ace/Future_Set.h"
8
 
 
9
 
#if !defined (ACE_LACKS_PRAGMA_ONCE)
10
 
#pragma once
11
 
#endif /* ACE_LACKS_PRAGMA_ONCE */
12
 
 
13
 
ACE_RCSID (ace, Future_Set, "Future_Set.cpp,v 4.12 2000/05/17 23:31:05 brunsch Exp")
14
 
 
15
 
#if defined (ACE_HAS_THREADS)
16
 
 
17
 
template <class T>
18
 
ACE_Future_Set<T>::ACE_Future_Set (ACE_Message_Queue<ACE_SYNCH> *new_queue)
19
 
  : delete_queue_ (0)
20
 
{
21
 
  if (new_queue)
22
 
    this->future_notification_queue_ = new_queue;
23
 
  else
24
 
    {
25
 
      ACE_NEW (this->future_notification_queue_,
26
 
               ACE_Message_Queue<ACE_SYNCH>);
27
 
      this->delete_queue_ = 1;
28
 
    }
29
 
}
30
 
 
31
 
template <class T>
32
 
ACE_Future_Set<T>::~ACE_Future_Set (void)
33
 
{
34
 
  // Detach ourselves from all remaining futures, if any, in our map.
35
 
  ACE_TYPENAME FUTURE_HASH_MAP::iterator iterator =
36
 
    this->future_map_.begin ();
37
 
 
38
 
  ACE_TYPENAME FUTURE_HASH_MAP::iterator end =
39
 
    this->future_map_.end ();
40
 
 
41
 
  for (;
42
 
       iterator != end;
43
 
       ++iterator)
44
 
    {
45
 
      FUTURE_HOLDER *future_holder = (*iterator).int_id_;
46
 
      future_holder->item_.detach (this);
47
 
      delete future_holder;
48
 
    }
49
 
 
50
 
  if (this->delete_queue_ != 0)
51
 
    delete this->future_notification_queue_;
52
 
}
53
 
 
54
 
template <class T> int
55
 
ACE_Future_Set<T>::is_empty () const
56
 
{
57
 
  return (((ACE_Future_Set<T>*)this)->future_map_.current_size () == 0 );
58
 
}
59
 
 
60
 
template <class T> int
61
 
ACE_Future_Set<T>::insert (ACE_Future<T> &future)
62
 
{
63
 
  FUTURE_HOLDER *future_holder;
64
 
  ACE_NEW_RETURN (future_holder,
65
 
                  FUTURE_HOLDER (future),
66
 
                  -1);
67
 
 
68
 
  FUTURE_REP *future_rep = future.get_rep ();
69
 
  int result = this->future_map_.bind (future_rep,
70
 
                                       future_holder);
71
 
 
72
 
  // If a new map entry was created, then attach to the future,
73
 
  // otherwise we were already attached to the future or some error
74
 
  // occurred so just delete the future holder.
75
 
  if ( result == 0 )
76
 
    // Attach ourself to the ACE_Futures list of observer
77
 
    future.attach (this);
78
 
  else
79
 
    delete future_holder;
80
 
 
81
 
  return result;
82
 
}
83
 
 
84
 
template <class T> void
85
 
ACE_Future_Set<T>::update (const ACE_Future<T> &future)
86
 
{
87
 
  ACE_Message_Block *mb;
88
 
  FUTURE &local_future = ACE_const_cast (ACE_Future<T> &, future);
89
 
 
90
 
  ACE_NEW (mb,
91
 
           ACE_Message_Block ((char *) local_future.get_rep (), 0));
92
 
 
93
 
  // Enqueue in priority order.
94
 
  this->future_notification_queue_->enqueue (mb, 0);
95
 
}
96
 
 
97
 
template <class T> int
98
 
ACE_Future_Set<T>::next_readable (ACE_Future<T> &future,
99
 
                                  ACE_Time_Value *tv)
100
 
{
101
 
  if (this->is_empty ())
102
 
    return 0;
103
 
 
104
 
  ACE_Message_Block *mb = 0;
105
 
  FUTURE_REP *future_rep = 0;
106
 
 
107
 
  // Wait for a "readable future" signal from the message queue.
108
 
  if (this->future_notification_queue_->dequeue_head (mb,
109
 
                                                      tv) != -1)
110
 
    {
111
 
      // Extract future rep from the message block.
112
 
      future_rep =
113
 
        ACE_reinterpret_cast (FUTURE_REP *,
114
 
                              mb->base ());
115
 
 
116
 
      // Delete the message block.
117
 
      mb->release ();
118
 
    }
119
 
  else
120
 
    return 0;
121
 
 
122
 
  // Remove the hash map entry with the specified future rep from our map.
123
 
  FUTURE_HOLDER *future_holder;
124
 
  if ( this->future_map_.find (future_rep,
125
 
                               future_holder) != -1 )
126
 
    {
127
 
      future = future_holder->item_;
128
 
      this->future_map_.unbind (future_rep);
129
 
      delete future_holder;
130
 
      return 1;
131
 
    }
132
 
 
133
 
  return 0;
134
 
}
135
 
 
136
 
#endif /* ACE_HAS_THREADS */
137
 
#endif /* ACE_FUTURE_SET_CPP */