forked from EmbeddedRPC/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
erpc_inter_thread_buffer_transport.cpp
74 lines (55 loc) · 1.56 KB
/
erpc_inter_thread_buffer_transport.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
68
69
70
71
72
73
74
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "erpc_inter_thread_buffer_transport.hpp"
using namespace erpc;
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////
InterThreadBufferTransport::~InterThreadBufferTransport(void) {}
void InterThreadBufferTransport::linkWithPeer(InterThreadBufferTransport *peer)
{
m_peer = peer;
peer->m_peer = this;
if (!m_state)
{
if (peer->m_state == NULL)
{
m_state = new SharedState;
peer->m_state = m_state;
}
else
{
m_state = peer->m_state;
}
}
}
erpc_status_t InterThreadBufferTransport::receive(MessageBuffer *message)
{
erpc_assert(m_state && m_peer);
m_inSem.get();
m_state->m_mutex.lock();
erpc_assert(m_inBuffer != NULL);
message->copy(m_inBuffer);
m_inBuffer = NULL;
m_outSem.put();
m_state->m_mutex.unlock();
return kErpcStatus_Success;
}
erpc_status_t InterThreadBufferTransport::send(MessageBuffer *message)
{
erpc_assert((m_state != NULL) && (m_peer != NULL));
m_peer->m_outSem.get();
m_state->m_mutex.lock();
erpc_assert(m_peer->m_inBuffer == NULL);
m_peer->m_inBuffer = const_cast<MessageBuffer *>(message);
m_peer->m_inSem.put();
m_state->m_mutex.unlock();
return kErpcStatus_Success;
}