IXWebSocket/ixwebsocket/IXSelectInterruptPipe.h

41 lines
1008 B
C
Raw Permalink Normal View History

2018-11-07 21:24:08 +01:00
/*
2019-03-15 02:37:38 +01:00
* IXSelectInterruptPipe.h
2018-11-07 21:24:08 +01:00
* Author: Benjamin Sergeant
2019-03-15 02:37:38 +01:00
* Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved.
2018-11-07 21:24:08 +01:00
*/
#pragma once
2019-03-15 02:37:38 +01:00
#include "IXSelectInterrupt.h"
2019-05-30 17:46:50 +02:00
#include <mutex>
#include <stdint.h>
2019-03-15 02:37:38 +01:00
#include <string>
namespace ix
2018-11-07 21:24:08 +01:00
{
2019-05-30 17:46:50 +02:00
class SelectInterruptPipe final : public SelectInterrupt
{
2018-11-07 21:24:08 +01:00
public:
2019-03-15 02:37:38 +01:00
SelectInterruptPipe();
virtual ~SelectInterruptPipe();
bool init(std::string& errorMsg) final;
2018-11-07 21:24:08 +01:00
2019-03-15 02:37:38 +01:00
bool notify(uint64_t value) final;
bool clear() final;
uint64_t read() final;
2019-03-15 19:41:57 +01:00
int getFd() const final;
2018-11-07 21:24:08 +01:00
private:
// Store file descriptors used by the communication pipe. Communication
// happens between a control thread and a background thread, which is
// blocked on select.
int _fildes[2];
mutable std::mutex _fildesMutex;
// Used to identify the read/write idx
static const int kPipeReadIndex;
static const int kPipeWriteIndex;
2018-11-07 21:24:08 +01:00
};
2019-05-30 17:46:50 +02:00
} // namespace ix