summaryrefslogtreecommitdiff
path: root/examples/ASX/Message_Queue
diff options
context:
space:
mode:
Diffstat (limited to 'examples/ASX/Message_Queue')
-rw-r--r--examples/ASX/Message_Queue/Makefile43
-rw-r--r--examples/ASX/Message_Queue/bounded_buffer.cpp130
-rw-r--r--examples/ASX/Message_Queue/buffer_stream.cpp209
-rw-r--r--examples/ASX/Message_Queue/priority_buffer.cpp139
4 files changed, 0 insertions, 521 deletions
diff --git a/examples/ASX/Message_Queue/Makefile b/examples/ASX/Message_Queue/Makefile
deleted file mode 100644
index f76ef41a74a..00000000000
--- a/examples/ASX/Message_Queue/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-#----------------------------------------------------------------------------
-# @(#)Makefile 1.1 10/18/96
-#
-# Makefile for Message_Queue tests
-#----------------------------------------------------------------------------
-
-#----------------------------------------------------------------------------
-# Local macros
-#----------------------------------------------------------------------------
-
-BIN = buffer_stream \
- bounded_buffer \
- priority_buffer
-
-VLDLIBS = $(LDLIBS:%=%$(VAR))
-
-BUILD = $(VBIN)
-
-#----------------------------------------------------------------------------
-# Include macros and targets
-#----------------------------------------------------------------------------
-
-include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU
-
-#----------------------------------------------------------------------------
-# Local targets
-#----------------------------------------------------------------------------
-
-#----------------------------------------------------------------------------
-# Dependencies
-#----------------------------------------------------------------------------
-
-# DO NOT DELETE THIS LINE -- g++dep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
-
-
-
-# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/examples/ASX/Message_Queue/bounded_buffer.cpp b/examples/ASX/Message_Queue/bounded_buffer.cpp
deleted file mode 100644
index 194fbf07280..00000000000
--- a/examples/ASX/Message_Queue/bounded_buffer.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// This short program copies stdin to stdout via the use of an ASX
-// $Id$
-
-// Message_Queue. It illustrates an implementation of the classic
-// "bounded buffer" program.
-
-
-#include "ace/Message_Queue.h"
-#include "ace/Thread_Manager.h"
-
-#if defined (ACE_HAS_THREADS)
-
-// Global thread manager.
-static ACE_Thread_Manager thr_mgr;
-
-// The producer reads data from the stdin stream, creates a message,
-// and then queues the message in the message list, where it is
-// removed by the consumer thread. A 0-sized message is enqueued when
-// there is no more data to read. The consumer uses this as a flag to
-// know when to exit.
-
-static void *
-producer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue)
-{
- // Insert thread into thr_mgr.
- ACE_Thread_Control thread_control (&thr_mgr);
-
- // Keep reading stdin, until we reach EOF.
-
- for (int n; ; )
- {
- // Allocate a new message.
- ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ);
-
- n = ACE_OS::read (ACE_STDIN, mb->rd_ptr (), mb->size ());
-
- if (n <= 0)
- {
- // Send a shutdown message to the other thread and exit.
- mb->length (0);
- if (msg_queue->enqueue_tail (mb) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- break;
- }
-
- // Send the message to the other thread.
- else
- {
- mb->msg_priority (n);
- mb->wr_ptr (n);
- if (msg_queue->enqueue_tail (mb) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- }
- }
-
- // The destructor of ACE_Thread_Control removes the exiting thread
- // from the thr_mgr automatically.
- return 0;
-}
-
-// The consumer dequeues a message from the ACE_Message_Queue, writes
-// the message to the stderr stream, and deletes the message. The
-// producer sends a 0-sized message to inform the consumer to stop
-// reading and exit.
-
-static void *consumer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue)
-{
- // Insert thread into thr_mgr.
- ACE_Thread_Control thread_control (&thr_mgr);
- int result = 0;
-
- // Keep looping, reading a message out of the queue, until we timeout
- // or get a message with a length == 0, which signals us to quit.
-
- for (;;)
- {
- ACE_Message_Block *mb;
-
- ACE_Time_Value timeout (ACE_OS::time (0) + 4, 0); // Wait for upto 4 seconds
-
- result = msg_queue->dequeue_head (mb, &timeout);
-
- if (result == -1)
- break;
-
- int length = mb->length ();
-
- if (length > 0)
- ACE_OS::write (ACE_STDOUT, mb->rd_ptr (), length);
-
- mb->release ();
-
- if (length == 0)
- break;
- }
-
- if (result == -1 && errno == EWOULDBLOCK)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n%a", "timed out waiting for message", 1));
-
- // The destructor of ACE_Thread_Control removes the exiting thread
- // from the thr_mgr automatically.
- return 0;
-}
-
-// Spawn off two threads that copy stdin to stdout.
-
-int main (int, char *[])
-{
- // Message list.
- ACE_Message_Queue<ACE_MT_SYNCH> msg_queue;
-
- if (thr_mgr.spawn (ACE_THR_FUNC (producer), (void *) &msg_queue,
- THR_NEW_LWP | THR_DETACHED) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1);
- else if (thr_mgr.spawn (ACE_THR_FUNC (consumer), (void *) &msg_queue,
- THR_NEW_LWP | THR_DETACHED) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1);
-
- // Wait for producer and consumer threads to exit.
- thr_mgr.wait ();
- return 0;
-}
-#else
-int
-main (int, char *[])
-{
- ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
- return 0;
-}
-#endif /* ACE_HAS_THREADS */
diff --git a/examples/ASX/Message_Queue/buffer_stream.cpp b/examples/ASX/Message_Queue/buffer_stream.cpp
deleted file mode 100644
index 7d0fcef4160..00000000000
--- a/examples/ASX/Message_Queue/buffer_stream.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-// This short program copies stdin to stdout via the use of an ASX
-// $Id$
-
-// STREAM. It illustrates an implementation of the classic "bounded
-// buffer" program using an ASX STREAM containing two Modules. Each
-// ACE_Module contains two Tasks. Each ACE_Task contains a
-// ACE_Message_Queue and a pointer to a ACE_Thread_Manager. Note how
-// the use of these reusable components reduces the reliance on global
-// variables, as compared with the bounded_buffer.C example.
-
-
-#include "ace/Synch.h"
-#include "ace/Service_Config.h"
-#include "ace/Stream.h"
-#include "ace/Module.h"
-#include "ace/Task.h"
-
-#if defined (ACE_HAS_THREADS)
-
-typedef ACE_Stream<ACE_MT_SYNCH> MT_Stream;
-typedef ACE_Module<ACE_MT_SYNCH> MT_Module;
-typedef ACE_Task<ACE_MT_SYNCH> MT_Task;
-
-class Common_Task : public MT_Task
- // = TITLE
- // Methods that are common to the producer and consumer.
-{
-public:
- Common_Task (void) {}
- // ACE_Task hooks
- virtual int open (void * = 0);
- virtual int close (u_long = 0);
-};
-
-// Define the Producer interface.
-
-class Producer : public Common_Task
-{
-public:
- Producer (void) {}
-
- // Read data from stdin and pass to consumer.
- virtual int svc (void);
-};
-
-class Consumer : public Common_Task
- // = TITLE
- // Define the Consumer interface.
-{
-public:
- Consumer (void) {}
-
- // Enqueue the message on the ACE_Message_Queue for subsequent
- // handling in the svc() method.
- virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv = 0);
-
- // Receive message from producer and print to stdout.
- virtual int svc (void);
-
-private:
-
- ACE_Time_Value timeout_;
-};
-
-// Spawn off a new thread.
-
-int
-Common_Task::open (void *)
-{
- if (this->activate (THR_NEW_LWP | THR_DETACHED) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), -1);
- return 0;
-}
-
-int
-Common_Task::close (u_long exit_status)
-{
- ACE_DEBUG ((LM_DEBUG, "(%t) thread is exiting with status %d in module %s\n",
- exit_status, this->name ()));
-
- // Can do anything here that is required when a thread exits, e.g.,
- // storing thread-specific information in some other storage
- // location, etc.
- return 0;
-}
-
-// The Consumer reads data from the stdin stream, creates a message,
-// and then queues the message in the message list, where it is
-// removed by the consumer thread. A 0-sized message is enqueued when
-// there is no more data to read. The consumer uses this as a flag to
-// know when to exit.
-
-int
-Producer::svc (void)
-{
- // Keep reading stdin, until we reach EOF.
-
- for (int n; ; )
- {
- // Allocate a new message.
- ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ);
-
- n = ACE_OS::read (ACE_STDIN, mb->rd_ptr (), mb->size ());
-
- if (n <= 0)
- {
- // Send a shutdown message to the other thread and exit.
- mb->length (0);
-
- if (this->put_next (mb) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- break;
- }
-
- // Send the message to the other thread.
- else
- {
- mb->wr_ptr (n);
-
- if (this->put_next (mb) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- }
- }
-
- return 0;
-}
-
-// Simply enqueue the Message_Block into the end of the queue.
-
-int
-Consumer::put (ACE_Message_Block *mb, ACE_Time_Value *tv)
-{
- return this->putq (mb, tv);
-}
-
-// The consumer dequeues a message from the ACE_Message_Queue, writes
-// the message to the stderr stream, and deletes the message. The
-// Consumer sends a 0-sized message to inform the consumer to stop
-// reading and exit.
-
-int
-Consumer::svc (void)
-{
- int result = 0;
-
- // Keep looping, reading a message out of the queue, until we
- // timeout or get a message with a length == 0, which signals us to
- // quit.
-
- for (;;)
- {
- ACE_Message_Block *mb;
-
- this->timeout_.sec (ACE_OS::time (0) + 4); // Wait for upto 4 seconds
-
- result = this->getq (mb, &this->timeout_);
-
- if (result == -1)
- break;
-
- int length = mb->length ();
-
- if (length > 0)
- ACE_OS::write (ACE_STDOUT, mb->rd_ptr (), length);
-
- mb->release ();
-
- if (length == 0)
- break;
- }
-
- if (result == -1 && errno == EWOULDBLOCK)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n%a", "timed out waiting for message", 1));
- return 0;
-}
-
-// Main driver function.
-
-int
-main (int, char *argv[])
-{
- ACE_Service_Config daemon (argv[0]);
-
- // Control hierachically-related active objects
- MT_Stream stream;
- MT_Module *pm = new MT_Module ("Consumer", new Consumer);
- MT_Module *cm = new MT_Module ("Producer", new Producer);
-
- // Create Producer and Consumer Modules and push them onto the
- // STREAM. All processing is performed in the STREAM.
-
- if (stream.push (pm) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "push"), 1);
- else if (stream.push (cm) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "push"), 1);
-
- // Barrier synchronization: wait for the threads to exit, then exit
- // ourselves.
- ACE_Service_Config::thr_mgr ()->wait ();
- return 0;
-}
-#else
-int
-main (int, char *[])
-{
- ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
- return 0;
-}
-#endif /* ACE_HAS_THREADS */
diff --git a/examples/ASX/Message_Queue/priority_buffer.cpp b/examples/ASX/Message_Queue/priority_buffer.cpp
deleted file mode 100644
index 2d057fd69c2..00000000000
--- a/examples/ASX/Message_Queue/priority_buffer.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-// This short program prints the contents of stdin to stdout sorted by
-// $Id$
-
-// the length of each line via the use of an ASX Message_Queue. It
-// illustrates how priorities can be used for ACE Message_Queues.
-
-
-#include "ace/Message_Queue.h"
-#include "ace/Read_Buffer.h"
-#include "ace/Thread_Manager.h"
-#include "ace/Service_Config.h"
-
-#if defined (ACE_HAS_THREADS)
-
-// Global thread manager.
-static ACE_Thread_Manager thr_mgr;
-
-// Make the queue be capable of being *very* large.
-static const long max_queue = LONG_MAX;
-
-// The consumer dequeues a message from the ACE_Message_Queue, writes
-// the message to the stderr stream, and deletes the message. The
-// producer sends a 0-sized message to inform the consumer to stop
-// reading and exit.
-
-static void *
-consumer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue)
-{
- // Keep looping, reading a message out of the queue, until we
- // timeout or get a message with a length == 0, which signals us to
- // quit.
-
- for (;;)
- {
- ACE_Message_Block *mb;
-
- if (msg_queue->dequeue_head (mb) == -1)
- break;
-
- int length = mb->length ();
-
- if (length > 0)
- ACE_OS::puts (mb->rd_ptr ());
-
- // Free up the buffer memory and the Message_Block.
- ACE_Service_Config::alloc ()->free (mb->rd_ptr ());
- mb->release ();
-
- if (length == 0)
- break;
- }
-
- return 0;
-}
-
-// The producer reads data from the stdin stream, creates a message,
-// and then queues the message in the message list, where it is
-// removed by the consumer thread. A 0-sized message is enqueued when
-// there is no more data to read. The consumer uses this as a flag to
-// know when to exit.
-
-static void *
-producer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue)
-{
- // Insert thread into thr_mgr.
- ACE_Thread_Control thread_control (&thr_mgr);
-
- ACE_Read_Buffer rb (ACE_STDIN);
-
- // Keep reading stdin, until we reach EOF.
-
- for (;;)
- {
- // Allocate a new buffer.
- char *buffer = rb.read ('\n');
-
- if (buffer == 0)
- {
- // Send a 0-sized shutdown message to the other thread and
- // exit.
- if (msg_queue->enqueue_tail (new ACE_Message_Block ((size_t) 0)) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- break;
- }
-
- // Enqueue the message in priority order.
- else
- {
- // Allocate a new message, but have it "borrow" its memory
- // from the buffer.
- ACE_Message_Block *mb = new ACE_Message_Block (rb.size (),
- ACE_Message_Block::MB_DATA,
- 0,
- buffer);
- mb->msg_priority (rb.size ());
- mb->wr_ptr (rb.size ());
-
- ACE_DEBUG ((LM_DEBUG, "enqueueing message of size %d\n",
- mb->msg_priority ()));
- // Enqueue in priority order.
- if (msg_queue->enqueue_prio (mb) == -1)
- ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next"));
- }
- }
-
- // Now read all the items out in priority order (i.e., ordered by
- // the size of the lines!).
- consumer (msg_queue);
-
- // The destructor of ACE_Thread_Control removes the exiting thread
- // from the thr_mgr automatically.
- return 0;
-}
-
-// Spawn off one thread that copies stdin to stdout in order of the
-// size of each line.
-
-int
-main (int, char *[])
-{
- // Message queue.
- ACE_Message_Queue<ACE_MT_SYNCH> msg_queue (max_queue);
-
- if (thr_mgr.spawn (ACE_THR_FUNC (producer), (void *) &msg_queue,
- THR_NEW_LWP | THR_DETACHED) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1);
-
- // Wait for producer and consumer threads to exit.
- thr_mgr.wait ();
- return 0;
-}
-#else
-int
-main (int, char *[])
-{
- ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
- return 0;
-}
-#endif /* ACE_HAS_THREADS */