You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If we can't initialize enterprise, we probably are missing enterprise.server.url
288
+
// and our license surely is not valid.
289
+
if !enterprise::is_server_initialized() && !enterprise::initialize_server(){
290
+
returnNone;
291
+
}
292
+
// If Enterprise thinks we are using a floating license, then report it will be in the keychain
293
+
if enterprise::is_server_floating_license(){
294
+
Some(LicenseLocation::Keychain)
295
+
}else{
296
+
None
297
+
}
298
+
}else{
299
+
None
278
300
}
279
301
}
280
302
}
281
303
}
282
304
}
283
305
284
306
/// Wrapper for [`init`] and [`shutdown`]. Instantiating this at the top of your script will initialize everything correctly and then clean itself up at exit as well.
285
-
pubstructSession{}
307
+
pubstructSession{
308
+
index:usize,
309
+
}
286
310
287
311
implSession{
288
312
/// Get a registered [`Session`] for use.
289
313
///
290
314
/// This is required so that we can keep track of the [`SESSION_COUNT`].
291
315
fnregistered_session() -> Self{
292
-
let _previous_count = SESSION_COUNT.fetch_add(1,SeqCst);
293
-
Self{}
316
+
let previous_count = SESSION_COUNT.fetch_add(1,SeqCst);
317
+
Self{
318
+
index: previous_count,
319
+
}
294
320
}
295
321
296
322
/// Before calling new you must make sure that the license is retrievable, otherwise the core won't be able to initialize.
@@ -300,10 +326,18 @@ impl Session {
300
326
pubfnnew() -> Result<Self,InitializationError>{
301
327
iflicense_location().is_some(){
302
328
// We were able to locate a license, continue with initialization.
303
-
// Grab the session before initialization to prevent another thread from initializing
304
-
// and shutting down before this thread can increment the SESSION_COUNT.
329
+
330
+
// Grab the lock before initialization to prevent another thread from initializing
331
+
// and racing the call to BNInitPlugins.
332
+
let _lock = INIT_LOCK
333
+
.lock()
334
+
.map_err(|_| InitializationError::InitMutex)?;
305
335
let session = Self::registered_session();
306
-
init()?;
336
+
// Since this whole section is locked, we're guaranteed to be index 0 if we're first.
337
+
// Only the first thread hitting this should be allowed to call BNInitPlugins
338
+
if session.index == 0{
339
+
init()?;
340
+
}
307
341
Ok(session)
308
342
}else{
309
343
// There was no license that could be automatically retrieved, you must call [Self::new_with_license].
@@ -316,8 +350,18 @@ impl Session {
316
350
/// This differs from [`Session::new`] in that it does not check to see if there is a license that the core
317
351
/// can discover by itself, therefor it is expected that you know where your license is when calling this directly.
0 commit comments