|
11 | 11 | is_prime |
12 | 12 | end |
13 | 13 | methods |
14 | | - function obj = APIUtil(create) |
| 14 | + function obj = APIUtil(varargin) |
15 | 15 |
|
16 | 16 | if getenv('DSS_EXTENSIONS_DEBUG') == '1' |
17 | 17 | warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library') |
|
25 | 25 | PropertiesMOfilePath = fullfile(MfilePath, 'messages', 'properties-en-US.mo'); |
26 | 26 | DSS_MATLAB.librefcount(1); |
27 | 27 | if libisloaded(obj.libname) |
28 | | - if (nargin > 0) && (create ~= 0) |
| 28 | + if (nargin > 0) && (varargin{1} ~= 0) |
29 | 29 | obj.dssctx = calllib(obj.libname, 'ctx_New'); |
| 30 | + DSS_MATLAB.ctxrefcount(obj.dssctx, 1); |
30 | 31 | obj.is_prime = 0; |
31 | 32 | else |
32 | 33 | obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime'); |
|
44 | 45 | loadlibrary(DLLfilePath, @DSS_MATLAB.dss_capi_no_thunk); |
45 | 46 | end |
46 | 47 | calllib(obj.libname, 'DSS_Start', 0); |
47 | | - calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath); |
48 | | - if (nargin > 0) && (create ~= 0) |
| 48 | + % calllib(obj.libname, 'DSS_SetPropertiesMO', PropertiesMOfilePath); |
| 49 | + if (nargin > 0) && (varargin{1} ~= 0) |
49 | 50 | obj.dssctx = calllib(obj.libname, 'ctx_New'); |
| 51 | + DSS_MATLAB.ctxrefcount(obj.dssctx, 1); |
50 | 52 | obj.is_prime = 0; |
51 | 53 | else |
52 | 54 | obj.dssctx = calllib(obj.libname, 'ctx_Get_Prime'); |
|
56 | 58 | end |
57 | 59 |
|
58 | 60 | function delete(obj) |
59 | | - if obj.is_prime ~= 0 |
60 | | - calllib(obj.libname, 'ctx_Dispose', obj.dssctx); |
| 61 | + |
| 62 | + if obj.is_prime == 0 |
| 63 | + cnt = DSS_MATLAB.ctxrefcount(obj.dssctx, -1); |
| 64 | + if cnt == 0 |
| 65 | + calllib(obj.libname, 'ctx_Dispose', obj.dssctx); |
| 66 | + end |
61 | 67 | end |
62 | 68 |
|
63 | 69 | % If nothing is using the library, unload it. |
64 | 70 | % Required to properly exit MATLAB. |
65 | 71 | cnt = DSS_MATLAB.librefcount(-1); |
66 | 72 | if (cnt == 0) |
67 | | - prime_ctx = calllib(obj.libname, 'ctx_Get_Prime') |
| 73 | + prime_ctx = calllib(obj.libname, 'ctx_Get_Prime'); |
68 | 74 | calllib(obj.libname, 'ctx_Text_Set_Command', prime_ctx, 'Set Parallel=no'); |
69 | 75 | calllib(obj.libname, 'ctx_DSS_ClearAll', prime_ctx); |
70 | 76 | unloadlibrary(obj.libname); |
|
0 commit comments