Skip to content

Commit 185d0b3

Browse files
committed
Apply field naming conventions: _prefix for instance, s_prefix for static
1 parent 6f8125e commit 185d0b3

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/Mono.Android/Microsoft.Android.Runtime/ManagedValueManager.cs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class ManagedValueManager : JniRuntime.JniValueManager
2424
const DynamicallyAccessedMemberTypes Constructors = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors;
2525

2626
readonly Lock _registeredInstancesLock = new ();
27-
readonly Dictionary<int, List<ReferenceTrackingHandle>> RegisteredInstances = new ();
28-
readonly ConcurrentQueue<IntPtr> CollectedContexts = new ();
27+
readonly Dictionary<int, List<ReferenceTrackingHandle>> _registeredInstances = new ();
28+
readonly ConcurrentQueue<IntPtr> _collectedContexts = new ();
2929

30-
bool disposed;
30+
bool _disposed;
3131

3232
static Lazy<ManagedValueManager> s_instance = new (() => new ManagedValueManager ());
3333
public static ManagedValueManager GetOrCreateInstance () => s_instance.Value;
@@ -41,13 +41,13 @@ unsafe ManagedValueManager ()
4141

4242
protected override void Dispose (bool disposing)
4343
{
44-
disposed = true;
44+
_disposed = true;
4545
base.Dispose (disposing);
4646
}
4747

4848
void ThrowIfDisposed ()
4949
{
50-
if (disposed)
50+
if (_disposed)
5151
throw new ObjectDisposedException (nameof (ManagedValueManager));
5252
}
5353

