Skip to content

Commit b6f19b7

Browse files
committed
move mex engine pointer from static variable to nonstatic
1 parent 0c04eea commit b6f19b7

18 files changed

+86
-39
lines changed

api/metrics/+opentelemetry/+metrics/AsynchronousInstrument.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function removeCallback(obj, callback)
6464
end
6565
if sum(found) > 0
6666
idx = find(found,1); % remove only the first match
67-
obj.Proxy.removeCallback(callback, idx);
67+
obj.Proxy.removeCallback(idx);
6868
% update Callback property
6969
if isa(obj.Callbacks, "function_handle")
7070
obj.Callbacks = [];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2024 The MathWorks, Inc.
2+
3+
#pragma once
4+
5+
#include "MatlabDataArray.hpp"
6+
#include "mex.hpp"
7+
8+
namespace libmexclass::opentelemetry {
9+
struct AsynchronousCallbackInput
10+
{
11+
AsynchronousCallbackInput(const matlab::data::Array& fh,
12+
const std::shared_ptr<matlab::engine::MATLABEngine> eng)
13+
: FunctionHandle(fh), MexEngine(eng) {}
14+
15+
matlab::data::Array FunctionHandle;
16+
const std::shared_ptr<matlab::engine::MATLABEngine> MexEngine;
17+
};
18+
} // namespace libmexclass::opentelemetry
19+
20+

api/metrics/include/opentelemetry-matlab/metrics/AsynchronousInstrumentProxy.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <list>
66

7+
#include "opentelemetry-matlab/metrics/AsynchronousCallbackInput.h"
8+
79
#include "libmexclass/proxy/Proxy.h"
810
#include "libmexclass/proxy/method/Context.h"
911

@@ -15,7 +17,8 @@ namespace nostd = opentelemetry::nostd;
1517
namespace libmexclass::opentelemetry {
1618
class AsynchronousInstrumentProxy : public libmexclass::proxy::Proxy {
1719
protected:
18-
AsynchronousInstrumentProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> inst) : CppInstrument(inst) {}
20+
AsynchronousInstrumentProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> inst,
21+
const std::shared_ptr<matlab::engine::MATLABEngine> eng) : CppInstrument(inst), MexEngine(eng) {}
1922

2023
public:
2124
void addCallback(libmexclass::proxy::method::Context& context);
@@ -29,8 +32,9 @@ class AsynchronousInstrumentProxy : public libmexclass::proxy::Proxy {
2932
private:
3033
nostd::shared_ptr<metrics_api::ObservableInstrument> CppInstrument;
3134

32-
std::list<matlab::data::Array> CallbackFunctions;
35+
std::list<AsynchronousCallbackInput> CallbackInputs;
3336

37+
const std::shared_ptr<matlab::engine::MATLABEngine> MexEngine; // used for feval on callbacks
3438
};
3539
} // namespace libmexclass::opentelemetry
3640

