summaryrefslogtreecommitdiff
path: root/ACE/tests/Message_Queue_Test_Ex.h
blob: be8f9b2752348a9e0c5a5324ec105a90ea5ea481 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// -*- C++ -*-

//=============================================================================
/**
 * @file Message_Queue_Test_Ex.h
 *
 * Define class needed for generating templates.
 *
 * @author Michael Vitlo <mvitalo@sprynet.com>
 * @author Irfan Pyarali <irfan@cs.wustl.edu>
 * @author David L. Levine <levine@cs.wustl.edu>
 * @author Guy Peleg <guy.peleg@amdocs.com>
 */
//=============================================================================

#ifndef ACE_TESTS_MESSAGE_QUEUE_TEST_EX_H
#define ACE_TESTS_MESSAGE_QUEUE_TEST_EX_H

#include "ace/OS_NS_string.h"

// User-defined class used for queue data.
class User_Class
{
public:
  User_Class (const char inputMsg[])
  {
    ACE_NEW (this->message_, char[ACE_OS::strlen (inputMsg) + 1]);
    ACE_OS::strcpy (this->message_, inputMsg);
  }

  ~User_Class () { delete [] this->message_; }

  const char *message () const
  {
    return this->message_;
  }

  // This is for checking the ACE_Message_Queue_Ex_N
  User_Class *next () const
  {
    return this->next_;
  }

  void next (User_Class *uc)
  {
    this->next_ = uc;
  }

private:
  char *message_ {};
  User_Class *next_ {};
};

// The main tests for the ACE_Message_Queue_Ex_N
struct Receive_Messages;

class MQ_Ex_N_Tester
{
public:
  int single_thread_performance_test ();

#if defined (ACE_HAS_THREADS)
  int performance_test ();

  /// Sender runs with an autonomous thread
  static ACE_THR_FUNC_RETURN sender (void *);

  /// Receiver runs with an autonomous thread
  static ACE_THR_FUNC_RETURN receiver (void *);

  /// Multi threaded tests use this queue
  ACE_Message_Queue_Ex_N<User_Class, ACE_MT_SYNCH>   mt_queue_;
#endif /* ACE_HAS_THREADS */

  /// Single threaded tests use this queue
  ACE_Message_Queue_Ex_N<User_Class, ACE_NULL_SYNCH> st_queue_;

private:
  /// Helper methods
  int test_enqueue_head ();
  int test_enqueue_tail ();
};

#endif /* ACE_TESTS_MESSAGE_QUEUE_TEST_EX_H */