Skip to content
This repository
Browse code

Add better error checking to the Windows ThreadLocal implementation.

  • Loading branch information...
commit d1f6ee76970acb158d46b42d09ed7b6a9b0b84bf 1 parent c49b8ea
authored December 31, 2012

Showing 1 changed file with 16 additions and 3 deletions. Show diff stats Hide diff stats

  1. 19  xbmc/threads/platform/win/ThreadLocal.h
19  xbmc/threads/platform/win/ThreadLocal.h
@@ -21,6 +21,7 @@
21 21
 #pragma once
22 22
 
23 23
 #include <windows.h>
  24
+#include "commons/Exception.h"
24 25
 
25 26
 namespace XbmcThreads
26 27
 {
@@ -32,11 +33,23 @@ namespace XbmcThreads
32 33
   {
33 34
     DWORD key;
34 35
   public:
35  
-    inline ThreadLocal() { key = TlsAlloc(); }
  36
+    inline ThreadLocal()
  37
+    {
  38
+       if ((key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
  39
+          throw XbmcCommons::UncheckedException("Ran out of Windows TLS Indexes. Windows Error Code %d",(int)GetLastError());
  40
+    }
36 41
 
37  
-    inline ~ThreadLocal() { TlsFree(key);  }
  42
+    inline ~ThreadLocal() 
  43
+    {
  44
+       if (!TlsFree(key))
  45
+          throw XbmcCommons::UncheckedException("Failed to free Tls %d, Windows Error Code %d",(int)key, (int)GetLastError());
  46
+    }
38 47
 
39  
-    inline void set(T* val) {  TlsSetValue(key,(LPVOID)val);  }
  48
+    inline void set(T* val)
  49
+    {
  50
+       if (!TlsSetValue(key,(LPVOID)val))
  51
+          throw XbmcCommons::UncheckedException("Failed to set Tls %d, Windows Error Code %d",(int)key, (int)GetLastError());
  52
+    }
40 53
 
41 54
     inline T* get() { return (T*)TlsGetValue(key); }
42 55
   };

0 notes on commit d1f6ee7

Please sign in to comment.
Something went wrong with that request. Please try again.