-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcCommunicator.cpp
executable file
·67 lines (61 loc) · 2.2 KB
/
ProcCommunicator.cpp
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
#include "ProcCommunicator.h"
#include <iostream>
#ifndef _WIN32
#include <unistd.h>
#include <fcntl.h>
#endif
ProcCommunicator::ProcCommunicator(const std::string &shMemName) : m_master_mem_name(shMemName + "_master"),
m_slave_mem_name(shMemName + "_slave"),
m_master_received_s(shMemName + "_m_rsem"),
m_slave_received_s(shMemName + "_s_rsem"),
m_master_sent_s(shMemName + "_m_sent"),
m_slave_sent_s(shMemName + "_s_sent"),
m_slave_ready_s(shMemName + "_s_ready")
{
}
ProcCommunicator::~ProcCommunicator()
{
#ifndef _WIN32
if (sem_close(m_master_received) == -1)
{
std::cerr << "Failed to destroy m_master_received semaphore\n";
}
if (sem_close(m_slave_received) == -1)
{
std::cerr << "Failed to destroy m_slave_received semaphore\n";
}
if (sem_close(m_master_sent) == -1)
{
std::cerr << "Failed to destroy m_master_sent semaphore\n";
}
if (sem_close(m_slave_sent) == -1)
{
std::cerr << "Failed to destroy m_slave_sent semaphore\n";
}
if (sem_close(m_slave_ready) == -1)
{
std::cerr << "Failed to destroy m_slave_ready semaphore\n";
}
#else
if (m_master_received && !CloseHandle(m_master_received))
{
std::cerr << "Failed to destroy m_master_received semaphore\n";
}
if (m_slave_received && !CloseHandle(m_slave_received))
{
std::cerr << "Failed to destroy m_slave_received semaphore\n";
}
if (m_master_sent && !CloseHandle(m_master_sent))
{
std::cerr << "Failed to destroy m_master_sent semaphore\n";
}
if (m_slave_sent && !CloseHandle(m_slave_sent))
{
std::cerr << "Failed to destroy m_slave_sent semaphore\n";
}
if (m_slave_ready && !CloseHandle(m_slave_ready))
{
std::cerr << "Failed to destroy m_slave_ready semaphore\n";
}
#endif
}