STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
request_with_waiters.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * lib/io/request_with_waiters.cpp
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
17 #include <stxxl/bits/parallel.h>
18 
19 #include <algorithm>
20 #include <functional>
21 
22 
24 
25 bool request_with_waiters::add_waiter(onoff_switch* sw)
26 {
27  // this lock needs to be obtained before poll(), otherwise a race
28  // condition might occur: the state might change and notify_waiters()
29  // could be called between poll() and insert() resulting in waiter sw
30  // never being notified
31  scoped_mutex_lock lock(waiters_mutex);
32 
33  if (poll()) // request already finished
34  {
35  return true;
36  }
37 
38  waiters.insert(sw);
39 
40  return false;
41 }
42 
43 void request_with_waiters::delete_waiter(onoff_switch* sw)
44 {
45  scoped_mutex_lock lock(waiters_mutex);
46  waiters.erase(sw);
47 }
48 
49 void request_with_waiters::notify_waiters()
50 {
51  scoped_mutex_lock lock(waiters_mutex);
52  std::for_each(waiters.begin(),
53  waiters.end(),
54  std::mem_fun(&onoff_switch::on)
56 }
57 
58 /*
59 int request_with_waiters::nwaiters()
60 {
61  scoped_mutex_lock lock(waiters_mutex);
62  return waiters.size();
63 }
64 */
65 
67 // vim: et:ts=4:sw=4
UnaryFunction for_each(ExtIterator begin, ExtIterator end, UnaryFunction functor, int_type nbuffers=0)
External equivalent of std::for_each, see stxxl::for_each.
Definition: scan.h:51
Aquire a lock that&#39;s valid until the end of scope.
Definition: mutex.h:106
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
#define _STXXL_FORCE_SEQUENTIAL
Definition: parallel.h:51
#define STXXL_END_NAMESPACE
Definition: namespace.h:17