Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Bug_3539_Regression_Test.cpp
blobc4a5ba453cddb158cb4fa29cb5f6f0e94620389f
2 //=============================================================================
3 /**
4 * @file Bug_3539_Regression_Test.cpp
6 * This test is similar to TSS_Test but it's a bit simpler and it uses
7 * ACE_TSS in a main() thread. It uses TSS_Test_Errno.h.
9 * @author Vladimir Zykov <vz@prismtech.com>
11 //=============================================================================
14 #include "test_config.h"
15 #include "TSS_Test_Errno.h"
16 #include <memory>
17 #include "ace/TSS_T.h"
18 #include "ace/Thread_Manager.h"
19 #include "ace/Atomic_Op_T.h"
21 ACE_Atomic_Op<ACE_SYNCH_MUTEX, int> status;
23 #if defined (ACE_HAS_THREADS)
25 struct ObjectWithTSS
27 public:
28 ACE_TSS_TYPE (Errno) tss_;
31 // Static variables.
32 int Errno::flags_;
33 int Errno::created_;
34 int Errno::deleted_;
35 ACE_Thread_Mutex *Errno::lock_ = 0;
37 ACE_THR_FUNC_RETURN
38 check_tss (ObjectWithTSS *o)
40 if (0 == o)
42 ACE_ERROR ((LM_ERROR,
43 "Nil object."));
44 status = 1;
47 Errno *e = o->tss_.ts_object (0);
48 if (0 != e)
50 ACE_ERROR ((LM_ERROR,
51 "TSS should not have any value yet."));
52 status = 2;
55 e = ACE_TSS_GET (&o->tss_, Errno);
56 if (0 == e)
58 ACE_ERROR ((LM_ERROR,
59 "TSS should now have a value."));
60 status = 3;
63 return 0;
66 // This worker function is the entry point for each thread.
67 ACE_THR_FUNC_RETURN
68 worker (void *c)
70 return check_tss (reinterpret_cast<ObjectWithTSS *> (c));
73 #endif /* ACE_HAS_THREADS */
75 int
76 run_main (int, ACE_TCHAR *[])
78 ACE_START_TEST (ACE_TEXT ("Bug_3539_Regression_Test"));
80 #if defined (ACE_HAS_THREADS)
81 Errno::allocate_lock ();
83 const u_int threads = ACE_MAX_THREADS;
86 ObjectWithTSS *o = 0;
87 ACE_NEW_RETURN (o, ObjectWithTSS, 1);
88 std::unique_ptr<ObjectWithTSS> owner (o);
90 if (ACE_Thread_Manager::instance ()->spawn_n
91 (threads,
92 ACE_THR_FUNC (worker),
94 THR_BOUND) == -1)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 ACE_TEXT ("%p\n"), ACE_TEXT ("spawn_n")),
97 1);
99 check_tss (o);
101 ACE_Thread_Manager::instance ()->wait ();
104 Errno::deallocate_lock ();
106 if (Errno::created () != Errno::deleted ())
108 ACE_ERROR_RETURN ((LM_ERROR,
109 ACE_TEXT ("Number created (%d) ")
110 ACE_TEXT ("!= number deleted (%d)\n"),
111 Errno::created (), Errno::deleted ()),
115 #else /* ACE_HAS_THREADS */
116 ACE_ERROR ((LM_INFO,
117 ACE_TEXT ("threads are not supported on this platform\n")));
118 #endif /* ACE_HAS_THREADS */
120 ACE_END_TEST;
121 return status.value ();