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