YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ShmemInputStream.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_SHMEM_SHMEMINPUTSTREAM_H
8#define YARP_SHMEM_SHMEMINPUTSTREAM_H
9
10#include "ShmemPlatform.h"
11#include "ShmemTypes.h"
12
13#include <yarp/conf/numeric.h>
14#include <yarp/os/Bytes.h>
15
16#include <atomic>
17#include <memory>
18#include <mutex>
19
20
22{
23public:
26
27 bool isOk() const;
28 bool open(int port, shmem::Socket* pSock);
30 void close();
31
32protected:
33 int read(char* data, int len);
34 bool Resize();
35 bool m_bOpen;
36
37 // Set by close() before waiting for a pending read to finish, so that a
38 // read waiting for data can give up
39 std::atomic<bool> m_bInterrupt;
40
42 int m_Port;
43
44 // Protects the shared buffer. A semaphore (used as a binary mutex) is
45 // used instead of a mutex, since it can be released by any thread.
47
48 // Signalled by the writer when new data is available. It must be a
49 // semaphore and not a mutex, since it is released by a different
50 // process (and thread) than the one waiting on it.
52
54
55 // Mutex for the whole class, to avoid concurrent close and read
56 std::recursive_mutex m_generalMutex;
57
58 std::unique_ptr<shmem::SharedMemory> m_pMap;
59 char* m_pData;
61
63};
64
65#endif
std::atomic< bool > m_bInterrupt
bool open(int port, shmem::Socket *pSock)
shmem::Socket * m_pSock
std::recursive_mutex m_generalMutex
yarp::conf::ssize_t read(yarp::os::Bytes &b)
ShmemHeader_t * m_pHeader
shmem::NamedSemaphore m_AccessMutex
shmem::NamedSemaphore m_WaitDataSem
std::unique_ptr< shmem::SharedMemory > m_pMap
std::mutex m_ReadSerializerMutex
A named inter-process semaphore.
A minimal IPv4 TCP socket.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
::ssize_t ssize_t
Definition numeric.h:87