Skip to content

Commit 4c4b1a9

Browse files
authored
[orc-rt] Replace wrapper fn void *CallCtx arg with uint64_t CallId. (#167452)
This argument serves as an opaque id (outside the ControllerAccess object) for a call to a wrapper function. I expect that most ControllerAccess implementations will want to use this argument as a sequence number (plain integer), for which uint64_t will be a better fit than void*. For ControllerAccess implementations that want to use a pointer, uint64_t should be sufficiently large.
1 parent f2aad35 commit 4c4b1a9

File tree

7 files changed

+60
-54
lines changed

7 files changed

+60
-54
lines changed

orc-rt/include/orc-rt-c/WrapperFunction.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ typedef struct {
5454
* Asynchronous return function for an orc-rt wrapper function.
5555
*/
5656
typedef void (*orc_rt_WrapperFunctionReturn)(
57-
orc_rt_SessionRef Session, void *CallCtx,
57+
orc_rt_SessionRef Session, uint64_t CallId,
5858
orc_rt_WrapperFunctionBuffer ResultBytes);
5959

6060
/**
6161
* orc-rt wrapper function prototype.
6262
*
6363
* ArgBytes contains the serialized arguments for the wrapper function.
6464
* Session holds a reference to the session object.
65-
* CallCtx holds a pointer to the context object for this particular call.
65+
* CallId holds a pointer to the context object for this particular call.
6666
* Return holds a pointer to the return function.
6767
*/
68-
typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef Session, void *CallCtx,
68+
typedef void (*orc_rt_WrapperFunction)(orc_rt_SessionRef Session,
69+
uint64_t CallId,
6970
orc_rt_WrapperFunctionReturn Return,
7071
orc_rt_WrapperFunctionBuffer ArgBytes);
7172

orc-rt/include/orc-rt/SPSWrapperFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ template <typename SPSSig> struct SPSWrapperFunction {
124124
}
125125

126126
template <typename Handler>
127-
static void handle(orc_rt_SessionRef Session, void *CallCtx,
127+
static void handle(orc_rt_SessionRef Session, uint64_t CallId,
128128
orc_rt_WrapperFunctionReturn Return,
129129
WrapperFunctionBuffer ArgBytes, Handler &&H) {
130-
WrapperFunction::handle(Session, CallCtx, Return, std::move(ArgBytes),
130+
WrapperFunction::handle(Session, CallId, Return, std::move(ArgBytes),
131131
WrapperFunctionSPSSerializer<SPSSig>(),
132132
std::forward<Handler>(H));
133133
}

orc-rt/include/orc-rt/SimpleNativeMemoryMap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ class SimpleNativeMemoryMap : public ResourceManager {
114114
} // namespace orc_rt
115115

116116
ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_reserve_sps_wrapper(
117-
orc_rt_SessionRef Session, void *CallCtx,
117+
orc_rt_SessionRef Session, uint64_t CallId,
118118
orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes);
119119

120120
ORC_RT_SPS_INTERFACE void
121121
orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper(
122-
orc_rt_SessionRef Session, void *CallCtx,
122+
orc_rt_SessionRef Session, uint64_t CallId,
123123
orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes);
124124

125125
ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper(
126-
orc_rt_SessionRef Session, void *CallCtx,
126+
orc_rt_SessionRef Session, uint64_t CallId,
127127
orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes);
128128

129129
ORC_RT_SPS_INTERFACE void
130130
orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper(
131-
orc_rt_SessionRef Session, void *CallCtx,
131+
orc_rt_SessionRef Session, uint64_t CallId,
132132
orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes);
133133

134134
#endif // ORC_RT_SIMPLENATIVEMEMORYMAP_H

orc-rt/include/orc-rt/WrapperFunction.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ using WFHandlerTraits = CallableTraitsHelper<WFHandlerTraitsImpl, C>;
137137

138138
template <typename Serializer> class StructuredYieldBase {
139139
public:
140-
StructuredYieldBase(orc_rt_SessionRef Session, void *CallCtx,
140+
StructuredYieldBase(orc_rt_SessionRef Session, uint64_t CallId,
141141
orc_rt_WrapperFunctionReturn Return, Serializer &&S)
142-
: Session(Session), CallCtx(CallCtx), Return(Return),
142+
: Session(Session), CallId(CallId), Return(Return),
143143
S(std::forward<Serializer>(S)) {}
144144

145145
protected:
146146
orc_rt_SessionRef Session;
147-
void *CallCtx;
147+
uint64_t CallId;
148148
orc_rt_WrapperFunctionReturn Return;
149149
std::decay_t<Serializer> S;
150150
};
@@ -158,9 +158,9 @@ class StructuredYield<std::tuple<RetT>, Serializer>
158158
using StructuredYieldBase<Serializer>::StructuredYieldBase;
159159
void operator()(RetT &&R) {
160160
if (auto ResultBytes = this->S.result().serialize(std::forward<RetT>(R)))
161-
this->Return(this->Session, this->CallCtx, ResultBytes->release());
161+
this->Return(this->Session, this->CallId, ResultBytes->release());
162162
else
163-
this->Return(this->Session, this->CallCtx,
163+
this->Return(this->Session, this->CallId,
164164
WrapperFunctionBuffer::createOutOfBandError(
165165
"Could not serialize wrapper function result data")
166166
.release());
@@ -173,7 +173,7 @@ class StructuredYield<std::tuple<>, Serializer>
173173
public:
174174
using StructuredYieldBase<Serializer>::StructuredYieldBase;
175175
void operator()() {
176-
this->Return(this->Session, this->CallCtx,
176+
this->Return(this->Session, this->CallId,
177177
WrapperFunctionBuffer().release());
178178
}
179179
};
@@ -251,12 +251,12 @@ struct WrapperFunction {
251251
///
252252
///
253253
/// static void adder_add_async_sps_wrapper(
254-
/// orc_rt_SessionRef Session, void *CallCtx,
254+
/// orc_rt_SessionRef Session, uint64_t CallId,
255255
/// orc_rt_WrapperFunctionReturn Return,
256256
/// orc_rt_WrapperFunctionBuffer ArgBytes) {
257257
/// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool);
258258
/// SPSWrapperFunction<SPSSig>::handle(
259-
/// Session, CallCtx, Return, ArgBytes,
259+
/// Session, CallId, Return, ArgBytes,
260260
/// WrapperFunction::handleWithAsyncMethod(&MyClass::myMethod));
261261
/// }
262262
/// @endcode
@@ -313,12 +313,12 @@ struct WrapperFunction {
313313
///
314314
///
315315
/// static void adder_add_sync_sps_wrapper(
316-
/// orc_rt_SessionRef Session, void *CallCtx,
316+
/// orc_rt_SessionRef Session, uint64_t CallId,
317317
/// orc_rt_WrapperFunctionReturn Return,
318318
/// orc_rt_WrapperFunctionBuffer ArgBytes) {
319319
/// using SPSSig = SPSString(SPSExecutorAddr, int32_t, bool);
320320
/// SPSWrapperFunction<SPSSig>::handle(
321-
/// Session, CallCtx, Return, ArgBytes,
321+
/// Session, CallId, Return, ArgBytes,
322322
/// WrapperFunction::handleWithSyncMethod(&Adder::addSync));
323323
/// }
324324
/// @endcode
@@ -368,7 +368,7 @@ struct WrapperFunction {
368368
/// This utility deserializes and serializes arguments and return values
369369
/// (using the given Serializer), and calls the given handler.
370370
template <typename Serializer, typename Handler>
371-
static void handle(orc_rt_SessionRef Session, void *CallCtx,
371+
static void handle(orc_rt_SessionRef Session, uint64_t CallId,
372372
orc_rt_WrapperFunctionReturn Return,
373373
WrapperFunctionBuffer ArgBytes, Serializer &&S,
374374
Handler &&H) {
@@ -380,16 +380,16 @@ struct WrapperFunction {
380380
typedef typename CallableArgInfo<Yield>::args_tuple_type RetTupleType;
381381

382382
if (ArgBytes.getOutOfBandError())
383-
return Return(Session, CallCtx, ArgBytes.release());
383+
return Return(Session, CallId, ArgBytes.release());
384384

385385
if (auto Args = S.arguments().template deserialize<ArgTuple>(ArgBytes))
386386
std::apply(HandlerTraits::forwardArgsAsRequested(bind_front(
387387
std::forward<Handler>(H),
388388
detail::StructuredYield<RetTupleType, Serializer>(
389-
Session, CallCtx, Return, std::move(S)))),
389+
Session, CallId, Return, std::move(S)))),
390390
*Args);
391391
else
392-
Return(Session, CallCtx,
392+
Return(Session, CallId,
393393
WrapperFunctionBuffer::createOutOfBandError(
394394
"Could not deserialize wrapper function arg data")
395395
.release());

orc-rt/lib/executor/SimpleNativeMemoryMap.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,45 +367,45 @@ Error SimpleNativeMemoryMap::recordDeallocActions(
367367
}
368368

369369
ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_reserve_sps_wrapper(
370-
orc_rt_SessionRef Session, void *CallCtx,
370+
orc_rt_SessionRef Session, uint64_t CallId,
371371
orc_rt_WrapperFunctionReturn Return,
372372
orc_rt_WrapperFunctionBuffer ArgBytes) {
373373
using Sig = SPSExpected<SPSExecutorAddr>(SPSExecutorAddr, SPSSize);
374374
SPSWrapperFunction<Sig>::handle(
375-
Session, CallCtx, Return, ArgBytes,
375+
Session, CallId, Return, ArgBytes,
376376
WrapperFunction::handleWithAsyncMethod(&SimpleNativeMemoryMap::reserve));
377377
}
378378

379379
ORC_RT_SPS_INTERFACE void
380380
orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper(
381-
orc_rt_SessionRef Session, void *CallCtx,
381+
orc_rt_SessionRef Session, uint64_t CallId,
382382
orc_rt_WrapperFunctionReturn Return,
383383
orc_rt_WrapperFunctionBuffer ArgBytes) {
384384
using Sig = SPSError(SPSExecutorAddr, SPSSequence<SPSExecutorAddr>);
385-
SPSWrapperFunction<Sig>::handle(Session, CallCtx, Return, ArgBytes,
385+
SPSWrapperFunction<Sig>::handle(Session, CallId, Return, ArgBytes,
386386
WrapperFunction::handleWithAsyncMethod(
387387
&SimpleNativeMemoryMap::releaseMultiple));
388388
}
389389

390390
ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper(
391-
orc_rt_SessionRef Session, void *CallCtx,
391+
orc_rt_SessionRef Session, uint64_t CallId,
392392
orc_rt_WrapperFunctionReturn Return,
393393
orc_rt_WrapperFunctionBuffer ArgBytes) {
394394
using Sig = SPSExpected<SPSExecutorAddr>(
395395
SPSExecutorAddr, SPSSimpleNativeMemoryMapInitializeRequest);
396-
SPSWrapperFunction<Sig>::handle(Session, CallCtx, Return, ArgBytes,
396+
SPSWrapperFunction<Sig>::handle(Session, CallId, Return, ArgBytes,
397397
WrapperFunction::handleWithAsyncMethod(
398398
&SimpleNativeMemoryMap::initialize));
399399
}
400400

401401
ORC_RT_SPS_INTERFACE void
402402
orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper(
403-
orc_rt_SessionRef Session, void *CallCtx,
403+
orc_rt_SessionRef Session, uint64_t CallId,
404404
orc_rt_WrapperFunctionReturn Return,
405405
orc_rt_WrapperFunctionBuffer ArgBytes) {
406406
using Sig = SPSError(SPSExecutorAddr, SPSSequence<SPSExecutorAddr>);
407407
SPSWrapperFunction<Sig>::handle(
408-
Session, CallCtx, Return, ArgBytes,
408+
Session, CallId, Return, ArgBytes,
409409
WrapperFunction::handleWithAsyncMethod(
410410
&SimpleNativeMemoryMap::deinitializeMultiple));
411411
}

orc-rt/unittests/DirectCaller.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class DirectCaller {
2222
virtual ~DirectResultSender() {}
2323
virtual void send(orc_rt_SessionRef Session,
2424
orc_rt::WrapperFunctionBuffer ResultBytes) = 0;
25-
static void send(orc_rt_SessionRef Session, void *CallCtx,
25+
static void send(orc_rt_SessionRef Session, uint64_t CallId,
2626
orc_rt_WrapperFunctionBuffer ResultBytes) {
2727
std::unique_ptr<DirectResultSender>(
28-
reinterpret_cast<DirectResultSender *>(CallCtx))
28+
reinterpret_cast<DirectResultSender *>(
29+
static_cast<uintptr_t>(CallId)))
2930
->send(Session, ResultBytes);
3031
}
3132
};
@@ -59,7 +60,8 @@ class DirectCaller {
5960
orc_rt::WrapperFunctionBuffer ArgBytes) {
6061
auto DR =
6162
makeDirectResultSender(std::forward<HandleResultFn>(HandleResult));
62-
Fn(Session, reinterpret_cast<void *>(DR.release()),
63+
Fn(Session,
64+
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(DR.release())),
6365
DirectResultSender::send, ArgBytes.release());
6466
}
6567

orc-rt/unittests/SPSWrapperFunctionTest.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
using namespace orc_rt;
2424

25-
static void void_noop_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
25+
static void void_noop_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId,
2626
orc_rt_WrapperFunctionReturn Return,
2727
orc_rt_WrapperFunctionBuffer ArgBytes) {
2828
SPSWrapperFunction<void()>::handle(
29-
Session, CallCtx, Return, ArgBytes,
29+
Session, CallId, Return, ArgBytes,
3030
[](move_only_function<void()> Return) { Return(); });
3131
}
3232

@@ -40,11 +40,12 @@ TEST(SPSWrapperFunctionUtilsTest, VoidNoop) {
4040
EXPECT_TRUE(Ran);
4141
}
4242

43-
static void add_via_lambda_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
43+
static void add_via_lambda_sps_wrapper(orc_rt_SessionRef Session,
44+
uint64_t CallId,
4445
orc_rt_WrapperFunctionReturn Return,
4546
orc_rt_WrapperFunctionBuffer ArgBytes) {
4647
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
47-
Session, CallCtx, Return, ArgBytes,
48+
Session, CallId, Return, ArgBytes,
4849
[](move_only_function<void(int32_t)> Return, int32_t X, int32_t Y) {
4950
Return(X + Y);
5051
});
@@ -64,11 +65,11 @@ static void add_via_function(move_only_function<void(int32_t)> Return,
6465
}
6566

6667
static void
67-
add_via_function_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
68+
add_via_function_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId,
6869
orc_rt_WrapperFunctionReturn Return,
6970
orc_rt_WrapperFunctionBuffer ArgBytes) {
7071
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
71-
Session, CallCtx, Return, ArgBytes, add_via_function);
72+
Session, CallId, Return, ArgBytes, add_via_function);
7273
}
7374

7475
TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) {
@@ -80,11 +81,11 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunction) {
8081
}
8182

8283
static void
83-
add_via_function_pointer_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
84+
add_via_function_pointer_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId,
8485
orc_rt_WrapperFunctionReturn Return,
8586
orc_rt_WrapperFunctionBuffer ArgBytes) {
8687
SPSWrapperFunction<int32_t(int32_t, int32_t)>::handle(
87-
Session, CallCtx, Return, ArgBytes, &add_via_function);
88+
Session, CallId, Return, ArgBytes, &add_via_function);
8889
}
8990

9091
TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) {
@@ -96,11 +97,12 @@ TEST(SPSWrapperFunctionUtilsTest, BinaryOpViaFunctionPointer) {
9697
}
9798

9899
static void
99-
round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
100+
round_trip_string_via_span_sps_wrapper(orc_rt_SessionRef Session,
101+
uint64_t CallId,
100102
orc_rt_WrapperFunctionReturn Return,
101103
orc_rt_WrapperFunctionBuffer ArgBytes) {
102104
SPSWrapperFunction<SPSString(SPSString)>::handle(
103-
Session, CallCtx, Return, ArgBytes,
105+
Session, CallId, Return, ArgBytes,
104106
[](move_only_function<void(std::string)> Return, span<const char> S) {
105107
Return({S.data(), S.size()});
106108
});
@@ -119,11 +121,11 @@ TEST(SPSWrapperFunctionUtilsTest, RoundTripStringViaSpan) {
119121
}
120122

121123
static void improbable_feat_sps_wrapper(orc_rt_SessionRef Session,
122-
void *CallCtx,
124+
uint64_t CallId,
123125
orc_rt_WrapperFunctionReturn Return,
124126
orc_rt_WrapperFunctionBuffer ArgBytes) {
125127
SPSWrapperFunction<SPSError(bool)>::handle(
126-
Session, CallCtx, Return, ArgBytes,
128+
Session, CallId, Return, ArgBytes,
127129
[](move_only_function<void(Error)> Return, bool LuckyHat) {
128130
if (LuckyHat)
129131
Return(Error::success());
@@ -155,11 +157,11 @@ TEST(SPSWrapperFunctionUtilsTest, TransparentConversionErrorFailureCase) {
155157
EXPECT_EQ(ErrMsg, "crushed by boulder");
156158
}
157159

158-
static void halve_number_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
160+
static void halve_number_sps_wrapper(orc_rt_SessionRef Session, uint64_t CallId,
159161
orc_rt_WrapperFunctionReturn Return,
160162
orc_rt_WrapperFunctionBuffer ArgBytes) {
161163
SPSWrapperFunction<SPSExpected<int32_t>(int32_t)>::handle(
162-
Session, CallCtx, Return, ArgBytes,
164+
Session, CallId, Return, ArgBytes,
163165
[](move_only_function<void(Expected<int32_t>)> Return, int N) {
164166
if (N % 2 == 0)
165167
Return(N >> 1);
@@ -208,12 +210,12 @@ class SPSSerializationTraits<SPSOpCounter<N>, OpCounter<N>> {
208210

209211
static void
210212
handle_with_reference_types_sps_wrapper(orc_rt_SessionRef Session,
211-
void *CallCtx,
213+
uint64_t CallId,
212214
orc_rt_WrapperFunctionReturn Return,
213215
orc_rt_WrapperFunctionBuffer ArgBytes) {
214216
SPSWrapperFunction<void(
215217
SPSOpCounter<0>, SPSOpCounter<1>, SPSOpCounter<2>,
216-
SPSOpCounter<3>)>::handle(Session, CallCtx, Return, ArgBytes,
218+
SPSOpCounter<3>)>::handle(Session, CallId, Return, ArgBytes,
217219
[](move_only_function<void()> Return,
218220
OpCounter<0>, OpCounter<1> &,
219221
const OpCounter<2> &,
@@ -281,11 +283,11 @@ class Adder {
281283
} // anonymous namespace
282284

283285
static void adder_add_async_sps_wrapper(orc_rt_SessionRef Session,
284-
void *CallCtx,
286+
uint64_t CallId,
285287
orc_rt_WrapperFunctionReturn Return,
286288
orc_rt_WrapperFunctionBuffer ArgBytes) {
287289
SPSWrapperFunction<int32_t(SPSExecutorAddr, int32_t, int32_t)>::handle(
288-
Session, CallCtx, Return, ArgBytes,
290+
Session, CallId, Return, ArgBytes,
289291
WrapperFunction::handleWithAsyncMethod(&Adder::addAsync));
290292
}
291293

@@ -300,11 +302,12 @@ TEST(SPSWrapperFunctionUtilsTest, HandleWtihAsyncMethod) {
300302
EXPECT_EQ(Result, 42);
301303
}
302304

303-
static void adder_add_sync_sps_wrapper(orc_rt_SessionRef Session, void *CallCtx,
305+
static void adder_add_sync_sps_wrapper(orc_rt_SessionRef Session,
306+
uint64_t CallId,
304307
orc_rt_WrapperFunctionReturn Return,
305308
orc_rt_WrapperFunctionBuffer ArgBytes) {
306309
SPSWrapperFunction<int32_t(SPSExecutorAddr, int32_t, int32_t)>::handle(
307-
Session, CallCtx, Return, ArgBytes,
310+
Session, CallId, Return, ArgBytes,
308311
WrapperFunction::handleWithSyncMethod(&Adder::addSync));
309312
}
310313

0 commit comments

Comments
 (0)