summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp')
-rw-r--r--src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp b/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp
new file mode 100644
index 0000000000..96a6011f96
--- /dev/null
+++ b/src/pal/tests/palsuite/threading/TLS/test2/TLS.cpp
@@ -0,0 +1,66 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*=============================================================================
+**
+** Source: tls.c
+**
+** Purpose: Test to ensure TlsAlloc and TlsFree are working when we try
+** to allocate the guaranted minimum number of indicies.
+**
+
+**
+**===========================================================================*/
+#include <palsuite.h>
+
+#define NUM_OF_INDEX 64
+/* Minimum guaranteed is at least 64 for all systems.*/
+
+/**
+ * main
+ *
+ * executable entry point
+ */
+INT __cdecl main( INT argc, CHAR **argv )
+{
+ DWORD dwIndexes[NUM_OF_INDEX];
+ int i,j;
+
+ /* PAL initialization */
+ if( (PAL_Initialize(argc, argv)) != 0 )
+ {
+ return FAIL;
+ }
+
+ /* Allocate a bunch of TLS indexes. */
+ for( i = 0; i < NUM_OF_INDEX; i++ )
+ {
+ if( (dwIndexes[i] = TlsAlloc()) == TLS_OUT_OF_INDEXES )
+ {/*ERROR */
+ DWORD dwError = GetLastError();
+ Fail("TlsAlloc() returned -1 with error %d"
+ "when trying to allocate %d index\n",
+ dwError,
+ i);
+ }
+ }
+
+ /* Free the TLS indexes.*/
+ for( j = 0; j < NUM_OF_INDEX; j++ )
+ {
+ if( TlsFree(dwIndexes[j]) == 0 )
+ {/* ERROR */
+ DWORD dwError = GetLastError();
+ Fail("TlsFree() returned 0 with error %d"
+ "when trying to free %d index\n",
+ dwError,
+ i);
+ }
+ }
+
+ PAL_Terminate();
+
+ return PASS;
+}
+