Hello,
I am using the code below to p/invoke a function (from a shared library ".so") that accepts a function pointer as a parameter to register a call back, it works fine at the beginning but after a while (when GC starts) the callback is stops being called.
P/Invoke code ...
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr CallBack(IntPtr context, State state);
[DllImport(LIBRARY_NAME)]
public static extern void setCallBackFunction(IntPtr handle, [MarshalAs(UnmanagedType.FunctionPtr)] CallBack callBack);
extern function signature...
void setCallBackFunction(void* handle, void *(*callBack) (void* context, State state));
GC logs....
I/art: Explicit concurrent mark sweep GC freed 64(14KB) AllocSpace objects, 2(6MB) LOS objects, 39% free, 8MB/13MB, paused 640us total 20.265ms
D/Mono: GC_TAR_BRIDGE bridges 11 objects 11 opaque 0 colors 11 colors-bridged 11 colors-visible 11 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.12ms tarjan 0.03ms scc-setup 0.12ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.06ms
D/Mono: GC_BRIDGE: Complete, was running for 21.70ms
D/Mono: GC_MINOR: (Nursery full) time 5.46ms, stw 5.77ms promoted 109K major size: 864K in use: 178K los size: 4224K in use: 3334K
Did anyone has a similar issue? if so how did you resolve it?
Can you please confirm if the P/invoke section correct?
And if possible can any one briefly describe the best practice for passing callbacks to extern library.
Thanks in advance.