Skip to content

Commit d915468

Browse files
committed
add C++ semaphore API
1 parent 2916152 commit d915468

1 file changed

Lines changed: 61 additions & 4 deletions

File tree

include/OpenImageDenoise/oidn.hpp

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ OIDN_NAMESPACE_BEGIN
248248
oidnReleaseBuffer(handle);
249249
}
250250

251-
OIDNBuffer getHandle() const
251+
const OIDNBuffer& getHandle() const
252252
{
253253
return handle;
254254
}
@@ -409,7 +409,7 @@ OIDN_NAMESPACE_BEGIN
409409
oidnReleaseSemaphore(handle);
410410
}
411411

412-
OIDNSemaphore getHandle() const
412+
const OIDNSemaphore& getHandle() const
413413
{
414414
return handle;
415415
}
@@ -503,7 +503,7 @@ OIDN_NAMESPACE_BEGIN
503503
oidnReleaseFilter(handle);
504504
}
505505

506-
OIDNFilter getHandle() const
506+
const OIDNFilter& getHandle() const
507507
{
508508
return handle;
509509
}
@@ -781,7 +781,7 @@ OIDN_NAMESPACE_BEGIN
781781
oidnReleaseDevice(handle);
782782
}
783783

784-
OIDNDevice getHandle() const
784+
const OIDNDevice& getHandle() const
785785
{
786786
return handle;
787787
}
@@ -899,6 +899,63 @@ OIDN_NAMESPACE_BEGIN
899899
}
900900
#endif
901901

902+
SemaphoreRef newSemaphore(OIDNExternalSemaphoreTypeFlags fdType, int fd) const
903+
{
904+
return oidnNewSharedSemaphoreFromFD(
905+
handle, static_cast<OIDNExternalSemaphoreTypeFlags>(fdType), fd);
906+
}
907+
908+
SemaphoreRef newSemaphore(OIDNExternalSemaphoreTypeFlags handleType, void* handle, const void* name) const
909+
{
910+
return oidnNewSharedSemaphoreFromWin32Handle(
911+
this->handle, static_cast<OIDNExternalSemaphoreTypeFlags>(handleType), handle, name);
912+
}
913+
914+
void signalSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value) const
915+
{
916+
oidnSignalSemaphoresAsync(handle, &semaphore.getHandle(), &value, 1);
917+
}
918+
919+
void signalSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
920+
const std::vector<uint64_t>& values) const
921+
{
922+
oidnSignalSemaphoresAsync(handle,
923+
reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
924+
values.data(),
925+
static_cast<int>(semaphores.size()));
926+
}
927+
928+
void waitSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value) const
929+
{
930+
oidnWaitSemaphoresAsync(handle, &semaphore.getHandle(), &value, nullptr, 1);
931+
}
932+
933+
void waitSemaphoreAsync(const SemaphoreRef& semaphore, uint64_t value, uint32_t timeoutMs) const
934+
{
935+
oidnWaitSemaphoresAsync(handle, &semaphore.getHandle(), &value, &timeoutMs, 1);
936+
}
937+
938+
void waitSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
939+
const std::vector<uint64_t>& values) const
940+
{
941+
oidnWaitSemaphoresAsync(handle,
942+
reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
943+
values.data(),
944+
nullptr,
945+
static_cast<int>(semaphores.size()));
946+
}
947+
948+
void waitSemaphoresAsync(const std::vector<SemaphoreRef>& semaphores,
949+
const std::vector<uint64_t>& values,
950+
const std::vector<uint32_t>& timeoutsMs) const
951+
{
952+
oidnWaitSemaphoresAsync(handle,
953+
reinterpret_cast<const OIDNSemaphore*>(semaphores.data()),
954+
values.data(),
955+
timeoutsMs.data(),
956+
static_cast<int>(semaphores.size()));
957+
}
958+
902959
// Creates a filter of the specified type (e.g. "RT").
903960
FilterRef newFilter(const char* type) const
904961
{

0 commit comments

Comments
 (0)