blob: f18966df0300a41297457343e8c4ccaf5f651fa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#define ACE_DOESNT_DEFINE_MAIN
#include "test_config.h"
#include "ace/Init_ACE.h"
#include "ace/Singleton.h"
int restart_test_logging (const ACE_TCHAR *program)
{
if (ACE_LOG_MSG->open (program, ACE_Log_Msg::OSTREAM |
ACE_Log_Msg::VERBOSE_LITE) != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("open log_msg failed")), -1);
if (ace_file_stream::instance()->set_output (program, 1) != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("set_output failed")), -1);
return 0;
}
void report_error (const ACE_TCHAR *lock)
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE_Singleton<int, %s> ")
ACE_TEXT ("failed to allocate\n"), lock));
}
using Singleton1 = ACE_Singleton<int, ACE_MT_SYNCH::MUTEX>;
using Singleton2 = ACE_Singleton<int, ACE_MT_SYNCH::RECURSIVE_MUTEX>;
int main ()
{
ACE::init ();
ACE_START_TEST (ACE_TEXT ("Singleton_Restart_Test"));
*Singleton1::instance () = 1;
*Singleton2::instance () = 2;
ACE::fini ();
ACE::init ();
if (restart_test_logging (program) != 0) // program defined in ACE_START_TEST
return -1;
int *i1 = Singleton1::instance ();
if (!i1)
report_error (ACE_TEXT ("ACE_SYNCH_MUTEX"));
int *i2 = Singleton2::instance ();
if (!i2)
report_error (ACE_TEXT ("ACE_SYNCH_RECURSIVE_MUTEX"));
ACE_END_TEST;
ACE::fini ();
return (i1 && i2) ? 0 : 1;
}
|