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
db447440
Commit
db447440
authored
Aug 07, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Event{Pipe,FD}: auto-create in constructor
Errors are fatal now. This makes the class a lot easier to use.
parent
b70d38dc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
59 deletions
+23
-59
EventFD.cxx
src/event/EventFD.cxx
+9
-16
EventFD.hxx
src/event/EventFD.hxx
+3
-14
EventPipe.cxx
src/event/EventPipe.cxx
+8
-14
EventPipe.hxx
src/event/EventPipe.hxx
+3
-15
No files found.
src/event/EventFD.cxx
View file @
db447440
...
...
@@ -21,33 +21,26 @@
#ifdef USE_EVENTFD
#include "EventFD.hxx"
#include "system/fd_util.h"
#include "system/FatalError.hxx"
#include "gcc.h"
#include <assert.h>
#include <unistd.h>
#include <sys/eventfd.h>
#ifdef WIN32
static
bool
PoorSocketPair
(
int
fd
[
2
]);
#endif
bool
EventFD
::
Create
()
EventFD
::
EventFD
()
:
fd
(
eventfd_cloexec_nonblock
(
0
,
0
))
{
assert
(
fd
==
-
1
);
fd
=
eventfd_cloexec_nonblock
(
0
,
0
);
return
fd
>=
0
;
if
(
fd
<
0
)
FatalSystemError
(
"eventfd() failed"
);
}
void
EventFD
::
Destroy
()
EventFD
::~
EventFD
()
{
close
(
fd
);
assert
(
fd
>=
0
);
#ifndef NDEBUG
fd
=
-
1
;
#endif
close
(
fd
);
}
bool
...
...
src/event/EventFD.hxx
View file @
db447440
...
...
@@ -22,33 +22,22 @@
#include "check.h"
#include <assert.h>
/**
* A class that wraps eventfd().
*
* For optimization purposes, this class does not have a constructor
* or a destructor.
* Errors in the constructor are fatal.
*/
class
EventFD
{
int
fd
;
public
:
#ifdef NDEBUG
EventFD
()
=
default
;
#else
EventFD
()
:
fd
(
-
1
)
{}
#endif
EventFD
();
~
EventFD
();
EventFD
(
const
EventFD
&
other
)
=
delete
;
EventFD
&
operator
=
(
const
EventFD
&
other
)
=
delete
;
bool
Create
();
void
Destroy
();
int
Get
()
const
{
assert
(
fd
>=
0
);
return
fd
;
}
...
...
src/event/EventPipe.cxx
View file @
db447440
...
...
@@ -20,8 +20,10 @@
#include "config.h"
#include "EventPipe.hxx"
#include "system/fd_util.h"
#include "system/FatalError.hxx"
#include "gcc.h"
#include <assert.h>
#include <unistd.h>
#ifdef WIN32
...
...
@@ -34,21 +36,18 @@
static
bool
PoorSocketPair
(
int
fd
[
2
]);
#endif
bool
EventPipe
::
Create
()
EventPipe
::
EventPipe
()
{
assert
(
fds
[
0
]
==
-
1
);
assert
(
fds
[
1
]
==
-
1
);
#ifdef WIN32
return
PoorSocketPair
(
fds
);
bool
success
=
PoorSocketPair
(
fds
);
#else
return
pipe_cloexec_nonblock
(
fds
)
>=
0
;
bool
success
=
pipe_cloexec_nonblock
(
fds
)
>=
0
;
#endif
if
(
!
success
)
FatalSystemError
(
"pipe() has failed"
);
}
void
EventPipe
::
Destroy
()
EventPipe
::~
EventPipe
()
{
#ifdef WIN32
closesocket
(
fds
[
0
]);
...
...
@@ -56,11 +55,6 @@ EventPipe::Destroy()
#else
close
(
fds
[
0
]);
close
(
fds
[
1
]);
#ifndef NDEBUG
fds
[
0
]
=
-
1
;
fds
[
1
]
=
-
1
;
#endif
#endif
}
...
...
src/event/EventPipe.hxx
View file @
db447440
...
...
@@ -22,34 +22,22 @@
#include "check.h"
#include <assert.h>
/**
* A pipe that can be used to trigger an event to the read side.
*
* For optimization purposes, this class does not have a constructor
* or a destructor.
* Errors in the constructor are fatal.
*/
class
EventPipe
{
int
fds
[
2
];
public
:
#ifdef NDEBUG
EventPipe
()
=
default
;
#else
EventPipe
()
:
fds
{
-
1
,
-
1
}
{};
#endif
EventPipe
();
~
EventPipe
();
EventPipe
(
const
EventPipe
&
other
)
=
delete
;
EventPipe
&
operator
=
(
const
EventPipe
&
other
)
=
delete
;
bool
Create
();
void
Destroy
();
int
Get
()
const
{
assert
(
fds
[
0
]
>=
0
);
assert
(
fds
[
1
]
>=
0
);
return
fds
[
0
];
}
...
...
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