Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/ObjCRuntime/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,27 @@ unsafe internal static BlockLiteral CreateBlock (Action action)
}

// This class will free the specified block when it's collected by the GC.
internal class BlockCollector : TrampolineBlockBase {
internal class BlockCollector {
IntPtr block;
int count;
public BlockCollector (IntPtr block)
: base (block, owns: true)
{
this.block = block;
count = 1;
}

public void Add (IntPtr block)
{
if (block != this.block)
throw new InvalidOperationException (string.Format ("Can't release the block 0x{0} because this BlockCollector instance is already tracking 0x{1}.", block.ToString ("x"), this.block.ToString ("x")));
Interlocked.Increment (ref count);
}

~BlockCollector ()
{
for (var i = 0; i < count; i++)
Runtime.ReleaseBlockOnMainThread (block);
count = 0;
}
}
#endif
Expand Down
6 changes: 5 additions & 1 deletion src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,11 @@ static Delegate ReleaseBlockWhenDelegateIsCollected (IntPtr block, Delegate @del
if (block == IntPtr.Zero)
return @delegate;

block_lifetime_table.Add (@delegate, new BlockCollector (block));
if (block_lifetime_table.TryGetValue (@delegate, out var existingCollector)) {
existingCollector.Add (block);
} else {
block_lifetime_table.Add (@delegate, new BlockCollector (block));
}
return @delegate;
}

Expand Down
10 changes: 4 additions & 6 deletions src/servicemanagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@

namespace ServiceManagement {
[Native]
[NoWatch, NoTV, NoiOS, MacCatalyst (16,0), Mac (13,0)]
public enum SMAppServiceStatus : long
{
[NoWatch, NoTV, NoiOS, MacCatalyst (16, 0), Mac (13, 0)]
public enum SMAppServiceStatus : long {
NotRegistered,
Enabled,
RequiresApproval,
NotFound,
}

// @interface SMAppService : NSObject
[NoWatch, NoTV, NoiOS, MacCatalyst (16,0), Mac (13,0)]
[NoWatch, NoTV, NoiOS, MacCatalyst (16, 0), Mac (13, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface SMAppService
{
interface SMAppService {
[Static]
[Export ("loginItemServiceWithIdentifier:")]
SMAppService CreateLoginItemService (string identifier);
Expand Down