api/metrics/include/opentelemetry-matlab/metrics/AsynchronousInstrumentProxyFactory.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ enum class AsynchronousInstrumentType {ObservableCounter, ObservableUpDownCounte
1515

1616
class AsynchronousInstrumentProxyFactory {
1717
public:
18-
AsynchronousInstrumentProxyFactory(nostd::shared_ptr<metrics_api::Meter> mt) : CppMeter(mt) {}
18+
AsynchronousInstrumentProxyFactory(nostd::shared_ptr<metrics_api::Meter> mt,
19+
const std::shared_ptr<matlab::engine::MATLABEngine> eng)
20+
: CppMeter(mt), MexEngine(eng) {}
1921

2022
std::shared_ptr<libmexclass::proxy::Proxy> create(AsynchronousInstrumentType type,
2123
const matlab::data::Array& callback, const std::string& name, const std::string& description,
@@ -24,5 +26,6 @@ class AsynchronousInstrumentProxyFactory {
2426
private:
2527

2628
nostd::shared_ptr<metrics_api::Meter> CppMeter;
29+
const std::shared_ptr<matlab::engine::MATLABEngine> MexEngine; // used for feval on callbacks
2730
};
2831
} // namespace libmexclass::opentelemetry

api/metrics/include/opentelemetry-matlab/metrics/MeasurementFetcher.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -9,7 +9,6 @@ class MeasurementFetcher
99
{
1010
public:
1111
static void Fetcher(metrics_api::ObserverResult observer_result, void * /* state */);
12-
static std::shared_ptr<matlab::engine::MATLABEngine> mlptr;
1312
};
1413
} // namespace libmexclass::opentelemetry
1514

api/metrics/include/opentelemetry-matlab/metrics/MeterProviderProxy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -18,7 +18,7 @@ namespace nostd = opentelemetry::nostd;
1818
namespace libmexclass::opentelemetry {
1919
class MeterProviderProxy : public libmexclass::proxy::Proxy {
2020
public:
21-
MeterProviderProxy(nostd::shared_ptr<metrics_api::MeterProvider> mp) : CppMeterProvider(mp) {
21+
MeterProviderProxy(nostd::shared_ptr<metrics_api::MeterProvider> mp) : CppMeterProvider(mp), MexEngine(nullptr) {
2222
REGISTER_METHOD(MeterProviderProxy, getMeter);
2323
REGISTER_METHOD(MeterProviderProxy, setMeterProvider);
2424
REGISTER_METHOD(MeterProviderProxy, postShutdown);
@@ -46,5 +46,6 @@ class MeterProviderProxy : public libmexclass::proxy::Proxy {
4646

4747
protected:
4848
nostd::shared_ptr<metrics_api::MeterProvider> CppMeterProvider;
49+
std::shared_ptr<matlab::engine::MATLABEngine> MexEngine; // mex engine pointer used by asynchronous instruments for feval
4950
};
5051
} // namespace libmexclass::opentelemetry

api/metrics/include/opentelemetry-matlab/metrics/MeterProxy.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -22,7 +22,8 @@ namespace nostd = opentelemetry::nostd;
2222
namespace libmexclass::opentelemetry {
2323
class MeterProxy : public libmexclass::proxy::Proxy {
2424
public:
25-
MeterProxy(nostd::shared_ptr<metrics_api::Meter> mt) : CppMeter(mt) {
25+
MeterProxy(nostd::shared_ptr<metrics_api::Meter> mt, const std::shared_ptr<matlab::engine::MATLABEngine> eng)
26+
: CppMeter(mt), MexEngine(eng) {
2627
REGISTER_METHOD(MeterProxy, createCounter);
2728
REGISTER_METHOD(MeterProxy, createUpDownCounter);
2829
REGISTER_METHOD(MeterProxy, createHistogram);
@@ -49,5 +50,7 @@ class MeterProxy : public libmexclass::proxy::Proxy {
4950
void createSynchronous(libmexclass::proxy::method::Context& context, SynchronousInstrumentType type);
5051

5152
nostd::shared_ptr<metrics_api::Meter> CppMeter;
53+
54+
const std::shared_ptr<matlab::engine::MATLABEngine> MexEngine; // mex engine pointer used by asynchronous instruments for feval
5255
};
5356
} // namespace libmexclass::opentelemetry

api/metrics/include/opentelemetry-matlab/metrics/ObservableCounterProxy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -10,7 +10,9 @@ namespace nostd = opentelemetry::nostd;
1010
namespace libmexclass::opentelemetry {
1111
class ObservableCounterProxy : public AsynchronousInstrumentProxy {
1212
public:
13-
ObservableCounterProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> ct) : AsynchronousInstrumentProxy(ct) {
13+
ObservableCounterProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> ct,
14+
const std::shared_ptr<matlab::engine::MATLABEngine> eng)
15+
: AsynchronousInstrumentProxy(ct, eng) {
1416
REGISTER_METHOD(ObservableCounterProxy, addCallback);
1517
REGISTER_METHOD(ObservableCounterProxy, removeCallback);
1618
}

api/metrics/include/opentelemetry-matlab/metrics/ObservableGaugeProxy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -10,7 +10,9 @@ namespace nostd = opentelemetry::nostd;
1010
namespace libmexclass::opentelemetry {
1111
class ObservableGaugeProxy : public AsynchronousInstrumentProxy {
1212
public:
13-
ObservableGaugeProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> g) : AsynchronousInstrumentProxy(g) {
13+
ObservableGaugeProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> g,
14+
const std::shared_ptr<matlab::engine::MATLABEngine> eng)
15+
: AsynchronousInstrumentProxy(g, eng) {
1416
REGISTER_METHOD(ObservableGaugeProxy, addCallback);
1517
REGISTER_METHOD(ObservableGaugeProxy, removeCallback);
1618
}

api/metrics/include/opentelemetry-matlab/metrics/ObservableUpDownCounterProxy.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2023-2024 The MathWorks, Inc.
22

33
#pragma once
44

@@ -10,7 +10,9 @@ namespace nostd = opentelemetry::nostd;
1010
namespace libmexclass::opentelemetry {
1111
class ObservableUpDownCounterProxy : public AsynchronousInstrumentProxy {
1212
public:
13-
ObservableUpDownCounterProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> ct) : AsynchronousInstrumentProxy(ct) {
13+
ObservableUpDownCounterProxy(nostd::shared_ptr<metrics_api::ObservableInstrument> ct,
14+
const std::shared_ptr<matlab::engine::MATLABEngine> eng)
15+
: AsynchronousInstrumentProxy(ct, eng) {
1416
REGISTER_METHOD(ObservableUpDownCounterProxy, addCallback);
1517
REGISTER_METHOD(ObservableUpDownCounterProxy, removeCallback);
1618
}

0 commit comments

Comments
 (0)