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
ecd5eb02
Commit
ecd5eb02
authored
Jan 10, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/WakeFD: use eventfd() if available
parent
3be57dc4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
WakeFD.cxx
src/event/WakeFD.cxx
+35
-1
WakeFD.hxx
src/event/WakeFD.hxx
+11
-0
No files found.
src/event/WakeFD.cxx
View file @
ecd5eb02
...
@@ -24,12 +24,24 @@
...
@@ -24,12 +24,24 @@
#include <unistd.h>
#include <unistd.h>
#ifdef HAVE_EVENTFD
#include <sys/eventfd.h>
#endif
bool
bool
WakeFD
::
Create
()
WakeFD
::
Create
()
{
{
assert
(
fds
[
0
]
==
-
1
);
assert
(
fds
[
0
]
==
-
1
);
assert
(
fds
[
1
]
==
-
1
);
assert
(
fds
[
1
]
==
-
1
);
#ifdef HAVE_EVENTFD
fds
[
0
]
=
eventfd_cloexec_nonblock
(
0
,
0
);
if
(
fds
[
0
]
>=
0
)
{
fds
[
1
]
=
-
2
;
return
true
;
}
#endif
return
pipe_cloexec_nonblock
(
fds
)
>=
0
;
return
pipe_cloexec_nonblock
(
fds
)
>=
0
;
}
}
...
@@ -40,7 +52,10 @@ WakeFD::Destroy()
...
@@ -40,7 +52,10 @@ WakeFD::Destroy()
/* By some strange reason this call hangs on Win32 */
/* By some strange reason this call hangs on Win32 */
close
(
fds
[
0
]);
close
(
fds
[
0
]);
#endif
#endif
close
(
fds
[
1
]);
#ifdef HAVE_EVENTFD
if
(
!
IsEventFD
())
#endif
close
(
fds
[
1
]);
#ifndef NDEBUG
#ifndef NDEBUG
fds
[
0
]
=
-
1
;
fds
[
0
]
=
-
1
;
...
@@ -52,6 +67,15 @@ bool
...
@@ -52,6 +67,15 @@ bool
WakeFD
::
Read
()
WakeFD
::
Read
()
{
{
assert
(
fds
[
0
]
>=
0
);
assert
(
fds
[
0
]
>=
0
);
#ifdef HAVE_EVENTFD
if
(
IsEventFD
())
{
eventfd_t
value
;
return
read
(
fds
[
0
],
&
value
,
sizeof
(
value
))
==
(
ssize_t
)
sizeof
(
value
);
}
#endif
assert
(
fds
[
1
]
>=
0
);
assert
(
fds
[
1
]
>=
0
);
char
buffer
[
256
];
char
buffer
[
256
];
...
@@ -62,6 +86,16 @@ void
...
@@ -62,6 +86,16 @@ void
WakeFD
::
Write
()
WakeFD
::
Write
()
{
{
assert
(
fds
[
0
]
>=
0
);
assert
(
fds
[
0
]
>=
0
);
#ifdef HAVE_EVENTFD
if
(
IsEventFD
())
{
static
constexpr
eventfd_t
value
=
1
;
gcc_unused
ssize_t
nbytes
=
write
(
fds
[
0
],
&
value
,
sizeof
(
value
));
return
;
}
#endif
assert
(
fds
[
1
]
>=
0
);
assert
(
fds
[
1
]
>=
0
);
gcc_unused
ssize_t
nbytes
=
write
(
fds
[
1
],
""
,
1
);
gcc_unused
ssize_t
nbytes
=
write
(
fds
[
1
],
""
,
1
);
...
...
src/event/WakeFD.hxx
View file @
ecd5eb02
...
@@ -48,7 +48,9 @@ public:
...
@@ -48,7 +48,9 @@ public:
int
Get
()
const
{
int
Get
()
const
{
assert
(
fds
[
0
]
>=
0
);
assert
(
fds
[
0
]
>=
0
);
#ifndef HAVE_EVENTFD
assert
(
fds
[
1
]
>=
0
);
assert
(
fds
[
1
]
>=
0
);
#endif
return
fds
[
0
];
return
fds
[
0
];
}
}
...
@@ -64,6 +66,15 @@ public:
...
@@ -64,6 +66,15 @@ public:
* be combined to one wakeup.
* be combined to one wakeup.
*/
*/
void
Write
();
void
Write
();
private
:
#ifdef HAVE_EVENTFD
bool
IsEventFD
()
{
assert
(
fds
[
0
]
>=
0
);
return
fds
[
1
]
==
-
2
;
}
#endif
};
};
#endif
/* MAIN_NOTIFY_H */
#endif
/* MAIN_NOTIFY_H */
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