]>
Commit | Line | Data |
---|---|---|
88399079 | 1 | // condition_variable -*- C++ -*- |
68a97d24 | 2 | |
8fc81078 | 3 | // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
68a97d24 BK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
68a97d24 BK |
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 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
68a97d24 BK |
24 | |
25 | #include <condition_variable> | |
26 | ||
7b800287 CF |
27 | #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) |
28 | ||
53dc5044 PC |
29 | _GLIBCXX_BEGIN_NAMESPACE(std) |
30 | ||
50a681c4 | 31 | condition_variable::condition_variable() throw () |
68a97d24 | 32 | { |
7b800287 | 33 | #ifdef __GTHREAD_COND_INIT |
f7459b6c | 34 | __native_type __tmp = __GTHREAD_COND_INIT; |
68a97d24 | 35 | _M_cond = __tmp; |
7b800287 | 36 | #else |
8fc81078 | 37 | int __e = __gthread_cond_init(&_M_cond, 0); |
7b800287 CF |
38 | |
39 | if (__e) | |
68a97d24 | 40 | __throw_system_error(__e); |
68a97d24 BK |
41 | #endif |
42 | } | |
43 | ||
50a681c4 | 44 | condition_variable::~condition_variable() throw () |
68a97d24 | 45 | { |
68a97d24 | 46 | // XXX no thread blocked |
7b800287 | 47 | /* int __e = */ __gthread_cond_destroy(&_M_cond); |
68a97d24 | 48 | // if __e == EBUSY then blocked |
68a97d24 BK |
49 | } |
50 | ||
7b800287 CF |
51 | void |
52 | condition_variable::wait(unique_lock<mutex>& __lock) | |
53 | { | |
54 | int __e = __gthread_cond_wait(&_M_cond, __lock.mutex()->native_handle()); | |
55 | ||
56 | if (__e) | |
d5cf2021 | 57 | __throw_system_error(__e); |
7b800287 | 58 | } |
d5cf2021 BK |
59 | |
60 | void | |
68a97d24 | 61 | condition_variable::notify_one() |
d5cf2021 | 62 | { |
7b800287 | 63 | int __e = __gthread_cond_signal(&_M_cond); |
68a97d24 BK |
64 | |
65 | // XXX not in spec | |
66 | // EINVAL | |
7b800287 | 67 | if (__e) |
68a97d24 | 68 | __throw_system_error(__e); |
68a97d24 BK |
69 | } |
70 | ||
d5cf2021 | 71 | void |
68a97d24 | 72 | condition_variable::notify_all() |
d5cf2021 | 73 | { |
7b800287 | 74 | int __e = __gthread_cond_broadcast(&_M_cond); |
68a97d24 BK |
75 | |
76 | // XXX not in spec | |
77 | // EINVAL | |
7b800287 | 78 | if (__e) |
68a97d24 | 79 | __throw_system_error(__e); |
68a97d24 BK |
80 | } |
81 | ||
50a681c4 | 82 | condition_variable_any::condition_variable_any() throw () |
b7200e3f | 83 | { } |
d5cf2021 | 84 | |
50a681c4 | 85 | condition_variable_any::~condition_variable_any() throw () |
b7200e3f | 86 | { } |
53dc5044 PC |
87 | |
88 | _GLIBCXX_END_NAMESPACE | |
68a97d24 | 89 | |
7b800287 | 90 | #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 |