1 #define ACE_BUILD_SVC_DLL
2 #include "ace/OS_NS_stdio.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/Thread_Manager.h"
5 #include "Performance_Test_Options.h"
6 #include "Benchmark_Performance.h"
8 #if defined (ACE_HAS_THREADS)
10 class ACE_Svc_Export Pipe_Thr_Test
: public Benchmark_Performance
13 virtual int init (int, ACE_TCHAR
**);
17 ACE_HANDLE pipe_handles
[2];
19 static void *reader (Pipe_Thr_Test
*);
23 Pipe_Thr_Test::reader (Pipe_Thr_Test
*t
)
25 ACE_HANDLE handle
= t
->pipe_handles
[0];
26 int ni
= t
->thr_id ();
27 size_t length
= performance_test_options
.msg_size ();
29 ACE_NEW_RETURN (to
, char[length
], 0);
31 while (ACE_OS::read (handle
, to
, length
) > 0)
32 performance_test_options
.thr_work_count
[ni
]++;
38 Pipe_Thr_Test::init (int, ACE_TCHAR
**)
42 if (ACE_OS::pipe (this->pipe_handles
) == -1)
43 ACE_OS::perror (ACE_TEXT("pipe")), ACE_OS::exit (1);
45 if (ACE_Thread_Manager::instance ()->spawn
46 (ACE_THR_FUNC (Pipe_Thr_Test::reader
),
47 (void *) this, performance_test_options
.t_flags ()) == -1)
48 ACE_OS::perror (ACE_TEXT("thr_create")), ACE_OS::exit (1);
56 ssize_t length
= performance_test_options
.msg_size ();
57 ACE_HANDLE handle
= this->pipe_handles
[1];
59 ACE_NEW_RETURN (from
, char[length
], -1);
61 while (!this->done ())
62 if (ACE_OS::write (handle
, from
, length
) != length
)
63 ACE_OS::perror (ACE_TEXT("write"));
65 ACE_OS::close (this->pipe_handles
[0]);
66 ACE_OS::close (this->pipe_handles
[1]);
71 ACE_SVC_FACTORY_DECLARE (Pipe_Thr_Test
)
72 ACE_SVC_FACTORY_DEFINE (Pipe_Thr_Test
)
74 // ACE_Service_Object_Type ptt (&pipe_thr_test, "Pipe_Thr_Test");
75 #endif /* ACE_HAS_THREADS */