1
0
mirror of https://github.com/wfjm/w11.git synced 2026-02-03 07:31:13 +00:00

move RtimerFd, ReventFd to librtools

This commit is contained in:
wfjm
2019-03-30 08:53:05 +01:00
parent f9faf937b1
commit 9411fe764d
10 changed files with 13 additions and 11 deletions

View File

@@ -0,0 +1,82 @@
// $Id: ReventFd.cpp 1089 2018-12-19 10:45:41Z mueller $
//
// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for complete details.
//
// Revision History:
// Date Rev Version Comment
// 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
// ---------------------------------------------------------------------------
/*!
\file
\brief Implemenation of class ReventFd.
*/
#include <errno.h>
#include <unistd.h>
#include <sys/eventfd.h>
#include "ReventFd.hpp"
#include "librtools/Rexception.hpp"
using namespace std;
/*!
\class Retro::ReventFd
\brief FIXME_docs
*/
// all method definitions in namespace Retro
namespace Retro {
//------------------------------------------+-----------------------------------
//! FIXME_docs
ReventFd::ReventFd()
{
fFd = ::eventfd(0,0); // ini value = 0; no flags
if (fFd < 0)
throw Rexception("ReventFd::ctor", "eventfd() failed: ", errno);
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
ReventFd::~ReventFd()
{
::close(fFd);
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
int ReventFd::SignalFd(int fd)
{
uint64_t one(1);
int irc = ::write(fd, &one, sizeof(one));
return irc;
}
//------------------------------------------+-----------------------------------
//! FIXME_docs
int ReventFd::WaitFd(int fd)
{
uint64_t buf;
int irc = ::read(fd, &buf, sizeof(buf));
return (irc <= 0) ? irc : int(buf);
}
} // end namespace Retro