summaryrefslogtreecommitdiff
path: root/ace/Auto_IncDec_T.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-12-24 14:04:45 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-12-24 14:04:45 +0000
commitb22069a94bf3c4c1783193c91e81175196f3fd9a (patch)
treee58b34ae43a2f0936ecd78f7096e4a1ecc558b3f /ace/Auto_IncDec_T.cpp
parentf37f503c109d7c7e592a43ff6afc66fede512cfc (diff)
downloadATCD-b22069a94bf3c4c1783193c91e81175196f3fd9a.tar.gz
ChangeLogTag:Thu Dec 23 13:57:04 1999 David L. Levine <levine@cs.wustl.edu>
Diffstat (limited to 'ace/Auto_IncDec_T.cpp')
-rw-r--r--ace/Auto_IncDec_T.cpp163
1 files changed, 19 insertions, 144 deletions
diff --git a/ace/Auto_IncDec_T.cpp b/ace/Auto_IncDec_T.cpp
index 68497c4e1bd..d915b51e672 100644
--- a/ace/Auto_IncDec_T.cpp
+++ b/ace/Auto_IncDec_T.cpp
@@ -1,157 +1,32 @@
// $Id$
-//============================================================================
-//
-// = LIBRARY
-// tests
-//
-// = FILENAME
-// Auto_IncDec_Test.cpp
-//
-// = DESCRIPTION
-// This is a simple test of the Auto Increment/Decrement Class in
-// ACE.
-//
-// = AUTHOR
-// Edan Ayal <EdanA@cti2.com>
-//
-//============================================================================
+#ifndef ACE_AUTO_INCDEC_T_C
+#define ACE_AUTO_INCDEC_T_C
-#include "ace/Auto_IncDec_T.h"
-#include "ace/Thread_Manager.h"
-#include "tests/test_config.h"
+#define ACE_BUILD_DLL
-ACE_RCSID(tests, Auto_IncDec_Test, "Auto_IncDec_Test.cpp, by Edan Ayal")
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
-#if defined(__BORLANDC__) && __BORLANDC__ >= 0x0530
-USELIB("..\ace\aced.lib");
-//---------------------------------------------------------------------------
-#endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */
+#include "ace/Auto_IncDec_T.h"
+#include "ace/Log_Msg.h"
-#if defined (ACE_HAS_THREADS)
+ACE_RCSID(ace, Auto_IncDec_T, "Auto_IncDec_T.cpp, by Edan Ayal")
-// Default number of threads.
-static size_t n_threads = 15;
+#if !defined (__ACE_INLINE__)
+#include "ace/Auto_IncDec_T.i"
+#endif /* __ACE_INLINE__ */
-typedef ACE_Atomic_Op<ACE_Thread_Mutex, int> INTERLOCKED_INT;
-static INTERLOCKED_INT current_threads_in_first_section;
-static INTERLOCKED_INT current_threads_in_second_section;
+ACE_ALLOC_HOOK_DEFINE(ACE_Auto_IncDec)
-static void *
-worker (void *)
+template <class ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> void
+ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::dump (void) const
{
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT (" (%t) worker starting\n")));
-
- { // First section.
- ACE_Auto_IncDec<INTERLOCKED_INT> threads_in_section_auto_inc_dec
- (current_threads_in_first_section);
-
- // Wait according to the number of threads...
- ACE_Time_Value pause (current_threads_in_first_section.value (),
- 0);
- ACE_OS::sleep (pause);
- }
+// ACE_TRACE ("ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::dump");
- { // Second section.
- ACE_Auto_IncDec<INTERLOCKED_INT> threads_in_section_auto_inc_dec
- (current_threads_in_second_section);
-
- // Wait according to the number of threads inside the previous
- // section...
- ACE_Time_Value pause (current_threads_in_first_section.value (),
- 0);
- ACE_OS::sleep (pause);
- }
-
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT (" (%t) worker exiting\n")));
- return 0;
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-template class ACE_Atomic_Op<ACE_Thread_Mutex, int>;
-template class ACE_Auto_IncDec<ACE_Atomic_Op<ACE_Thread_Mutex, int> >;
-#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-#pragma instantiate ACE_Atomic_Op<ACE_Thread_Mutex, int>
-#pragma instantiate ACE_Auto_IncDec<ACE_Atomic_Op<ACE_Thread_Mutex, int> >
-#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
-
-#else
-#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-template class ACE_Auto_IncDec<int>;
-#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-#pragma instantiate ACE_Auto_IncDec<int>
-#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
-#endif /* ACE_HAS_THREADS */
-
-// Spawn off threads.
-
-int
-main (int, ASYS_TCHAR *[])
-{
- ACE_START_TEST (ASYS_TEXT ("Auto_IncDec_Test"));
-
-#if defined (ACE_HAS_THREADS)
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT (" (%t) main thread starting\n")));
-
- current_threads_in_first_section = 0;
- current_threads_in_second_section = 0;
-
- if (ACE_Thread_Manager::instance ()->spawn_n
- (n_threads,
- ACE_THR_FUNC (worker),
- 0,
- THR_NEW_LWP) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- ASYS_TEXT ("%p\n"),
- ASYS_TEXT ("spawn_n")),
- -1);
- // Make sure at least one thread is started...
- ACE_Thread::yield ();
-
- while (ACE_Thread_Manager::instance ()->count_threads ())
- {
- // wait according to the number of threads...
- ACE_DEBUG ((LM_DEBUG,
- " %d in first section, %d in second section\n",
- current_threads_in_first_section.value (),
- current_threads_in_second_section.value ()));
-
- ACE_Time_Value pause (1, 0);
- ACE_OS::sleep (pause);
- }
-
- ACE_Thread_Manager::instance ()->wait ();
-
- ACE_ASSERT (current_threads_in_first_section.value () == 0
- && current_threads_in_second_section.value () == 0);
-
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT (" (%t) exiting main thread\n")));
-#else
- int counter = 0;
- {
- ACE_Auto_IncDec<int> Auto_IncDec1 (counter);
- ACE_ASSERT (counter == 1);
-
- ACE_Auto_IncDec<int> Auto_IncDec2 (counter);
- ACE_ASSERT (counter == 2);
-
- {
- ACE_ASSERT (counter == 2);
- ACE_Auto_IncDec<int> Auto_IncDec3 (counter);
- ACE_ASSERT (counter == 3);
- }
-
- ACE_ASSERT (counter == 2);
- }
-
- ACE_ASSERT (counter == 0);
-
-#endif /* ACE_HAS_THREADS */
-
- ACE_END_TEST;
- return 0;
-}
+#endif /* ACE_AUTO_INCDEC_T_C */