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
297
+
// and our license surely is not valid.
298
+
if !enterprise::is_server_initialized() && !enterprise::initialize_server(){
299
+
returnNone;
300
+
}
301
+
// If Enterprise thinks we are using a floating license, then report it will be in the keychain
302
+
if enterprise::is_server_floating_license(){
303
+
Some(LicenseLocation::Keychain)
304
+
}else{
305
+
None
306
+
}
307
+
}else{
308
+
None
278
309
}
279
310
}
280
311
}
281
312
}
282
313
}
283
314
284
315
/// 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{}
316
+
pubstructSession{
317
+
index:usize,
318
+
}
286
319
287
320
implSession{
288
321
/// Get a registered [`Session`] for use.
289
322
///
290
323
/// This is required so that we can keep track of the [`SESSION_COUNT`].
291
324
fnregistered_session() -> Self{
292
-
let _previous_count = SESSION_COUNT.fetch_add(1,SeqCst);
293
-
Self{}
325
+
let previous_count = SESSION_COUNT.fetch_add(1,SeqCst);
326
+
Self{
327
+
index: previous_count,
328
+
}
294
329
}
295
330
296
331
/// Before calling new you must make sure that the license is retrievable, otherwise the core won't be able to initialize.
@@ -300,10 +335,16 @@ impl Session {
300
335
pubfnnew() -> Result<Self,InitializationError>{
301
336
iflicense_location().is_some(){
302
337
// 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.
338
+
339
+
// Grab the lock before initialization to prevent another thread from initializing
340
+
// and racing the call to BNInitPlugins.
341
+
let _lock = INIT_LOCK.lock().map_err(|_| InitializationError::InitMutex)?;
305
342
let session = Self::registered_session();
306
-
init()?;
343
+
// Since this whole section is locked, we're guaranteed to be index 0 if we're first.
344
+
// Only the first thread hitting this should be allowed to call BNInitPlugins
345
+
if session.index == 0{
346
+
init()?;
347
+
}
307
348
Ok(session)
308
349
}else{
309
350
// There was no license that could be automatically retrieved, you must call [Self::new_with_license].
@@ -316,8 +357,16 @@ impl Session {
316
357
/// This differs from [`Session::new`] in that it does not check to see if there is a license that the core
317
358
/// can discover by itself, therefor it is expected that you know where your license is when calling this directly.
0 commit comments