Commit graph

391 commits

Author SHA1 Message Date
Lewis Baker ac76fcf5de
Merge branch 'master' into static_thread_pool 2018-08-09 08:46:40 -07:00
Lewis Baker 4ffd6290e0 Add some docs to README for static_thread_pool. 2018-08-09 08:44:31 -07:00
Lewis Baker b2b9c66fb0 Make static_thread_pool::schedule() declared [[nodiscard]] 2018-08-09 08:44:07 -07:00
Lewis Baker 18e02bd0cd Fix bug in static_thread_pool::wake_one_thread()
It's possible that we won't find a thread to wake up in a
single pass through the worker threads. Now loop until we
do find a worker thread to wake up.
2018-08-08 08:37:28 -07:00
Lewis Baker 2115feeb50 Fix occasionally-failing test in scheduling_operator_tests.cpp
Disabled a CHECK() for the thread that the schedule_on() operator
resumes on since the outcome is actually not guaranteed with the
current implementation of task<T>. See #79 for details.
2018-08-08 08:16:46 -07:00
Lewis Baker 2d89231737 Update Cake version to latest.
This should fix #82 (vswhere output decoding issues)
2018-08-08 07:57:06 -07:00
Lewis Baker bd9d2539c6 Fix uninitialised member in static_thread_pool. 2018-08-07 00:08:37 -07:00
Lewis Baker 4900f94b38 Make for_each_async() execute the first iteration onto scheduler. 2018-08-06 23:51:21 -07:00
Lewis Baker d5bb99b4e4 Fix type truncation warning under 32-bit platforms. 2018-08-06 23:27:46 -07:00
Lewis Baker b17d9465b5
Add missing #include 2018-08-06 09:27:18 -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 73d24f4689 Add test showing parallel for_each using continuation stealing.
This allows parallel execution of a bulk operation using only
a single coroutine frame. The continuation of the loop is eligible
to be stolen by other threads while executing the current iteration.
2018-08-06 08:40:11 -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
Lewis Baker e6c05b1693 Add missing newline at end of file. 2018-08-06 08:25:23 -07:00
Lewis Baker eb8ad58c1d Avoid use of std::hardware_destructive_interference_size.
This is not yet implemented under libc++.
2018-08-03 08:26:05 -07:00
Lewis Baker 398fb1dc1f Fix static_thread_pool crashes.
- thread_state::m_mask was being incorrectly initialised
- Modified try_local_enqueue() to attempt to enlarge the local
  queue if it looks like it's run out of space.
- Removed doubly-linked list from schedule_operation as it wasn't
  needed.
- Catch any potential exceptions thrown by auto_reset_event::wait()
  and just sleep for 1ms in this case rather than terminating the
  thread.