@@ -59,8 +59,8 @@ public unsafe override void CollectPeers ()
5959
{
6060
ThrowIfDisposed ();
6161

62-
while (CollectedContexts.TryDequeue (out IntPtr contextPtr)) {
63-
Debug.Assert (contextPtr != IntPtr.Zero, "CollectedContexts should not contain null pointers.");
62+
while (_collectedContexts.TryDequeue (out IntPtr contextPtr)) {
63+
Debug.Assert (contextPtr != IntPtr.Zero, "_collectedContexts should not contain null pointers.");
6464
HandleContext* context = (HandleContext*)contextPtr;
6565

6666
lock (_registeredInstancesLock) {
@@ -73,7 +73,7 @@ public unsafe override void CollectPeers ()
7373
void Remove (HandleContext* context)
7474
{
7575
int key = context->PeerIdentityHashCode;
76-
if (!RegisteredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
76+
if (!_registeredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
7777
return;
7878

7979
for (int i = peers.Count - 1; i >= 0; i--) {
@@ -84,7 +84,7 @@ void Remove (HandleContext* context)
8484
}
8585

8686
if (peers.Count == 0) {
87-
RegisteredInstances.Remove (key);
87+
_registeredInstances.Remove (key);
8888
}
8989
}
9090
}
@@ -104,9 +104,9 @@ public override void AddPeer (IJavaPeerable value)
104104
int key = value.JniIdentityHashCode;
105105
lock (_registeredInstancesLock) {
106106
List<ReferenceTrackingHandle>? peers;
107-
if (!RegisteredInstances.TryGetValue (key, out peers)) {
107+
if (!_registeredInstances.TryGetValue (key, out peers)) {
108108
peers = [new ReferenceTrackingHandle (value)];
109-
RegisteredInstances.Add (key, peers);
109+
_registeredInstances.Add (key, peers);
110110
return;
111111
}
112112

@@ -156,7 +156,7 @@ void WarnNotReplacing (int key, IJavaPeerable ignoreValue, IJavaPeerable keepVal
156156
int key = GetJniIdentityHashCode (reference);
157157

158158
lock (_registeredInstancesLock) {
159-
if (!RegisteredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
159+
if (!_registeredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
160160
return null;
161161

162162
for (int i = peers.Count - 1; i >= 0; i--) {
@@ -168,7 +168,7 @@ void WarnNotReplacing (int key, IJavaPeerable ignoreValue, IJavaPeerable keepVal
168168
}
169169

170170
if (peers.Count == 0)
171-
RegisteredInstances.Remove (key);
171+
_registeredInstances.Remove (key);
172172
}
173173
return null;
174174
}
@@ -177,15 +177,15 @@ public override void RemovePeer (IJavaPeerable value)
177177
{
178178
ThrowIfDisposed ();
179179

180-
// Remove any collected contexts before modifying RegisteredInstances
180+
// Remove any collected contexts before modifying _registeredInstances
181181
CollectPeers ();
182182

183183
if (value == null)
184184
throw new ArgumentNullException (nameof (value));
185185

186186
lock (_registeredInstancesLock) {
187187
int key = value.JniIdentityHashCode;
188-
if (!RegisteredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
188+
if (!_registeredInstances.TryGetValue (key, out List<ReferenceTrackingHandle>? peers))
189189
return;
190190

191191
for (int i = peers.Count - 1; i >= 0; i--) {
@@ -198,7 +198,7 @@ public override void RemovePeer (IJavaPeerable value)
198198
GC.KeepAlive (target);
199199
}
200200
if (peers.Count == 0)
201-
RegisteredInstances.Remove (key);
201+
_registeredInstances.Remove (key);
202202
}
203203
}
204204

@@ -280,8 +280,8 @@ public override List<JniSurfacedPeerInfo> GetSurfacedPeers ()
280280
CollectPeers ();
281281

282282
lock (_registeredInstancesLock) {
283-
var peers = new List<JniSurfacedPeerInfo> (RegisteredInstances.Count);
284-
foreach (var (identityHashCode, referenceTrackingHandles) in RegisteredInstances) {
283+
var peers = new List<JniSurfacedPeerInfo> (_registeredInstances.Count);
284+
foreach (var (identityHashCode, referenceTrackingHandles) in _registeredInstances) {
285285
foreach (var peer in referenceTrackingHandles) {
286286
if (peer.Target is IJavaPeerable target) {
287287
peers.Add (new JniSurfacedPeerInfo (identityHashCode, new WeakReference<IJavaPeerable> (target)));
@@ -333,19 +333,19 @@ unsafe struct HandleContext
333333
{
334334
static readonly nuint Size = (nuint)Marshal.SizeOf<HandleContext> ();
335335

336-
int identityHashCode;
337-
IntPtr controlBlock;
338-
IntPtr gcHandle; // GCHandle stored as IntPtr to keep blittable layout
336+
int _identityHashCode;
337+
IntPtr _controlBlock;
338+
IntPtr _gcHandle; // GCHandle stored as IntPtr to keep blittable layout
339339

340-
public int PeerIdentityHashCode => identityHashCode;
340+
public int PeerIdentityHashCode => _identityHashCode;
341341
public bool IsCollected
342342
{
343343
get
344344
{
345-
if (controlBlock == IntPtr.Zero)
345+
if (_controlBlock == IntPtr.Zero)
346346
throw new InvalidOperationException ("HandleContext control block is not initialized.");
347347

348-
return ((JniObjectReferenceControlBlock*) controlBlock)->handle == IntPtr.Zero;
348+
return ((JniObjectReferenceControlBlock*) _controlBlock)->handle == IntPtr.Zero;
349349
}
350350
}
351351

@@ -358,18 +358,18 @@ private struct JniObjectReferenceControlBlock
358358
public int refs_added;
359359
}
360360

361-
public GCHandle AssociatedGCHandle => GCHandle.FromIntPtr (gcHandle);
361+
public GCHandle AssociatedGCHandle => GCHandle.FromIntPtr (_gcHandle);
362362

363363
#if DEBUG
364-
static readonly HashSet<IntPtr> knownContexts = new ();
364+
static readonly HashSet<IntPtr> s_knownContexts = new ();
365365

366366
public static unsafe void EnsureAllContextsAreOurs (MarkCrossReferencesArgs* mcr)
367367
{
368-
lock (knownContexts) {
368+
lock (s_knownContexts) {
369369
for (nuint i = 0; i < mcr->ComponentCount; i++) {
370370
StronglyConnectedComponent component = mcr->Components [i];
371371
for (nuint j = 0; j < component.Count; j++) {
372-
if (!knownContexts.Contains ((IntPtr)component.Contexts [j])) {
372+
if (!s_knownContexts.Contains ((IntPtr)component.Contexts [j])) {
373373
throw new InvalidOperationException ("Unknown reference tracking handle.");
374374
}
375375
}
@@ -385,15 +385,15 @@ public static unsafe void EnsureAllContextsAreOurs (MarkCrossReferencesArgs* mcr
385385
throw new OutOfMemoryException ("Failed to allocate memory for HandleContext.");
386386
}
387387

388-
context->identityHashCode = peer.JniIdentityHashCode;
389-
context->controlBlock = peer.JniObjectReferenceControlBlock;
388+
context->_identityHashCode = peer.JniIdentityHashCode;
389+
context->_controlBlock = peer.JniObjectReferenceControlBlock;
390390

391391
GCHandle handle = JavaMarshal.CreateReferenceTrackingHandle (peer, context);
392-
context->gcHandle = GCHandle.ToIntPtr (handle);
392+
context->_gcHandle = GCHandle.ToIntPtr (handle);
393393

394394
#if DEBUG
395-
lock (knownContexts) {
396-
knownContexts.Add ((IntPtr)context);
395+
lock (s_knownContexts) {
396+
s_knownContexts.Add ((IntPtr)context);
397397
}
398398
#endif
399399

@@ -407,8 +407,8 @@ public static void Free (ref HandleContext* context)
407407
}
408408

409409
#if DEBUG
410-
lock (knownContexts) {
411-
knownContexts.Remove ((IntPtr)context);
410+
lock (s_knownContexts) {
411+
s_knownContexts.Remove ((IntPtr)context);
412412
}
413413
#endif
414414

@@ -439,8 +439,8 @@ static unsafe void BridgeProcessingFinished (MarkCrossReferencesArgs* mcr)
439439
ReadOnlySpan<GCHandle> handlesToFree = ProcessCollectedContexts (mcr);
440440
JavaMarshal.FinishCrossReferenceProcessing (mcr, handlesToFree);
441441

442-
// Schedule cleanup of RegisteredInstances on a thread pool thread.
443-
// The bridge thread must not take lock(RegisteredInstances) — see deadlock notes.
442+
// Schedule cleanup of _registeredInstances on a thread pool thread.
443+
// The bridge thread must not take lock(_registeredInstances) — see deadlock notes.
444444
Task.Run (GetOrCreateInstance ().CollectPeers);
445445
}
446446

@@ -469,10 +469,10 @@ void ProcessContext (HandleContext* context)
469469

470470
GCHandle handle = context->AssociatedGCHandle;
471471

472-
// Note: modifying the RegisteredInstances dictionary while processing the collected contexts
472+
// Note: modifying the _registeredInstances dictionary while processing the collected contexts
473473
// is tricky and can lead to deadlocks, so we remember which contexts were collected and we will free
474474
// them later outside of the bridge processing loop.
475-
instance.CollectedContexts.Enqueue ((IntPtr)context);
475+
instance._collectedContexts.Enqueue ((IntPtr)context);
476476

477477
// important: we must not free the handle before passing it to JavaMarshal.FinishCrossReferenceProcessing
478478
handlesToFree.Add (handle);

0 commit comments

Comments
 (0)