-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathReventFd.cpp
More file actions
79 lines (63 loc) · 1.85 KB
/
ReventFd.cpp
File metadata and controls
79 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// $Id: ReventFd.cpp 1185 2019-07-12 17:29:12Z mueller $
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright 2013-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// Revision History:
// Date Rev Version Comment
// 2019-06-08 1161 1.1 derive from Rfd, inherit Fd
// 2018-12-18 1089 1.0.1 use c++ style casts
// 2013-01-14 475 1.0 Initial version
// 2013-01-11 473 0.5 First draft
// ---------------------------------------------------------------------------
/*!
\brief Implemenation of class ReventFd.
*/
#include <errno.h>
#include <unistd.h>
#include <sys/eventfd.h>
#include "ReventFd.hpp"
#include "Rexception.hpp"
using namespace std;
/*!
\class Retro::ReventFd
\brief FIXME_docs
*/
// all method definitions in namespace Retro
namespace Retro {
//------------------------------------------+-----------------------------------
//! FIXME_docs
ReventFd::ReventFd()
: ReventFd("ReventFd::")
{}
//------------------------------------------+-----------------------------------
//! FIXME_docs
ReventFd::ReventFd(const char* cnam)
: Rfd(cnam)
{
fFd = ::eventfd(0,0); // ini value = 0; no flags
if (fFd < 0)
throw Rexception(fCnam+"ctor", "eventfd() failed: ", errno);
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
void ReventFd::Signal(uint64_t val)
{
int irc = ::write(fFd, &val, sizeof(val));
if (irc < 0) {
throw Rexception(fCnam+"Signal()", "write() failed: ", errno);
}
return;
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
uint64_t ReventFd::Wait()
{
uint64_t buf;
int irc = ::read(fFd, &buf, sizeof(buf));
if (irc < 0) {
if (errno == EAGAIN) return 0;
throw Rexception(fCnam+"Wait()", "read() failed: ", errno);
}
return buf;
}
} // end namespace Retro