|
72 | 72 |
|
73 | 73 | # default session |
74 | 74 |
|
75 | | -default_msession = nothing |
| 75 | +const default_msession_ref = Ref{MSession}() |
76 | 76 |
|
77 | | -function restart_default_msession(bufsize::Integer = default_output_buffer_size) |
78 | | - global default_msession |
79 | | - if default_msession !== nothing && default_msession.ptr != C_NULL |
80 | | - close(default_msession) |
| 77 | +# this function will start an MSession if default_msession_ref is undefined or if the |
| 78 | +# MSession has been closed so that the engine ptr is void |
| 79 | +function get_default_msession() |
| 80 | + if !isassigned(default_msession_ref) || default_msession_ref[].ptr == C_NULL |
| 81 | + default_msession_ref[] = MSession() |
81 | 82 | end |
82 | | - default_msession = MSession(bufsize) |
83 | | - return nothing |
| 83 | + return default_msession_ref[] |
84 | 84 | end |
85 | 85 |
|
86 | | - |
87 | | -function get_default_msession() |
88 | | - global default_msession |
89 | | - if default_msession === nothing |
90 | | - default_msession = MSession() |
91 | | - end |
92 | | - return default_msession::MSession |
| 86 | +function restart_default_msession(bufsize::Integer = default_output_buffer_size) |
| 87 | + close_default_msession() |
| 88 | + default_msession_ref[] = MSession(bufsize) |
| 89 | + return nothing |
93 | 90 | end |
94 | 91 |
|
95 | 92 | function close_default_msession() |
96 | | - global default_msession |
97 | | - if default_msession !== nothing |
98 | | - close(default_msession) |
99 | | - default_msession = nothing |
| 93 | + if isassigned(default_msession_ref) && default_msession_ref[].ptr !== C_NULL |
| 94 | + close(default_msession_ref[]) |
100 | 95 | end |
101 | 96 | return nothing |
102 | 97 | end |
|
0 commit comments