Skip to content

Commit

Permalink
[FOLD]
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Oct 6, 2016
1 parent 37b361b commit 9180730
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 85 deletions.
102 changes: 18 additions & 84 deletions extras/beast/server/io_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,116 +24,49 @@ class io_object

/** Manages a set of objects performing asynchronous I/O.
*/
class io_list final
template<class Derived>
class io_list
{
private:
template<class = void>
void destroy();

std::mutex m_;
std::size_t n_ = 0;
bool closed_ = false;
std::condition_variable cv_;
boost::container::flat_map<io_object*,
std::weak_ptr<io_object>> map_;
std::function<void(void)> f_;

public:
io_list() = default;

/** Destroy the list.
Effects:
Closes the io_list if it was not previously
closed. No finisher is invoked in this case.
Blocks until all work is destroyed.
*/
~io_list()
{
destroy();
}

/** Return `true` if the list is closed.
Thread Safety:
Undefined result if called concurrently
with close().
*/
bool
closed() const
{
return closed_;
}

/** Create associated work if not closed.
Requirements:
`std::is_base_of_v<work, T> == true`
Thread Safety:
May be called concurrently.
Effects:
Atomically creates, inserts, and returns new
work T, or returns nullptr if the io_list is
closed,
If the call succeeds and returns a new object,
it is guaranteed that a subsequent call to close
will invoke work::close on the object.
*/
template <class T, class... Args>
std::shared_ptr<T>
emplace(Args&&... args);

/** Cancel active I/O.
Thread Safety:
May not be called concurrently.
Effects:
Associated work is closed.
Finisher if provided, will be called when
all associated work is destroyed. The finisher
may be called from a foreign thread, or within
the call to this function.
Only the first call to close will set the
finisher.
No effect after the first call.
*/
template<class Finisher>
void
close(Finisher&& f);

void
close()
{
close([]{});
}
close();

/** Block until the io_list stops.
Effects:
The caller is blocked until the io_list is
closed and all associated work is destroyed.
Thread safety:
May be called concurrently.
Preconditions:
No call to io_service::run on any io_service
used by work objects associated with this io_list
exists in the caller's call stack.
*/
template<class = void>
void
join();

private:
void destroy();

std::mutex m_;
std::size_t n_ = 0;
bool closed_ = false;
std::condition_variable cv_;
boost::container::flat_map<io_object*,
std::weak_ptr<io_object>> map_;
std::function<void(void)> f_;
};

//------------------------------------------------------------------------------

#if 0

template<class>
void
io_list::work::destroy()
Expand Down Expand Up @@ -226,7 +159,8 @@ io_list::join()
});
}


#endif

} // beast

#endif
3 changes: 2 additions & 1 deletion test/core/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

#include <beast/unit_test/suite.hpp>

#include <beast/server/io_list.hpp>
#include <boost/asio.hpp>

namespace beast {

template<class Derived>
class basic_listener
{
Expand Down

0 comments on commit 9180730

Please sign in to comment.