コード例 #1
0
        static UnmanagedThread()
        {
            NativeLibraryUtils.SetDllImportResolvers();

            if (Os.IsWindows)
            {
                SetThreadExitCallbackDelegate        = SetThreadExitCallbackWindows;
                RemoveThreadExitCallbackDelegate     = RemoveThreadExitCallbackWindows;
                EnableCurrentThreadExitEventDelegate = EnableCurrentThreadExitEventWindows;
            }
            else if (Os.IsMacOs)
            {
                SetThreadExitCallbackDelegate        = SetThreadExitCallbackMacOs;
                RemoveThreadExitCallbackDelegate     = RemoveThreadExitCallbackMacOs;
                EnableCurrentThreadExitEventDelegate = EnableCurrentThreadExitEventMacOs;
            }
            else if (Os.IsLinux)
            {
                if (Os.IsMono)
                {
                    SetThreadExitCallbackDelegate        = SetThreadExitCallbackMono;
                    RemoveThreadExitCallbackDelegate     = RemoveThreadExitCallbackMono;
                    EnableCurrentThreadExitEventDelegate = EnableCurrentThreadExitEventMono;
                }
                else
                {
                    unsafe
                    {
                        // Depending on the Linux distro, use either libcoreclr or libpthread.
                        try
                        {
                            int tlsIndex;

                            CheckResult(NativeMethodsLinuxLibcoreclr.pthread_key_create(new IntPtr(&tlsIndex), IntPtr.Zero));
                            CheckResult(NativeMethodsLinuxLibcoreclr.pthread_key_delete(tlsIndex));

                            SetThreadExitCallbackDelegate        = SetThreadExitCallbackLibcoreclr;
                            RemoveThreadExitCallbackDelegate     = RemoveThreadExitCallbackLibcoreclr;
                            EnableCurrentThreadExitEventDelegate = EnableCurrentThreadExitEventLibcoreclr;
                        }
                        catch (EntryPointNotFoundException)
                        {
                            SetThreadExitCallbackDelegate        = SetThreadExitCallbackLibpthread;
                            RemoveThreadExitCallbackDelegate     = RemoveThreadExitCallbackLibpthread;
                            EnableCurrentThreadExitEventDelegate = EnableCurrentThreadExitEventLibpthread;
                        }
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Unsupported OS: " + Environment.OSVersion);
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes the <see cref="UnmanagedThread"/> class.
 /// </summary>
 static UnmanagedThread()
 {
     NativeLibraryUtils.SetDllImportResolvers();
 }