OSDN Git Service

2008-05-25 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / condition_variable
1 // <condition_variable> -*- C++ -*-
2
3 // Copyright (C) 2008 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file condition_variable
31  *  This is a Standard C++ Library header.
32  */
33
34 #ifndef _GLIBCXX_CONDITION_VARIABLE
35 #define _GLIBCXX_CONDITION_VARIABLE 1
36
37 #pragma GCC system_header
38
39 #ifndef __GXX_EXPERIMENTAL_CXX0X__
40 # include <c++0x_warning.h>
41 #else
42
43 #include <mutex> // unique_lock
44
45 namespace std 
46 {
47   // XXX
48   class system_time;
49
50   /// condition_variable
51   class condition_variable
52   {
53   public:
54
55 #if __GTHREAD_HAS_COND
56     typedef __gthread_cond_t native_handle_type;
57 #else
58     typedef int native_handle_type;
59 #endif
60
61     condition_variable();
62     ~condition_variable();
63
64     void 
65     notify_one();
66
67     void 
68     notify_all();
69
70     void 
71     wait(unique_lock<mutex>& __lock);
72
73     template<typename _Predicate>
74       void 
75       wait(unique_lock<mutex>& __lock, _Predicate __p)
76       {
77         while (!__p())
78           wait(__lock);
79       }
80   
81     template<typename _Duration>
82       bool 
83       timed_wait(unique_lock<mutex>& __lock, const _Duration& __rtime);
84
85     bool 
86     timed_wait(unique_lock<mutex>& __lock, const system_time& __atime);
87
88     template<typename _Predicate>
89       bool 
90       timed_wait(unique_lock<mutex>& __lock, const system_time& __atime,
91                  _Predicate pred);
92
93     template<typename _Duration, typename _Predicate>
94       bool 
95       timed_wait(unique_lock<mutex>& __lock, const _Duration& __rtime, 
96                  _Predicate pred);
97
98     native_handle_type 
99     native_handle() { return _M_cond; }
100
101   private:
102     native_handle_type  _M_cond;
103     condition_variable(const condition_variable&);
104     condition_variable& operator=(const condition_variable&);
105   };
106
107   /// condition_variable_any
108   // Like above, only mutex may not have try_lock.
109   class condition_variable_any
110   {
111   public:
112 #if __GTHREAD_HAS_COND
113     typedef __gthread_cond_t native_handle_type;
114 #else
115     typedef int native_handle_type;
116 #endif
117
118     condition_variable_any();
119     ~condition_variable_any();
120
121     void 
122     notify_one();
123
124     void 
125     notify_all();
126
127     template<typename _Lock>
128       void 
129       wait(_Lock& __lock);
130
131     template<typename _Lock, typename _Predicate>
132       void 
133       wait(_Lock& __lock, _Predicate __p);
134
135     template<typename _Lock>
136       bool 
137       timed_wait(_Lock& __lock, const system_time& __atime);
138
139     template<typename _Lock, typename _Duration>
140       bool 
141       timed_wait(_Lock& __lock, const _Duration& __rtime);
142
143     template<typename _Lock, typename _Predicate>
144       bool 
145       timed_wait(_Lock& __lock, const system_time& __atime, _Predicate __p);
146
147     template<typename _Lock, typename _Duration, typename _Predicate>
148       bool 
149       timed_wait(_Lock& __lock, const _Duration& __rtime, _Predicate __p);
150
151     native_handle_type 
152     native_handle() { return _M_cond; }
153
154   private:
155     native_handle_type  _M_cond;
156     condition_variable_any(const condition_variable_any&);
157     condition_variable_any& operator=(const condition_variable_any&);
158   };
159
160 }
161
162 #endif // __GXX_EXPERIMENTAL_CXX0X__
163
164 #endif // _GLIBCXX_CONDITION_VARIABLE