@@ -29,18 +29,16 @@ extern "C"
29
29
30
30
void _addGlobalObject (jobject globalObject, jclass globalClass)
31
31
{
32
- globalReferenceMtx. lock ( );
32
+ std::lock_guard<std::mutex> lockGuard (globalReferenceMtx );
33
33
std::pair<jclass, int > objPair = std::make_pair (globalClass, 0 );
34
34
objectGlobalReference[globalObject] = objPair;
35
- globalReferenceMtx.unlock ();
36
35
}
37
36
38
37
jclass _getGlobalClass (jobject globalObject)
39
38
{
40
- globalReferenceMtx. lock ( );
39
+ std::lock_guard<std::mutex> lockGuard (globalReferenceMtx );
41
40
auto it = objectGlobalReference.find (globalObject);
42
41
auto cls = it != objectGlobalReference.end () ? it->second .first : nullptr ;
43
- globalReferenceMtx.unlock ();
44
42
return cls;
45
43
}
46
44
@@ -290,13 +288,12 @@ extern "C"
290
288
// / reference counter
291
289
void _updateObjectReference (jobject globalObject, bool isRetain)
292
290
{
293
- globalReferenceMtx. lock ( );
291
+ std::lock_guard<std::mutex> lockGuard (globalReferenceMtx );
294
292
DNDebug (" _updateObjectReference %s" , isRetain ? " retain" : " release" );
295
293
auto it = objectGlobalReference.find (globalObject);
296
294
if (it == objectGlobalReference.end ())
297
295
{
298
296
DNError (" _updateObjectReference %s error not contain this object!!!" , isRetain ? " retain" : " release" );
299
- globalReferenceMtx.unlock ();
300
297
return ;
301
298
}
302
299
@@ -305,7 +302,6 @@ extern "C"
305
302
// / dart object retain this dart object
306
303
// / reference++
307
304
it->second .second += 1 ;
308
- globalReferenceMtx.unlock ();
309
305
return ;
310
306
}
311
307
@@ -320,7 +316,6 @@ extern "C"
320
316
objectGlobalReference.erase (it);
321
317
env->DeleteGlobalRef (globalObject);
322
318
}
323
- globalReferenceMtx.unlock ();
324
319
}
325
320
326
321
// / release native object from cache
0 commit comments