internal static void DecrementCallbackCount(int processId) { lock (syncLock) { var c = callbackCount[processId]; CfxDebug.Assert(c > 0); //Debug.Print("DecrementCallbackCount: callbackCount[{0}] = {1}", processId, c - 1); if (c == 1) { // The main callback returned callbackCount.Remove(processId); suspensionCount.Remove(processId); return; } callbackCount[processId] = c - 1; if (c == 2) { // All callbacks except the main callback returned, // release any threads waiting in SuspendCallbacks. Monitor.PulseAll(syncLock); } } }
private static void Load() { CfxDebug.Announce(); string libCfx, libCef; FindLibraries(out libCef, out libCfx); var loader = NativeFunctionLoader.Create(); var libcfxPath = System.IO.Path.Combine(libCfxDirPath, libCfx); var libcefPath = System.IO.Path.Combine(libCefDirPath, libCef); // as of 3.2883, this must be in the path due to libcef dependencies. var path = Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", libCefDirPath + ";" + path); libcefPtr = loader.LoadNativeLibrary(libcefPath); if (libcefPtr == IntPtr.Zero) { throw new CfxException("Unable to load libcef library " + libcefPath); } libcfxPtr = loader.LoadNativeLibrary(libcfxPath); if (libcfxPtr == IntPtr.Zero) { throw new CfxException("Unable to load libcfx library " + libcfxPath); } cfx_gc_handle_switch = SwitchGcHandle; int platform; IntPtr release; IntPtr string_get_pointer; IntPtr string_destroy; IntPtr get_function_pointer; cfx_api_initialize_delegate api_initialize = (cfx_api_initialize_delegate)LoadDelegate(loader, libcfxPtr, "cfx_api_initialize", typeof(cfx_api_initialize_delegate)); int retval = api_initialize( libcefPtr, Marshal.GetFunctionPointerForDelegate(cfx_gc_handle_switch), out platform, out CW_USEDEFAULT, out release, out string_get_pointer, out string_destroy, out get_function_pointer ); if (retval != 0) { switch (retval) { case 1: throw new CfxException("Unable to get native function cef_api_hash from libcef library"); case 2: Runtime.cfx_api_hash_delegate api_hash = (Runtime.cfx_api_hash_delegate)LoadDelegate(loader, libcefPtr, "cef_api_hash", typeof(Runtime.cfx_api_hash_delegate)); var apiHash = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(api_hash(0)); throw new CfxException("API hash mismatch: incompatible libcef.dll (" + apiHash + ")"); } } PlatformOS = (CfxPlatformOS)platform; cfx_release = (cfx_release_delegate)Marshal.GetDelegateForFunctionPointer(release, typeof(cfx_release_delegate)); cfx_string_get_ptr = (cfx_string_get_ptr_delegate)Marshal.GetDelegateForFunctionPointer(string_get_pointer, typeof(cfx_string_get_ptr_delegate)); cfx_string_destroy = (cfx_string_destroy_delegate)Marshal.GetDelegateForFunctionPointer(string_destroy, typeof(cfx_string_destroy_delegate)); cfx_get_function_pointer = (cfx_get_function_pointer_delegate)Marshal.GetDelegateForFunctionPointer(get_function_pointer, typeof(cfx_get_function_pointer_delegate)); cef_string_userfree_utf16_free = (cef_string_userfree_utf16_free_delegate)LoadDelegate(loader, libcefPtr, "cef_string_userfree_utf16_free", typeof(cef_string_userfree_utf16_free_delegate)); CfxApiLoader.LoadCfxRuntimeApi(); librariesLoaded = true; }