-
Notifications
You must be signed in to change notification settings - Fork 474
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 2 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. | ||
io_service(std::uint32_t concurrencyHint); | ||
|
||
#if CPPCORO_OS_WINNT | ||
io_service(std::uint32_t concurrencyHint); | ||
#endif | ||
#if CPPCORO_OS_LINUX | ||
io_service(size_t queue_length); | ||
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'm not a huge fan of having this constructor parameter have different meanings on two different platforms - it makes it more difficult to write cross-platform application code. We could either add two parameters here, or instead pass in some kind of configuration struct that allows overriding defaults? |
||
#endif | ||
~io_service(); | ||
|
||
io_service(io_service&& other) = delete; | ||
|
@@ -147,6 +155,10 @@ namespace cppcoro | |
|
||
void try_reschedule_overflow_operations() noexcept; | ||
|
||
void queue_overflow_operation_to_head(schedule_operation* operation) noexcept; | ||
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 think the names of the They are both actually pushing items onto the head of the queue. What about naming them |
||
|
||
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; | ||
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. The message queue could just be a direct member rather than a pointer to a heap-allocated object. |
||
#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). | ||
|
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.