Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add better error checking to the Windows ThreadLocal implementation.

  • Loading branch information...
commit d1f6ee76970acb158d46b42d09ed7b6a9b0b84bf 1 parent c49b8ea
Jim Carroll authored
Showing with 16 additions and 3 deletions.
  1. +16 −3 xbmc/threads/platform/win/ThreadLocal.h
View
19 xbmc/threads/platform/win/ThreadLocal.h
@@ -21,6 +21,7 @@
#pragma once
#include <windows.h>
+#include "commons/Exception.h"
namespace XbmcThreads
{
@@ -32,11 +33,23 @@ namespace XbmcThreads
{
DWORD key;
public:
- inline ThreadLocal() { key = TlsAlloc(); }
+ inline ThreadLocal()
+ {
+ if ((key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+ throw XbmcCommons::UncheckedException("Ran out of Windows TLS Indexes. Windows Error Code %d",(int)GetLastError());
+ }
- inline ~ThreadLocal() { TlsFree(key); }
+ inline ~ThreadLocal()
+ {
+ if (!TlsFree(key))
+ throw XbmcCommons::UncheckedException("Failed to free Tls %d, Windows Error Code %d",(int)key, (int)GetLastError());
+ }
- inline void set(T* val) { TlsSetValue(key,(LPVOID)val); }
+ inline void set(T* val)
+ {
+ if (!TlsSetValue(key,(LPVOID)val))
+ throw XbmcCommons::UncheckedException("Failed to set Tls %d, Windows Error Code %d",(int)key, (int)GetLastError());
+ }
inline T* get() { return (T*)TlsGetValue(key); }
};
Please sign in to comment.
Something went wrong with that request. Please try again.