Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / ACE / tests / TSS_Static_Test.cpp
blobc86f1e4fee63e4dc65a9610b5438d9ccb2b8b418
2 //=============================================================================
3 /**
4 * @file TSS_Static_Test.cpp
6 * This program tests the interaction between TSS and thread keys
7 * created during static construction. VxWorks static construction
8 * is quite broken. This test is designed to test changes to work
9 * around a bug in the VxWorks loader that constructs static objects
10 * multiple times. It sounds hard to believe, but I've seen it!
12 * @author Chad Elliott <elliott_c@ociweb.com>
14 //=============================================================================
17 #include "test_config.h"
18 #include "ace/ACE.h"
19 #include "ace/Init_ACE.h"
20 #include "ace/Thread.h"
23 #if defined (ACE_HAS_TSS_EMULATION)
25 class Some_Object
27 public:
28 Some_Object ();
29 ~Some_Object ();
32 Some_Object::Some_Object ()
34 ACE::init ();
36 // Cause the ACE_Log_Msg to be constructed during static construction
37 ACE_DEBUG ((LM_DEBUG, ""));
39 // Assign something to TSS during static construction
40 ACE_thread_key_t key;
41 if (ACE_Thread::keycreate (&key, 0) == 0)
43 ACE_Thread::setspecific (key, this);
48 Some_Object::~Some_Object ()
50 ACE::fini ();
54 static Some_Object sobject;
56 int
57 run_main (int, ACE_TCHAR *[])
59 ACE_START_TEST (ACE_TEXT ("TSS_Static_Test"));
61 int status = 0;
62 ACE_thread_key_t key;
63 if (ACE_Thread::keycreate (&key, 0) == 0)
65 void* specific = 0;
66 if (ACE_Thread::getspecific (key, &specific) == 0)
68 if (specific == 0)
70 ACE_DEBUG ((LM_DEBUG, "Got back pointer: %x from key: %d. "
71 "Good!\n",
72 (size_t)specific, key));
74 else
76 ++status;
77 ACE_ERROR ((LM_ERROR, "Something (%x) was found in tss "
78 "slot %d.\n"
79 "Nothing should be stored in our "
80 "TSS slot!\n",
81 (size_t)specific, key));
84 else
86 ++status;
87 ACE_ERROR ((LM_ERROR, "Unable to get the thread specific "
88 "storage.\n"));
91 else
93 ++status;
94 ACE_ERROR ((LM_ERROR, "Unable to create the thread specific "
95 "storage key.\n"));
97 ACE_END_TEST;
98 return status;
100 #else
102 run_main (int, ACE_TCHAR *[])
104 ACE_START_TEST (ACE_TEXT ("TSS_Static_Test"));
105 ACE_DEBUG ((LM_INFO, ACE_TEXT ("This test requires TSS Emulation.\n")));
106 ACE_END_TEST;
107 return 0;
109 #endif /* ACE_HAS_TSS_EMULATION */