Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
a14997ff
Commit
a14997ff
authored
Oct 18, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: manage all SocketEvents in a linked list
Not only those which are "ready".
parent
dd94f975
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
20 deletions
+33
-20
Loop.cxx
src/event/Loop.cxx
+21
-9
Loop.hxx
src/event/Loop.hxx
+10
-6
SocketEvent.cxx
src/event/SocketEvent.cxx
+1
-1
SocketEvent.hxx
src/event/SocketEvent.hxx
+1
-4
No files found.
src/event/Loop.cxx
View file @
a14997ff
...
...
@@ -67,6 +67,8 @@ EventLoop::~EventLoop() noexcept
{
assert
(
idle
.
empty
());
assert
(
timers
.
empty
());
assert
(
sockets
.
empty
());
assert
(
ready_sockets
.
empty
());
}
#ifdef HAVE_URING
...
...
@@ -117,7 +119,11 @@ EventLoop::AddFD(int fd, unsigned events, SocketEvent &event) noexcept
assert
(
!
IsAlive
()
||
IsInside
());
#endif
return
poll_group
.
Add
(
fd
,
events
,
&
event
);
if
(
!
poll_group
.
Add
(
fd
,
events
,
&
event
))
return
false
;
sockets
.
push_back
(
event
);
return
true
;
}
bool
...
...
@@ -131,12 +137,13 @@ EventLoop::ModifyFD(int fd, unsigned events, SocketEvent &event) noexcept
}
bool
EventLoop
::
RemoveFD
(
int
fd
)
noexcept
EventLoop
::
RemoveFD
(
int
fd
,
SocketEvent
&
event
)
noexcept
{
#ifdef HAVE_THREADED_EVENT_LOOP
assert
(
!
IsAlive
()
||
IsInside
());
#endif
event
.
unlink
();
return
poll_group
.
Remove
(
fd
);
}
...
...
@@ -213,11 +220,13 @@ EventLoop::Wait(Event::Duration timeout) noexcept
const
auto
poll_result
=
poll_group
.
ReadEvents
(
ExportTimeoutMS
(
timeout
));
ready_sockets
.
clear
();
for
(
size_t
i
=
0
;
i
<
poll_result
.
GetSize
();
++
i
)
{
auto
&
s
=
*
(
SocketEvent
*
)
poll_result
.
GetObject
(
i
);
s
.
SetReadyFlags
(
poll_result
.
GetEvents
(
i
));
ready_sockets
.
push_back
(
s
);
auto
&
socket_event
=
*
(
SocketEvent
*
)
poll_result
.
GetObject
(
i
);
socket_event
.
SetReadyFlags
(
poll_result
.
GetEvents
(
i
));
/* move from "sockets" to "ready_sockets" */
socket_event
.
unlink
();
ready_sockets
.
push_back
(
socket_event
);
}
return
poll_result
.
GetSize
()
>
0
;
...
...
@@ -309,10 +318,13 @@ EventLoop::Run() noexcept
/* invoke sockets */
while
(
!
ready_sockets
.
empty
()
&&
!
quit
)
{
auto
&
sm
=
ready_sockets
.
front
();
ready_sockets
.
pop_front
();
auto
&
socket_event
=
ready_sockets
.
front
();
/* move from "ready_sockets" back to "sockets" */
socket_event
.
unlink
();
sockets
.
push_back
(
socket_event
);
s
m
.
Dispatch
();
s
ocket_event
.
Dispatch
();
}
}
while
(
!
quit
);
...
...
src/event/Loop.hxx
View file @
a14997ff
...
...
@@ -91,18 +91,22 @@ class EventLoop final
DeferredList
deferred
;
#endif
using
Ready
SocketList
=
using
SocketList
=
boost
::
intrusive
::
list
<
SocketEvent
,
boost
::
intrusive
::
member_hook
<
SocketEvent
,
SocketEvent
::
ReadyListHook
,
&
SocketEvent
::
ready_siblings
>
,
boost
::
intrusive
::
base_hook
<
boost
::
intrusive
::
list_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>>
,
boost
::
intrusive
::
constant_time_size
<
false
>>
;
/**
* A list of scheduled #SocketEvent instances, without those
* which are ready (these are in #ready_sockets).
*/
SocketList
sockets
;
/**
* A linked list of #SocketEvent instances which have a
* non-zero "ready_flags" field, and need to be dispatched.
*/
Ready
SocketList
ready_sockets
;
SocketList
ready_sockets
;
#ifdef HAVE_URING
std
::
unique_ptr
<
Uring
::
Manager
>
uring
;
...
...
@@ -188,7 +192,7 @@ public:
bool
AddFD
(
int
fd
,
unsigned
events
,
SocketEvent
&
event
)
noexcept
;
bool
ModifyFD
(
int
fd
,
unsigned
events
,
SocketEvent
&
event
)
noexcept
;
bool
RemoveFD
(
int
fd
)
noexcept
;
bool
RemoveFD
(
int
fd
,
SocketEvent
&
event
)
noexcept
;
/**
* Remove the given #SocketEvent after the file descriptor
...
...
src/event/SocketEvent.cxx
View file @
a14997ff
...
...
@@ -69,7 +69,7 @@ SocketEvent::Schedule(unsigned flags) noexcept
if
(
scheduled_flags
==
0
)
success
=
loop
.
AddFD
(
fd
.
Get
(),
flags
,
*
this
);
else
if
(
flags
==
0
)
success
=
loop
.
RemoveFD
(
fd
.
Get
());
success
=
loop
.
RemoveFD
(
fd
.
Get
()
,
*
this
);
else
success
=
loop
.
ModifyFD
(
fd
.
Get
(),
flags
,
*
this
);
...
...
src/event/SocketEvent.hxx
View file @
a14997ff
...
...
@@ -45,14 +45,11 @@ class EventLoop;
* thread that runs the #EventLoop, except where explicitly documented
* as thread-safe.
*/
class
SocketEvent
{
class
SocketEvent
final
:
public
boost
::
intrusive
::
list_base_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
{
friend
class
EventLoop
;
EventLoop
&
loop
;
using
ReadyListHook
=
boost
::
intrusive
::
list_member_hook
<
boost
::
intrusive
::
link_mode
<
boost
::
intrusive
::
auto_unlink
>>
;
ReadyListHook
ready_siblings
;
using
Callback
=
BoundMethod
<
void
(
unsigned
events
)
noexcept
>
;
const
Callback
callback
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment