| 660 | } // namespace |
| 661 | |
| 662 | static ThreadPool* GetCurrentThreadPool() { |
| 663 | // Preserve the caller's last-error value while also detecting TLS failures. |
| 664 | DWORD original_error = GetLastError(); |
| 665 | // Ensure a successful TlsGetValue() leaves GetLastError() == 0. |
| 666 | SetLastError(0); |
| 667 | auto* pool = static_cast<ThreadPool*>(TlsGetValue(GetPoolTlsIndex())); |
| 668 | DWORD tls_error = GetLastError(); |
| 669 | if (tls_error != 0) { |
| 670 | // No need to restore original_error here: ARROW_LOG(FATAL) aborts the process. |
| 671 | ARROW_LOG(FATAL) << "TlsGetValue failed for thread pool TLS: " |
| 672 | << WinErrorMessage(tls_error); |
| 673 | } |
| 674 | // Restore the caller's last-error value. |
| 675 | SetLastError(original_error); |
| 676 | return pool; |
| 677 | } |
| 678 | |
| 679 | static void SetCurrentThreadPool(ThreadPool* pool) { |
| 680 | BOOL ok = TlsSetValue(GetPoolTlsIndex(), pool); |
no test coverage detected