Commit graph

171 commits

Author SHA1 Message Date
fghzxm a87e97fe5b generator_promise::{initial,final}_suspend() can be noexcept 2020-10-12 10:43:10 -07:00
Andreas Buhr 8929f9cc40 Small fixes to make gcc happy 2020-10-12 10:42:13 -07:00
Andreas Buhr fdb7a74f63 translate "for co_await" to regular for loops using "co_await"
"for co_await" was in the coroutine-ts but did not make it into
the C++20 standard. This patch translates the "for co_await"
which were used to standard for loops using "co_await".
This is necessary to compile on MSVC 1928 in with c++-latest.
2020-10-12 10:38:08 -07:00
yaoxinliu 69e575480a avoid the compiler warning of -Wreorder 2020-05-29 17:48:20 -07:00
yaoxinliu 932f08586c fix a bug in ipv4_address::is_private_network() 2020-05-29 17:48:20 -07:00
Gomez 92892f31d0 Make recursive_generator [[nodiscard]] like generator (ditto shared_task) 2020-02-27 18:18:01 -08:00
Billy O'Neal 926b032de2 Avoid std::atomic_init deprecated by P0883. (#140)
Resolves #139
2020-01-28 14:05:38 -08:00
denchat 00b34af58e gcc complains using std::invoke
without <functional>
2020-01-17 07:39:29 -08:00
Lewis Baker 56d3a0bfaa
Fix typo in generator::operator== 2019-10-29 15:31:54 -07:00
Lewis Baker e2cfe2bebd
Fix generator<T> to satisfy the range concept
* Iterator type needed to support equality comparisons both it == sentinel and sentinel == it.
* difference_type needed to be a signed integer (it was an unsigned size_t)
2019-10-29 13:48:25 -07:00
Lewis Baker 150220b391
Merge pull request #122 from denchat/patch-7
Suppress warning about unused parameter with `[[maybe_unused]]`.
2019-09-03 07:17:20 -07:00
Lewis Baker a45cac7ad3
Merge pull request #123 from denchat/patch-8
Add missing `#include <exception>` in sync_wait_task.hpp needed for std::exception_ptr.
2019-09-03 07:15:23 -07:00
denchat 75ab993a70
iterator_category needs <iterator> 2019-09-02 13:07:24 +07:00
denchat cfc01521aa
m_exception is std::exception_ptr 2019-09-02 12:36:53 +07:00
denchat e7407b3d99
await_suspend never actually uses input producer
suppress warning with [[maybe_unused]]
2019-09-02 01:38:43 +07:00
Joseph Malle 3c60ea2df0 Annotate async_generator, generator, and task with [[nodiscard]] 2019-04-05 15:15:20 +02:00
Lewis Baker 17bd85ac36
Merge pull request #92 from lewissbaker/disruptor
Add synchronisation primitives for ring-buffered producer/consumer
2019-01-21 22:27:13 -08:00
Lewis Baker 1f3366ddb6 Make recursive_generator<T> satisfy the Range concept.
Fix recursive_generator<T&&> to have a 'reference' type of T&&.
2019-01-18 22:28:18 -08:00
Lewis Baker 8e9db4c48a Perfectly-forward generator<T>::iterator::reference type to fmap(). 2019-01-18 22:14:12 -08:00
Lewis Baker 83538a69ef Improve generator<T> codegen on Clang.
Use a separate 'generator_sentinel' type for the end() iterator.
This avoids some mutation of the coroutine_handle member of the
iterator and turns the comparison into a call to .done().

Seems to allow better allocation elision of the coroutine frame
in some cases when building under Clang.
2019-01-18 21:40:53 -08:00
Lewis Baker 73f75a3efe
Merge branch 'master' into disruptor 2019-01-15 10:53:09 -08:00
Lewis Baker 59f2e779a2 Allow co_yield of rvalue from generator<T&>
Need to define `yield_value()` overload taking rvalue reference for all types.
2019-01-10 21:13:12 -08:00
Lewis Baker 64b0572fa8 Fix generator<T&&>
Add missing a cast to reference_type.
Fix `generator<T&&>::iterator::reference` typedef to be `T&&`.
2019-01-10 21:13:12 -08:00
Lewis Baker c6a25679f7 Fix inability to 'co_yield' a non-const T& from generator<const T>.
Fixes #88.
2019-01-01 21:16:06 -08:00
Lewis Baker 62110e8538
Fixes to allow generator<T> to implement Range concept
Range concept from range-v3 requires the iterator to:
- be default constructible
- support post-increment operator
2018-11-16 15:39:06 -08:00
Lewis Baker a44c6895f7 Fix some 2-phase lookup issues that caused Clang build to break. 2018-10-31 20:18:56 -07:00
Lewis Baker 38d5af8648
Fix typo. 2018-10-31 10:26:02 -07:00
Lewis Baker 3cdc22bbed Make the ring-buffer wait operations take a scheduler.
The awaiting coroutine will be resumed using the scheduler if it
is suspended waiting for a sequence number. This simplifies code
as the caller doesn't need to remember to manually reschedule.
Forcing a scheduler to provided also prevents the producer/consumer
coroutines from effectively becoming single-threaded.
2018-10-30 23:31:36 -07:00
Lewis Baker 8745d1b6d6 Change ring-buffer sequencer tests to use static_thread_pool.
This will allow them to be run on Linux platforms.

