Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for linux scheduler and timer #64

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4d1845b
Turn off warnings about std::result_of_t usage on latest msvc compiler.
lewissbaker Jan 20, 2018
c549df8
support for linux scheduler and timer
neo5167 Jan 27, 2018
af44da4
restructuring the code to reduce ifdefs
neo5167 Feb 7, 2018
26e6c72
conforming to the white space and indentation rules.
neo5167 Feb 12, 2018
3ecdf4a
Update .travis.yml to refer to clang-7
lewissbaker Feb 16, 2018
377deb8
Try clang-7.0 instead of clang-7 package name
lewissbaker Feb 17, 2018
48e1ef5
Fix clang-7 apt package names again
lewissbaker Feb 24, 2018
7d0f2df
Try setting CLANG_VERSION=7 instead of 7.0 in Travis config
lewissbaker Feb 24, 2018
862e99d
[README] Add C++ highlighting for 'schedule_on' (#67)
modocache Feb 27, 2018
936e6ee
Remove possible warnings with redefinitions
attila0x2A Mar 9, 2018
a19b13b
Merge pull request #71 from think-cell/redef_warnings
lewissbaker Mar 27, 2018
4963e33
Update appveyor.yml to ignore x86 optimised failures
lewissbaker Mar 27, 2018
53d4a06
Merge pull request #76 from lewissbaker/appveyor-tweaks
lewissbaker Mar 27, 2018
a4d2c7b
Correct file_write_operation's friend class
attila0x2A Mar 29, 2018
98d98e2
Merge pull request #77 from think-cell/correct_file_write
lewissbaker Apr 4, 2018
b0e5f76
Fix typo in async_generator state description
attila0x2A Mar 8, 2018
14ad4bd
Fix io_service_fixture_with_threads: create given threads count (#75)
grishavanika Apr 5, 2018
bce2a72
Replace <iosfwd> with <ostream> in doctest.h to try and fix linker er…
lewissbaker Apr 6, 2018
5aa1cd1
[AppVeyor] Reenable VS 2017 Preview build variants
lewissbaker Apr 6, 2018
2492c07
Link against vcruntime[d].lib instead of msvcurt[d].lib
lewissbaker Apr 9, 2018
115aa39
fixed the minor comments from lewis.
neo5167 Apr 11, 2018
e5dc2fc
changes for white space based on clang-format.el
neo5167 Apr 12, 2018
d02cab7
copyright block
neo5167 Apr 16, 2018
b23f640
support for linux scheduler and timer
neo5167 Jan 27, 2018
723c049
restructuring the code to reduce ifdefs
neo5167 Feb 7, 2018
b8db839
conforming to the white space and indentation rules.
neo5167 Feb 12, 2018
cc86c9b
fixed the minor comments from lewis.
neo5167 Apr 11, 2018
343fe0a
changes for white space based on clang-format.el
neo5167 Apr 12, 2018
2565005
copyright block
neo5167 Apr 16, 2018
b006b04
rebasing with upstream master and fixing some windows bugs.
Jun 20, 2018
7fec714
fixing merge conflicts.
Jun 20, 2018
87910b8
removing repeated files from cake.
Jun 20, 2018
8007d4f
indentation fixes.
Jun 20, 2018
ab4b9b7
indentation fixes.
Jun 20, 2018
d38a213
more indentation changes. Moving from cc mode to llvm style.
Jun 20, 2018
1696936
reverting some changes since the functions are no longer needed.
Jun 20, 2018
751232b
windows tests passing.
Jun 21, 2018
f870053
All linux tests passing.
Jun 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ addons:
- llvm-toolchain-trusty
packages:
- python2.7
- clang-6.0
- lld-6.0
- clang-7
- lld-7
- ninja-build

cache:
Expand All @@ -37,12 +37,12 @@ env:
- CMAKE_VERSION="3.9.1"
matrix:
include:
- env: RELEASE=debug ARCH=x64 CLANG_VERSION=6.0
- env: RELEASE=optimised ARCH=x64 CLANG_VERSION=6.0
- env: RELEASE=debug ARCH=x64 CLANG_VERSION=7
- env: RELEASE=optimised ARCH=x64 CLANG_VERSION=7
allow_failures:
# Clang 6.0~svn320382 has a bug that causes optimised builds to fail.
# See https://bugs.llvm.org/show_bug.cgi?id=34897
- env: RELEASE=optimised ARCH=x64 CLANG_VERSION=6.0
- env: RELEASE=optimised ARCH=x64 CLANG_VERSION=7

before_install:
- export CC="$CC-$CLANG_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ task<> example()
```

API Summary:
```
```c++
// <cppcoro/schedule_on.hpp>
namespace cppcoro
{
Expand Down
10 changes: 8 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

version: 1.0.{build}

image:
- Visual Studio 2017
#- Visual Studio 2017 Preview
- Visual Studio 2017 Preview

platform:
- x64
Expand All @@ -13,6 +12,13 @@ configuration:
- debug
- optimised

matrix:
# Allow failures under MSVC x86 optimised since there are some known compiler
# bugs causing failures here.
allow_failures:
- platform: x86
configuration: optimised

clone_script:
- ps: git clone -q $("--branch=" + $env:APPVEYOR_REPO_BRANCH) $("https://github.com/" + $env:APPVEYOR_REPO_NAME + ".git") $env:APPVEYOR_BUILD_FOLDER
- ps: if (!$env:APPVEYOR_PULL_REQUEST_NUMBER) {$("git checkout -qf " + $env:APPVEYOR_REPO_COMMIT)}
Expand Down
8 changes: 6 additions & 2 deletions config.cake
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ if cake.system.isWindows() or cake.system.isCygwin():
# Enable C++17 features like std::optional<>
compiler.addCppFlag('/std:c++latest')

compiler.addDefine('_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING')

compiler.addProgramFlag('/nodefaultlib')
compiler.addModuleFlag('/nodefaultlib')

Expand All @@ -137,7 +139,7 @@ if cake.system.isWindows() or cake.system.isCygwin():
compiler.runtimeLibraries = 'debug-dll'
compiler.addLibrary('msvcrtd')
compiler.addLibrary('msvcprtd')
compiler.addLibrary('msvcurtd')
compiler.addLibrary('vcruntimed')
compiler.addLibrary('ucrtd')
compiler.addLibrary('oldnames')

Expand All @@ -159,7 +161,7 @@ if cake.system.isWindows() or cake.system.isCygwin():
compiler.runtimeLibraries = 'release-dll'
compiler.addLibrary('msvcrt')
compiler.addLibrary('msvcprt')
compiler.addLibrary('msvcurt')
compiler.addLibrary('vcruntime')
compiler.addLibrary('ucrt')
compiler.addLibrary('oldnames')

Expand Down Expand Up @@ -293,6 +295,8 @@ elif cake.system.isLinux() or cake.system.isDarwin():
compiler.addLibrary('c++')
compiler.addLibrary('c')
compiler.addLibrary('pthread')
compiler.addLibrary('rt')
compiler.addLibrary('uuid')

#compiler.addProgramFlag('-Wl,--trace')
#compiler.addProgramFlag('-Wl,-v')
Expand Down
4 changes: 2 additions & 2 deletions include/cppcoro/async_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ namespace cppcoro
// State transition diagram
// VNRCA - value_not_ready_consumer_active
// VNRCS - value_not_ready_consumer_suspended
// VRPA - value_ready_consumer_active
// VRPS - value_ready_consumer_suspended
// VRPA - value_ready_producer_active
// VRPS - value_ready_producer_suspended
//
// A +--- VNRCA --[C]--> VNRCS yield_value()
// | | | A | A | .
Expand Down
133 changes: 133 additions & 0 deletions include/cppcoro/detail/linux.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#pragma once
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to use #ifdef include guards to be consistent with other headers?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a copyright/license header as per the existing source files?

Please attribute copyright to the appropriate entity.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have to circle back on this. Have to speak with our team here to get the appropriate rights entity name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


#include <mqueue.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/eventfd.h>
#include <fcntl.h>
#include <uuid/uuid.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <utility>

namespace cppcoro
{
namespace detail
{
namespace linux
{
using fd_t = int;

enum message_type
{
CALLBACK_TYPE,
RESUME_TYPE
};

class safe_fd
{
public:

safe_fd()
: m_fd(-1)
{}

explicit safe_fd(fd_t fd)
: m_fd(fd)
{}

safe_fd(const safe_fd& other) = delete;

safe_fd(safe_fd&& other) noexcept
: m_fd(other.m_fd)
{
other.m_fd = -1;
}

~safe_fd()
{
close();
}

safe_fd& operator=(safe_fd fd) noexcept
{
swap(fd);
return *this;
}

constexpr fd_t fd() const { return m_fd; }

/// Calls close() and sets the fd to -1.
void close() noexcept;

void swap(safe_fd& other) noexcept
{
std::swap(m_fd, other.m_fd);
}

bool operator==(const safe_fd& other) const
{
return m_fd == other.m_fd;
}

bool operator!=(const safe_fd& other) const
{
return m_fd != other.m_fd;
}

bool operator==(fd_t fd) const
{
return m_fd == fd;
}

bool operator!=(fd_t fd) const
{
return m_fd != fd;
}

private:

fd_t m_fd;

};

struct message
{
enum message_type m_type;
void* m_ptr;
};

struct io_state : linux::message
{
using callback_type = void(io_state* state);
callback_type* m_callback;
};

class message_queue
{
private:
mqd_t m_mqdt;
char m_qname[NAME_MAX];
safe_fd m_epollfd;
struct epoll_event m_ev;
message_queue();
public:
message_queue(size_t queue_length);
~message_queue();
bool enqueue_message(void* message, message_type type);
bool dequeue_message(void*& message, message_type& type, bool wait);
};

safe_fd create_event_fd();
safe_fd create_timer_fd();
safe_fd create_epoll_fd();
}
}
}
2 changes: 1 addition & 1 deletion include/cppcoro/file_write_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace cppcoro

private:

friend class cppcoro::detail::win32_overlapped_operation<file_write_operation>;
friend class cppcoro::detail::win32_overlapped_operation_cancellable<file_write_operation_cancellable>;

bool try_start() noexcept;
void cancel() noexcept;
Expand Down
17 changes: 16 additions & 1 deletion include/cppcoro/io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
# include <cppcoro/detail/win32.hpp>
#endif

#if CPPCORO_OS_LINUX
#include <cppcoro/detail/linux.hpp>
#endif

#include <optional>
#include <chrono>
#include <cstdint>
#include <atomic>
#include <utility>
#include <experimental/coroutine>
#include <vector>

namespace cppcoro
{
Expand All @@ -42,8 +47,11 @@ namespace cppcoro
/// actively processing events.
/// Note that the number of active threads may temporarily go
/// above this number.
#if CPPCORO_OS_WINNT
io_service(std::uint32_t concurrencyHint);

#elif CPPCORO_OS_LINUX
io_service(size_t queue_length);
#endif
~io_service();

io_service(io_service&& other) = delete;
Expand Down Expand Up @@ -147,6 +155,10 @@ namespace cppcoro

void try_reschedule_overflow_operations() noexcept;

void queue_overflow_operation_to_head(schedule_operation* operation) noexcept;

void queue_overflow_operation_to_tail(schedule_operation* operation) noexcept;

bool try_enter_event_loop() noexcept;
void exit_event_loop() noexcept;

Expand All @@ -169,6 +181,9 @@ namespace cppcoro
detail::win32::safe_handle m_iocpHandle;
#endif

#if CPPCORO_OS_LINUX
detail::linux::message_queue* m_mq;
#endif
// Head of a linked-list of schedule operations that are
// ready to run but that failed to be queued to the I/O
// completion port (eg. due to low memory).
Expand Down
10 changes: 9 additions & 1 deletion lib/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,29 @@ sources = script.cwd([
'ipv4_endpoint.cpp',
'ipv6_address.cpp',
'ipv6_endpoint.cpp',
'io_service.cpp',
])

extras = script.cwd([
'build.cake',
'use.cake',
])

if variant.platform == "linux":
detailIncludes.extend(cake.path.join(env.expand('${CPPCORO}'), 'include', 'cppcoro', 'detail', [
'linux.hpp',
]))
sources.extend(script.cwd([
'linux.cpp',
]))

if variant.platform == "windows":
detailIncludes.extend(cake.path.join(env.expand('${CPPCORO}'), 'include', 'cppcoro', 'detail', [
'win32.hpp',
'win32_overlapped_operation.hpp',
]))
sources.extend(script.cwd([
'win32.cpp',
'io_service.cpp',
'file.cpp',
'readable_file.cpp',
'writable_file.cpp',
Expand Down
4 changes: 3 additions & 1 deletion lib/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <cassert>

#if CPPCORO_OS_WINNT
# define WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <Windows.h>
#endif

Expand Down
4 changes: 3 additions & 1 deletion lib/file_read_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <cppcoro/file_read_operation.hpp>

#if CPPCORO_OS_WINNT
# define WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <Windows.h>

bool cppcoro::file_read_operation::try_start() noexcept
Expand Down
4 changes: 3 additions & 1 deletion lib/file_write_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <cppcoro/file_write_operation.hpp>

#if CPPCORO_OS_WINNT
# define WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <Windows.h>

bool cppcoro::file_write_operation::try_start() noexcept
Expand Down
Loading