Skip to content

Commit 32c0f7a

Browse files
authored
Auto-name shared objects (#4)
without names in box, to prevent aliasing
1 parent 10e083a commit 32c0f7a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/FluidPDWrapper.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ under the European Union’s Horizon 2020 research and innovation programme
1919
#include <clients/common/OfflineClient.hpp>
2020
#include <clients/common/ParameterSet.hpp>
2121
#include <clients/common/ParameterTypes.hpp>
22+
#include <clients/nrt/FluidSharedInstanceAdaptor.hpp>
2223

2324
#include <m_pd.h>
2425

2526
#include <cctype>
2627
#include <cstdarg>
2728
#include <cstring>
29+
#include <chrono>
2830
#include <tuple>
2931
#include <utility>
3032

@@ -413,6 +415,16 @@ class FluidPDWrapper : public impl::FluidPDBase<FluidPDWrapper<Client>,
413415
friend impl::RealTime<FluidPDWrapper<Client>>;
414416
friend impl::NonRealTime<FluidPDWrapper<Client>>;
415417

418+
419+
template <typename T>
420+
struct IsThreadedShared : std::false_type
421+
{};
422+
423+
template <typename T>
424+
struct IsThreadedShared<NRTThreadingAdaptor<NRTSharedInstanceAdaptor<T>>>
425+
: std::true_type
426+
{};
427+
416428
struct StreamingListInput
417429
{
418430

@@ -1079,9 +1091,30 @@ class FluidPDWrapper : public impl::FluidPDBase<FluidPDWrapper<Client>,
10791091
}
10801092
// process in-box attributes for mutable params
10811093
paramArgProcess(ac, av);
1094+
checkName(mParams);
10821095
// return params so this can be called in client initaliser
10831096
return mParams;
10841097
}
1098+
1099+
template<typename ClientType = Client>
1100+
std::enable_if_t<IsThreadedShared<ClientType>::value>
1101+
checkName(ParamSetType& params)
1102+
{
1103+
if(params.template get<0>().size() == 0)
1104+
{
1105+
const auto p1 = std::chrono::steady_clock::now();
1106+
std::stringstream ss;
1107+
ss << 'u' << std::chrono::duration_cast<std::chrono::nanoseconds>(
1108+
p1.time_since_epoch()).count();
1109+
1110+
params.template set<0>(ss.str(),nullptr);
1111+
}
1112+
}
1113+
1114+
template<typename ClientType = Client>
1115+
std::enable_if_t<!IsThreadedShared<ClientType>::value>
1116+
checkName(ParamSetType&){}
1117+
10851118

10861119
// Sets up a single parameter
10871120

0 commit comments

Comments
 (0)