Skip to content

Commit

Permalink
capicxx-someip-runtime 3.1.12.8
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed Jan 25, 2018
1 parent 41af704 commit 52c9d21
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes
=======

v3.1.12.8
- Fixed data race in generated StubDefault when using attributes
- use eventfd instead of pipe in Watch

v3.1.12.7
- Don't hold mutex when pushing to watch from cleanup thread to prevent deadlock

v3.1.12.6
- Fixed hang-up in proxy destruction when async method call was done
and proxy is not available.
Expand Down
14 changes: 12 additions & 2 deletions include/CommonAPI/SomeIP/StubAdapterHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ class GetAttributeStubDispatcher: public StubDispatcher<StubClass_> {
public:
typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType;
typedef const AttributeType_& (StubClass_::*GetStubFunctor)(std::shared_ptr<CommonAPI::ClientId>);
typedef typename StubClass_::StubAdapterType StubAdapterType;
typedef typename CommonAPI::Stub<StubAdapterType, typename StubClass_::RemoteEventType> StubType;

GetAttributeStubDispatcher(GetStubFunctor getStubFunctor, bool _isLittleEndian, AttributeDepl_ *_depl = nullptr)
: getStubFunctor_(getStubFunctor), isLittleEndian_(_isLittleEndian), depl_(_depl) {
Expand All @@ -778,7 +780,12 @@ class GetAttributeStubDispatcher: public StubDispatcher<StubClass_> {

std::shared_ptr<ClientId> clientId = std::make_shared<ClientId>(message.getClientId());

outputStream << CommonAPI::Deployable<AttributeType_, AttributeDepl_>((stub.get()->*getStubFunctor_)(clientId), depl_);
auto stubAdapter = stub->StubType::getStubAdapter();
stubAdapter->lockAttributes();
auto deployable = CommonAPI::Deployable<AttributeType_, AttributeDepl_>((stub.get()->*getStubFunctor_)(clientId), depl_);
stubAdapter->unlockAttributes();

outputStream << deployable;
outputStream.flush();

return _connection->sendMessage(reply);
Expand Down Expand Up @@ -902,7 +909,10 @@ class SetObservableAttributeStubDispatcher: public SetAttributeStubDispatcher<St

private:
inline void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> _client, const std::shared_ptr<StubClass_> _stub) {
(_stub->StubType::getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(_client, _stub));
auto stubAdapter = _stub->StubType::getStubAdapter();
stubAdapter->lockAttributes();
(stubAdapter.get()->*fireChangedFunctor_)(this->getAttributeValue(_client, _stub));
stubAdapter->unlockAttributes();
}

const FireChangedFunctor fireChangedFunctor_;
Expand Down
9 changes: 8 additions & 1 deletion include/CommonAPI/SomeIP/Watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class Watch : public CommonAPI::Watch {
void processQueueEntry(std::shared_ptr<QueueEntry> _queueEntry);

private:
#ifdef _WIN32
int pipeFileDescriptors_[2];
#else
int eventFd_;
#endif

pollfd pollFileDescriptor_;
std::vector<CommonAPI::DispatchSource*> dependentDispatchSources_;
Expand All @@ -70,9 +74,12 @@ class Watch : public CommonAPI::Watch {

std::weak_ptr<Connection> connection_;

const int pipeValue_;
#ifdef _WIN32
HANDLE wsaEvent_;
const int pipeValue_;
#else
const std::uint64_t eventFdValue_;

#endif
};

Expand Down
25 changes: 17 additions & 8 deletions src/CommonAPI/SomeIP/Watch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@
#include <ws2tcpip.h>
#else
#include <unistd.h>
#include <sys/eventfd.h>
#endif

#include <CommonAPI/SomeIP/Connection.hpp>

namespace CommonAPI {
namespace SomeIP {

Watch::Watch(const std::shared_ptr<Connection>& _connection) : pipeValue_(4) {
Watch::Watch(const std::shared_ptr<Connection>& _connection) :
#ifdef _WIN32
pipeValue_(4)
#else
eventFd_(0),
eventFdValue_(1)
#endif
{
#ifdef _WIN32
WSADATA wsaData;
int iResult;
Expand Down Expand Up @@ -144,12 +152,14 @@ Watch::Watch(const std::shared_ptr<Connection>& _connection) : pipeValue_(4) {
closesocket(ListenSocket);
WSACleanup();
}
pollFileDescriptor_.fd = pipeFileDescriptors_[0];
#else
if(pipe2(pipeFileDescriptors_, O_NONBLOCK) == -1) {
eventFd_ = eventfd(0, EFD_NONBLOCK | EFD_SEMAPHORE);
if (eventFd_ == -1) {
std::perror(__func__);
}
pollFileDescriptor_.fd = eventFd_;
#endif
pollFileDescriptor_.fd = pipeFileDescriptors_[0];
pollFileDescriptor_.events = POLLIN;

connection_ = _connection;
Expand All @@ -169,8 +179,7 @@ Watch::~Watch() {
closesocket(pipeFileDescriptors_[0]);
WSACleanup();
#else
close(pipeFileDescriptors_[0]);
close(pipeFileDescriptors_[1]);
close(eventFd_);
#endif
}

Expand Down Expand Up @@ -228,7 +237,7 @@ void Watch::pushQueue(std::shared_ptr<QueueEntry> _queueEntry) {
}
}
#else
while (write(pipeFileDescriptors_[1], &pipeValue_, sizeof(pipeValue_)) == -1) {
while (write(eventFd_, &eventFdValue_, sizeof(eventFdValue_)) == -1) {
if (errno != EAGAIN && errno != EINTR) {
std::perror(__func__);
break;
Expand Down Expand Up @@ -256,8 +265,8 @@ void Watch::popQueue() {
printf("recv failed with error: %d\n", WSAGetLastError());
}
#else
int readValue = 0;
while (read(pipeFileDescriptors_[0], &readValue, sizeof(readValue)) == -1) {
std::uint64_t readValue(0);
while (read(eventFd_, &readValue, sizeof(readValue)) == -1) {
if (errno != EAGAIN && errno != EINTR) {
std::perror(__func__);
break;
Expand Down

0 comments on commit 52c9d21

Please sign in to comment.