-
Notifications
You must be signed in to change notification settings - Fork 477
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
4d1845b
c549df8
af44da4
26e6c72
3ecdf4a
377deb8
48e1ef5
7d0f2df
862e99d
936e6ee
a19b13b
4963e33
53d4a06
a4d2c7b
98d98e2
b0e5f76
14ad4bd
bce2a72
5aa1cd1
2492c07
115aa39
e5dc2fc
d02cab7
b23f640
723c049
b8db839
cc86c9b
343fe0a
2565005
b006b04
7fec714
87910b8
8007d4f
ab4b9b7
d38a213
1696936
751232b
f870053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#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> | ||
|
||
typedef int DWORD; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to avoid adding new global-scope typedefs and #defines like this in public headers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is only required for timeout values inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Fixed it. |
||
#define INFINITE (DWORD)-1 | ||
|
||
namespace cppcoro | ||
{ | ||
namespace detail | ||
{ | ||
namespace linux | ||
{ | ||
enum message_type | ||
{ | ||
CALLBACK_TYPE, | ||
RESUME_TYPE | ||
}; | ||
|
||
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]; | ||
int 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); | ||
}; | ||
|
||
int create_event_fd(); | ||
int create_timer_fd(); | ||
int create_epoll_fd(); | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ | |
# include <cppcoro/detail/win32.hpp> | ||
#endif | ||
|
||
#if CPPCORO_OS_LINUX | ||
#include <cppcoro/detail/linux.hpp> | ||
#endif | ||
|
||
#include <optional> | ||
#include <chrono> | ||
#include <cstdint> | ||
|
@@ -42,8 +46,12 @@ 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); | ||
|
||
#endif | ||
#if CPPCORO_OS_LINUX | ||
io_service(size_t queue_length); | ||
#endif | ||
~io_service(); | ||
|
||
io_service(io_service&& other) = delete; | ||
|
@@ -76,8 +84,8 @@ namespace cppcoro | |
template<typename REP, typename PERIOD> | ||
[[nodiscard]] | ||
timed_schedule_operation schedule_after( | ||
const std::chrono::duration<REP, PERIOD>& delay, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a number of unnecessary whitespace changes in these commits. Have you tried running clang-format over the files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will circle back on this. I am fixing my editor to have the same whitespace language as yours. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. Things are now "tab"-bed according to clang-format-6.0.el from my emacs. That fixed it. |
||
cancellation_token cancellationToken = {}) noexcept; | ||
const std::chrono::duration<REP, PERIOD>& delay, | ||
cancellation_token cancellationToken = {}) noexcept; | ||
|
||
/// Process events until the io_service is stopped. | ||
/// | ||
|
@@ -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; | ||
|
||
|
@@ -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). | ||
|
@@ -206,9 +221,9 @@ namespace cppcoro | |
public: | ||
|
||
timed_schedule_operation( | ||
io_service& service, | ||
std::chrono::high_resolution_clock::time_point resumeTime, | ||
cppcoro::cancellation_token cancellationToken) noexcept; | ||
io_service& service, | ||
std::chrono::high_resolution_clock::time_point resumeTime, | ||
cppcoro::cancellation_token cancellationToken) noexcept; | ||
|
||
timed_schedule_operation(timed_schedule_operation&& other) noexcept; | ||
|
||
|
@@ -303,14 +318,14 @@ namespace cppcoro | |
template<typename REP, typename RATIO> | ||
cppcoro::io_service::timed_schedule_operation | ||
cppcoro::io_service::schedule_after( | ||
const std::chrono::duration<REP, RATIO>& duration, | ||
cppcoro::cancellation_token cancellationToken) noexcept | ||
const std::chrono::duration<REP, RATIO>& duration, | ||
cppcoro::cancellation_token cancellationToken) noexcept | ||
{ | ||
return timed_schedule_operation{ | ||
*this, | ||
std::chrono::high_resolution_clock::now() + duration, | ||
std::move(cancellationToken) | ||
}; | ||
std::chrono::high_resolution_clock::now() + duration, | ||
std::move(cancellationToken) | ||
}; | ||
} | ||
|
||
#endif |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.