Skip to content

Commit

Permalink
Fix return code check for Semaphore operations #47 (#48)
Browse files Browse the repository at this point in the history
* Fix take and give semaphore operations in RTI Perftest #47
* Add CR changes
* CR Changes and documentation
  • Loading branch information
javmorcas authored Apr 4, 2018
1 parent 6974e75 commit f84bcf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
47 changes: 23 additions & 24 deletions srcCpp/RTIDDSImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void RTIDDSImpl<T>::Shutdown()
}

if(_pongSemaphore != NULL) {
RTIOsapiSemaphore_delete(_pongSemaphore);
_pongSemaphore = NULL;
RTIOsapiSemaphore_delete(_pongSemaphore);
_pongSemaphore = NULL;
}

DDSDomainParticipantFactory::finalize_instance();
Expand Down Expand Up @@ -885,42 +885,38 @@ class RTIPublisher : public IMessagingWriter
}
}

bool waitForPingResponse()
{
if(_pongSemaphore != NULL)
{
if(!RTIOsapiSemaphore_take(_pongSemaphore, NULL))
{
fprintf(stderr,"Unexpected error taking semaphore\n");
bool waitForPingResponse() {
if(_pongSemaphore != NULL) {
if(RTIOsapiSemaphore_take(_pongSemaphore, NULL)
== RTI_OSAPI_SEMAPHORE_STATUS_ERROR) {
fprintf(stderr, "Unexpected error taking semaphore\n");
return false;
}
}
return true;
}

/* time out in milliseconds */
bool waitForPingResponse(int timeout)
bool waitForPingResponse(int timeout)
{
struct RTINtpTime blockDurationIn;
RTINtpTime_packFromMillisec(blockDurationIn, 0, timeout);

if(_pongSemaphore != NULL)
{
if(!RTIOsapiSemaphore_take(_pongSemaphore, &blockDurationIn))
{
fprintf(stderr,"Unexpected error taking semaphore\n");
if(_pongSemaphore != NULL) {
if (RTIOsapiSemaphore_take(_pongSemaphore, &blockDurationIn)
== RTI_OSAPI_SEMAPHORE_STATUS_ERROR) {
fprintf(stderr, "Unexpected error taking semaphore\n");
return false;
}
}
return true;
}
}

bool notifyPingResponse()
bool notifyPingResponse()
{
if(_pongSemaphore != NULL)
{
if(!RTIOsapiSemaphore_give(_pongSemaphore))
{
if(_pongSemaphore != NULL) {
if(RTIOsapiSemaphore_give(_pongSemaphore)
!= RTI_OSAPI_SEMAPHORE_STATUS_OK) {
fprintf(stderr,"Unexpected error giving semaphore\n");
return false;
}
Expand Down Expand Up @@ -1134,7 +1130,8 @@ class RTIDynamicDataPublisher : public IMessagingWriter

bool waitForPingResponse() {
if (_pongSemaphore != NULL) {
if (!RTIOsapiSemaphore_take(_pongSemaphore, NULL)) {
if (RTIOsapiSemaphore_take(_pongSemaphore, NULL)
== RTI_OSAPI_SEMAPHORE_STATUS_ERROR) {
fprintf(stderr, "Unexpected error taking semaphore\n");
return false;
}
Expand All @@ -1148,7 +1145,8 @@ class RTIDynamicDataPublisher : public IMessagingWriter
RTINtpTime_packFromMillisec(blockDuration, 0, timeout);

if (_pongSemaphore != NULL) {
if (!RTIOsapiSemaphore_take(_pongSemaphore, &blockDuration)) {
if (RTIOsapiSemaphore_take(_pongSemaphore, &blockDuration)
== RTI_OSAPI_SEMAPHORE_STATUS_ERROR) {
fprintf(stderr, "Unexpected error taking semaphore\n");
return false;
}
Expand All @@ -1158,7 +1156,8 @@ class RTIDynamicDataPublisher : public IMessagingWriter

bool notifyPingResponse() {
if (_pongSemaphore != NULL) {
if (!RTIOsapiSemaphore_give(_pongSemaphore)) {
if (RTIOsapiSemaphore_give(_pongSemaphore)
!= RTI_OSAPI_SEMAPHORE_STATUS_OK) {
fprintf(stderr, "Unexpected error giving semaphore\n");
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions srcDoc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Release Notes 2.3.2
What's Fixed in 2.3.2
~~~~~~~~~~~~~~~~~~~~~~

Classic C++ Semaphore Take() and Give() operations not checking for errors properly (#47)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions, the semaphore Take() and Give() operations
were not being checked for error in a correct way in the Classic C++ API implementation.
This has been fixed.

Update Security Certificates and Governance files (#49)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit f84bcf9

Please sign in to comment.