Exemplo n.º 1
0
        /// <summary>
        /// Enables thread exit event for current thread.
        /// </summary>
        public static void EnableCurrentThreadExitEvent(int callbackId, IntPtr threadLocalValue)
        {
            Debug.Assert(threadLocalValue != IntPtr.Zero);

            // Store any value so that destructor callback is fired.
            if (Os.IsWindows)
            {
                var res = NativeMethodsWindows.FlsSetValue(callbackId, threadLocalValue);

                if (!res)
                {
                    throw new InvalidOperationException("FlsSetValue failed: " + Marshal.GetLastWin32Error());
                }
            }
            else if (Os.IsMacOs)
            {
                var res = NativeMethodsMacOs.pthread_setspecific(callbackId, threadLocalValue);
                NativeMethodsLinux.CheckResult(res);
            }
            else if (Os.IsLinux)
            {
                var res = Os.IsMono
                    ? NativeMethodsMono.pthread_setspecific(callbackId, threadLocalValue)
                    : NativeMethodsLinux.pthread_setspecific(callbackId, threadLocalValue);

                NativeMethodsLinux.CheckResult(res);
            }
            else
            {
                throw new InvalidOperationException("Unsupported OS: " + Environment.OSVersion);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Enables thread exit event for current thread.
 /// </summary>
 private static void EnableCurrentThreadExitEventMono(int callbackId, IntPtr threadLocalValue)
 {
     CheckResult(NativeMethodsMono.pthread_setspecific(callbackId, threadLocalValue));
 }