2018-08-03 08:25:09 -07:00
Lewis Baker d4c106635b Make spin_mutex avoid cache contention while waiting for lock.
Don't write to flag until it looks like the lock has become
available. This should reduce the cache-line unnecessarily
jumping between cores when under contention.
2018-08-03 08:17:55 -07:00
Lewis Baker c6d5f6a738 WIP version of static_thread_pool.
Still seems to have some bugs that cause crashes in the tests.
2018-07-31 08:09:09 -07:00
Lewis Baker c2bf160656 Add auto_reset_event, spin_wait and spin_mutex utilities. 2018-07-31 08:05:52 -07:00
mwinterb d3a569f6c5 Fixed move constructor for win32_overlapped_operation_cancellable. (#80)
Addresses aspects of #34.
2018-07-17 09:55:19 -07:00
Lewis Baker 4022c11543
Merge branch 'master' into generic_ops 2018-04-09 12:15:06 +09:30
Lewis Baker 2492c07829
Link against vcruntime[d].lib instead of msvcurt[d].lib
The msvcurt[d].lib is actually intended for C++/CLI usage and
seems to no longer being bundled with the default VS install
in more recent Visual Studio 2017 installs.

Should fix #73
2018-04-09 11:55:53 +09:30
Lewis Baker 5aa1cd1ff9
[AppVeyor] Reenable VS 2017 Preview build variants
The AppVeyor 'Visual Studio 2017 Preview' image has now been updated with
VS 2017.7 Preview 2
2018-04-06 15:37:00 +09:30
Lewis Baker 9185e33e54
Merge branch 'master' into generic_ops 2018-04-06 15:26:25 +09:30
Lewis Baker bce2a72817
Replace <iosfwd> with <ostream> in doctest.h to try and fix linker errors under Linux (#78) 2018-04-06 15:25:51 +09:30
Lewis Baker 4a66d0889f
Merge branch 'master' into generic_ops 2018-04-06 11:38:49 +09:30
grishavanika 14ad4bd5dd Fix io_service_fixture_with_threads: create given threads count (#75) 2018-04-05 16:14:57 +09:30
Attila b0e5f765ba Fix typo in async_generator state description 2018-04-04 12:34:11 +09:30
Lewis Baker 98d98e2389
Merge pull request #77 from think-cell/correct_file_write
Correct file_write_operation's friend class
2018-04-04 12:10:17 +09:30
Attila a4d2c7b003 Correct file_write_operation's friend class 2018-03-29 15:52:27 +02:00
Lewis Baker ca52b5e63d
Merge branch 'master' into generic_ops 2018-03-27 14:16:11 +10:30
Lewis Baker 53d4a0653b
Merge pull request #76 from lewissbaker/appveyor-tweaks
Update appveyor.yml to ignore x86 optimised failures
2018-03-27 12:25:10 +10:30
Lewis Baker 4963e33422
Update appveyor.yml to ignore x86 optimised failures
Several tests are currently failing due to what seems to be compiler bugs.

Ignore tests for now and revisit once MSVC 15.7 is released.
2018-03-27 11:47:42 +10:30
Lewis Baker a19b13b06c
Merge pull request #71 from think-cell/redef_warnings
Remove possible warnings with redefinitions of WIN32_LEAN_AND_MEAN.
2018-03-27 11:43:13 +10:30
Lewis Baker 7622c2f520 Update cake to fix issue with generated .vcproj files. 2018-03-26 23:34:20 +10:30
Lewis Baker 054631b1fd Skip failing when_all() test on msvc x86 optimised.
It seems to be failing due to an msvc compiler bug.
2018-03-26 23:22:40 +10:30
Attila 936e6eeb10 Remove possible warnings with redefinitions
If the library is used as part of a bigger project some definitions can
be provided via external build files.
2018-03-09 17:32:58 +01:00
Brian Gesiak 862e99d817 [README] Add C++ highlighting for 'schedule_on' (#67) 2018-02-27 13:03:03 +10:30
Lewis Baker 7d0f2dfad1
Try setting CLANG_VERSION=7 instead of 7.0 in Travis config 2018-02-25 09:15:51 +10:30
Lewis Baker 48e1ef5754
Fix clang-7 apt package names again 2018-02-25 09:10:00 +10:30
Lewis Baker 377deb81c0
Try clang-7.0 instead of clang-7 package name 2018-02-18 08:29:17 +10:30
Lewis Baker 3ecdf4a1a4
Update .travis.yml to refer to clang-7
The clang mainline has now been branched for clang-6 and mainline now uses clang-7 version.
2018-02-16 11:53:50 +10:30
Lewis Baker 48a8680859 Merge branch 'master' into generic_ops 2018-01-20 15:14:24 +10:30
Lewis Baker 4d1845b5c3 Turn off warnings about std::result_of_t usage on latest msvc compiler.
I will move over to using std::invoke_result_t once I have confirmed
that it is supported by clang/libc++ as well.
2018-01-20 15:12:45 +10:30
Lewis Baker 3ca50b3f25 Add some printf to "write a file" test. 2018-01-14 09:15:52 +10:30
Lewis Baker bcd6a2d465 Change 'write a file' test to be single-threaded.
Attempting to eliminate a race-condition as a potential cause of
a crash in this test.
2018-01-13 21:00:51 +10:30
Lewis Baker 16e0df5b5c Add basic send_to/recv_from functionality to socket class. 2018-01-12 06:35:51 +10:30
Lewis Baker be0c017186 Declare socket operation factory methods to be noexcept. 2018-01-12 06:35:45 +10:30
Lewis Baker 27c5e6cb73 Use memcpy when populating sockaddr structures to avoid UB.
It's possible that using reintepret_cast to cast from sockaddr* to
sockaddr_in[6]* may potentially lead to undefined-behaviour due
to aliasing rules.
2018-01-12 06:35:39 +10:30
Lewis Baker b830b08324 Refactor async I/O operation classes to remove some duplication.
Factors out implementation of calls to OS that was duplicated in
both cancellable and non-cancellable operation objects into an
'impl' class that can be used by both.

Also, fixed potential data race in some try_start() methods when
trying to read the m_skipCompletionOnSuccess member of a socket
after starting the I/O operation. Now ensure that this flag is
read before starting the operation.

Simplified logic for file_[read/write]_operation slightly by
passing out-parameter to receive number of bytes read/written
if operation completes synchronously. This avoids an extra call
to GetOverlappedResult() to retrieve this information.
2018-01-12 06:35:30 +10:30