STXXL
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
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
14
#include <
stxxl/bits/common/mutex.h
>
15
#include <
stxxl/bits/common/onoff_switch.h
>
16
#include <
stxxl/bits/io/request_with_waiters.h
>
17
#include <
stxxl/bits/parallel.h
>
18
19
#include <
algorithm
>
20
#include <functional>
21
22
23
STXXL_BEGIN_NAMESPACE
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)
55
_STXXL_FORCE_SEQUENTIAL
);
56
}
57
58
/*
59
int request_with_waiters::nwaiters()
60
{
61
scoped_mutex_lock lock(waiters_mutex);
62
return waiters.size();
63
}
64
*/
65
66
STXXL_END_NAMESPACE
67
// vim: et:ts=4:sw=4
onoff_switch.h
stxxl::onoff_switch
Definition:
onoff_switch.h:29
request_with_waiters.h
stxxl::for_each
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
parallel.h
stxxl::scoped_mutex_lock
Aquire a lock that's valid until the end of scope.
Definition:
mutex.h:106
STXXL_BEGIN_NAMESPACE
#define STXXL_BEGIN_NAMESPACE
Definition:
namespace.h:16
mutex.h
algorithm
_STXXL_FORCE_SEQUENTIAL
#define _STXXL_FORCE_SEQUENTIAL
Definition:
parallel.h:51
STXXL_END_NAMESPACE
#define STXXL_END_NAMESPACE
Definition:
namespace.h:17
lib
io
request_with_waiters.cpp
STXXL 1.4.0
- Generated on Thu Dec 12 2013 15:30:26 for STXXL by
1.8.5