Change producer in multi-producer examples to reschedule onto the
thread-pool if probably suspended. This allows producer and
consumer to run concurrently rather than the consumer executing
the producer inline.
2018-10-27 12:06:14 -07:00
Lewis Baker dd617acb99 Add some more API docs to sequencer classes. 2018-10-27 12:02:10 -07:00
Lewis Baker 0f082f4eaf Fix bug in sequence_barrier.
It was incorrectly calculating the minimum target sequence number
for requeued awaiters which could result in missed wakeups.
2018-10-27 11:50:18 -07:00
Lewis Baker 0a6028ce37 Fix bug in multi_producer_sequence that could result in requeueing
the same waiter multiple times.

The requeue list wasn't being cleared when going around the loop.
2018-10-27 11:32:05 -07:00
Lewis Baker f8a4c5ed8a Work around missing std::hardware_destructive_interference_size.
Use new CPPCORO_CPU_CACHE_LINE instead.

Clang/libc++ doesn't define this symbol so just use a constant
on platforms other than MSVC.
2018-10-22 22:31:01 -07:00
Lewis Baker e25d12f06e
Merge branch 'master' into disruptor 2018-10-21 09:02:44 -07:00
Lewis Baker 16851b30d2 Work-in-progress round_robin_scheduler class. 2018-10-04 07:42:37 -07:00
Lewis Baker 0330e66fdb Fix typo in async_generator's fmap definition. 2018-10-04 07:28:44 -07:00
Lewis Baker b04d53c36d Add symmetric-transfer versions of task/async_generator for clang.
Switch based on the new CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER
macro which is currently only defined for Clang >= 7.
2018-10-03 21:58:12 -07:00
Lewis Baker f6ceb21e37 Add async_scope class for waiting on variable number of tasks. 2018-09-09 23:12:24 -07:00
Lewis Baker 151cc57b13 Fix comment copy/paste typo. 2018-09-09 23:12:23 -07:00
Lewis Baker 490e1e44d3 Remove unnecessary forward declaration. 2018-09-09 23:12:23 -07:00
Lewis Baker 4a284c8ef5 Work around MSVC codegen bug that caused socket tests to hang
Declare win32_overlapped_operation's await_suspend() methods as
noinline to work around a bad codegen bug under x86/x64 optimised
builds under MSVC 2017.7 and 2017.8.
2018-09-07 08:35:35 -07:00
Lewis Baker d965af8836 Add workaround for MSVC bad codegen bug.
Mark task<T>'s final_awaitable::await_suspend() method as noinline.

This fixes a crash in the multi-threaded async_auto_reset_event
tests under x86 optimised builds under MSVC 2017.8.
2018-09-07 08:23:37 -07:00
Lewis Baker 02d78fb79a Fix typo in comment. 2018-09-07 07:49:26 -07:00
Lewis Baker e23897adc4
Merge branch 'master' into sockets2 2018-08-20 21:07:17 -07:00
Lewis Baker 8357f3a9eb
Merge branch 'master' into static_thread_pool 2018-08-20 12:58:58 -07:00
Lewis Baker 3864a047db Workaround MSVC bug that breaks when_all() and sync_wait().
MSVC 2017.8 generates bad code for when_all() and sync_wait()
that causes a crash due to it resuming the coroutine at the
wrong suspend-point in the expression 'co_yield co_await x'.

Work around this by manually calling promise.yield_value()
instead of using co_yield.
2018-08-17 07:36:35 -07:00
Lewis Baker 868c0f427d Merge branch 'master' into generic_ops 2018-08-15 22:18:25 -07:00
Lewis Baker b2b9c66fb0 Make static_thread_pool::schedule() declared [[nodiscard]] 2018-08-09 08:44:07 -07:00
Lewis Baker 0bf30e7d1a Declare await_suspend() noinline to workaround msvc bug.
MSVC was inlining local variables in await_suspend() into the
coroutine frame of the caller which was breaking the guarantees
required by the for_each_async() test.
2018-08-06 08:45:17 -07:00
Lewis Baker 9e0942843b Improvements to static_thread_pool
- Worker threads now spin for a short while before putting
  themselves to sleep. This reduces the overhead for enqueueing
  items as the enqueuing thread doesn't have to call into the OS
  to wake up the thread so often. It should also improve the
  responsiveness of worker threads.
- Keep track of the number of sleeping threads in an atomic integer
  so that enqueueing threads only need to look in one place to check
  whether any threads need to be woken rather than scanning the
  thread-state of each worker thread.
- Make m_globalQueueHead atomic so that worker threads that are
  spinning waiting for new work can perform an approximate check
  for new work without needing to acquire the mutex lock.
2018-08-06 08:34:38 -07:00