Skip to content

Commit 4b1acc3

Browse files
committed
iox-eclipse-iceoryx#33 added static cast to help with template deduction; decltype in duration used for platform independent conversion; other windows platform tweaks
Signed-off-by: Christian Eltzschig <[email protected]>
1 parent 2fd3f0f commit 4b1acc3

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

iceoryx_utils/include/iceoryx_utils/cxx/smart_c.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#pragma once
1616

17+
#include "iceoryx_utils/platform/platform-correction.hpp"
18+
1719
#include <cstring>
1820
#include <initializer_list>
1921
#include <iostream>

iceoryx_utils/platform/win/include/iceoryx_utils/platform/semaphore.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ inline int sem_init(sem_t* sem, int pshared, unsigned int value)
8282
return -1;
8383
}
8484

85-
// sem_t *
86-
// sem_open( const char *name, int oflag )
87-
//{
88-
//}
85+
inline sem_t* sem_open(const char* name, int oflag)
86+
{
87+
return nullptr;
88+
}
8989

9090
inline sem_t* sem_open(const char* name, int oflag, mode_t mode, unsigned int value)
9191
{

iceoryx_utils/source/posix_wrapper/semaphore.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,12 @@ bool Semaphore::init(sem_t* handle, const int pshared, const unsigned int value)
233233

234234
bool Semaphore::open(const int oflag) noexcept
235235
{
236-
bool success = setHandleFromCall(cxx::makeSmartC(
237-
sem_open, cxx::ReturnMode::PRE_DEFINED_ERROR_CODE, {static_cast<sem_t*>(SEM_FAILED)}, {}, m_name, oflag));
236+
bool success = setHandleFromCall(cxx::makeSmartC(static_cast<sem_t* (*)(const char*, int)>(sem_open),
237+
cxx::ReturnMode::PRE_DEFINED_ERROR_CODE,
238+
{static_cast<sem_t*>(SEM_FAILED)},
239+
{},
240+
m_name,
241+
oflag));
238242

239243
if (!success)
240244
{
@@ -245,14 +249,15 @@ bool Semaphore::open(const int oflag) noexcept
245249

246250
bool Semaphore::open(const int oflag, const mode_t mode, const unsigned int value) noexcept
247251
{
248-
bool success = setHandleFromCall(cxx::makeSmartC(sem_open,
249-
cxx::ReturnMode::PRE_DEFINED_ERROR_CODE,
250-
{static_cast<sem_t*>(SEM_FAILED)},
251-
{},
252-
m_name,
253-
oflag,
254-
mode,
255-
value));
252+
bool success =
253+
setHandleFromCall(cxx::makeSmartC(static_cast<sem_t* (*)(const char*, int, mode_t, unsigned int)>(sem_open),
254+
cxx::ReturnMode::PRE_DEFINED_ERROR_CODE,
255+
{static_cast<sem_t*>(SEM_FAILED)},
256+
{},
257+
m_name,
258+
oflag,
259+
mode,
260+
value));
256261
if (!success)
257262
{
258263
m_errorValue = SemaphoreError::CREATION_FAILED;

iceoryx_utils/source/posix_wrapper/system_configuration.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "iceoryx_utils/cxx/smart_c.hpp"
1818

19+
1920
namespace iox
2021
{
2122
namespace posix

iceoryx_utils/source/units/duration.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct timespec Duration::timespec(const TimeSpecReference& reference) const
2424
switch (reference)
2525
{
2626
case TimeSpecReference::None:
27-
return {this->seconds<int>(), static_cast<int>(this->nanoSeconds<int64_t>() - this->seconds<int64_t>() * 1000000000)};
27+
return {this->seconds<int>(),
28+
static_cast<int>(this->nanoSeconds<int64_t>() - this->seconds<int64_t>() * 1000000000)};
2829
default:
2930
{
3031
struct timespec referenceTime;
@@ -46,7 +47,8 @@ struct timespec Duration::timespec(const TimeSpecReference& reference) const
4647
int64_t seconds = this->seconds<int64_t>() + referenceTime.tv_sec + sumOfNanoSeconds / NanoSecondsPerSecond;
4748
int64_t nanoSeconds = sumOfNanoSeconds % NanoSecondsPerSecond;
4849

49-
return {seconds, nanoSeconds};
50+
return {static_cast<decltype(referenceTime.tv_sec)>(seconds),
51+
static_cast<decltype(referenceTime.tv_nsec)>(nanoSeconds)};
5052
}
5153
}
5254
}

0 commit comments

Comments
 (0)