diff options
Diffstat (limited to 'examples/System_V_IPC/SV_Semaphores')
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Makefile | 137 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp | 31 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp | 42 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h | 11 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphores.cpp | 94 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphores_1.cpp | 97 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp | 108 |
7 files changed, 0 insertions, 520 deletions
diff --git a/examples/System_V_IPC/SV_Semaphores/Makefile b/examples/System_V_IPC/SV_Semaphores/Makefile deleted file mode 100644 index 49a6af0ed65..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Makefile +++ /dev/null @@ -1,137 +0,0 @@ -#---------------------------------------------------------------------------- -# $Id: Makefile 1.1 10/18/96 -# -# Makefile for Semaphore wrapper class examples -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = Semaphores_1 \ - Semaphores_2 - -LSRC = $(addsuffix .cpp,$(BIN)) - -VLDLIBS = $(LDLIBS:%=%$(VAR)) - -BUILD = $(VBIN) - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(ACE_ROOT)/include/makeinclude/macros.GNU -include $(ACE_ROOT)/include/makeinclude/rules.common.GNU -include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU -include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU -include $(ACE_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. - -.obj/Semaphores_1.o .obj/Semaphores_1.so .shobj/Semaphores_1.o .shobj/Semaphores_1.so: Semaphores_1.cpp \ - $(ACE_ROOT)/ace/SV_Shared_Memory.h \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/inc_user_config.h \ - $(ACE_ROOT)/ace/config.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Record.h \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Log_Record.i \ - $(ACE_ROOT)/ace/SV_Shared_Memory.i \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ - $(ACE_ROOT)/ace/Malloc.h \ - $(ACE_ROOT)/ace/Malloc.i \ - $(ACE_ROOT)/ace/Malloc_T.h \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Atomic_Op.i \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Malloc_T.i \ - $(ACE_ROOT)/ace/Memory_Pool.h \ - $(ACE_ROOT)/ace/Signal.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Signal.i \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Mem_Map.h \ - $(ACE_ROOT)/ace/Mem_Map.i \ - $(ACE_ROOT)/ace/Memory_Pool.i -.obj/Semaphores_2.o .obj/Semaphores_2.so .shobj/Semaphores_2.o .shobj/Semaphores_2.so: Semaphores_2.cpp \ - $(ACE_ROOT)/ace/Malloc.h \ - $(ACE_ROOT)/ace/ACE.h \ - $(ACE_ROOT)/ace/OS.h \ - $(ACE_ROOT)/ace/inc_user_config.h \ - $(ACE_ROOT)/ace/config.h \ - $(ACE_ROOT)/ace/streams.h \ - $(ACE_ROOT)/ace/Basic_Types.h \ - $(ACE_ROOT)/ace/Basic_Types.i \ - $(ACE_ROOT)/ace/OS.i \ - $(ACE_ROOT)/ace/Trace.h \ - $(ACE_ROOT)/ace/Log_Msg.h \ - $(ACE_ROOT)/ace/Log_Record.h \ - $(ACE_ROOT)/ace/ACE.i \ - $(ACE_ROOT)/ace/Log_Priority.h \ - $(ACE_ROOT)/ace/Log_Record.i \ - $(ACE_ROOT)/ace/Malloc.i \ - $(ACE_ROOT)/ace/Malloc_T.h \ - $(ACE_ROOT)/ace/Synch.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.h \ - $(ACE_ROOT)/ace/SV_Semaphore_Simple.i \ - $(ACE_ROOT)/ace/SV_Semaphore_Complex.i \ - $(ACE_ROOT)/ace/Synch.i \ - $(ACE_ROOT)/ace/Synch_T.h \ - $(ACE_ROOT)/ace/Event_Handler.h \ - $(ACE_ROOT)/ace/Event_Handler.i \ - $(ACE_ROOT)/ace/Synch_T.i \ - $(ACE_ROOT)/ace/Thread.h \ - $(ACE_ROOT)/ace/Thread.i \ - $(ACE_ROOT)/ace/Atomic_Op.i \ - $(ACE_ROOT)/ace/Free_List.h \ - $(ACE_ROOT)/ace/Free_List.i \ - $(ACE_ROOT)/ace/Malloc_T.i \ - $(ACE_ROOT)/ace/Memory_Pool.h \ - $(ACE_ROOT)/ace/Signal.h \ - $(ACE_ROOT)/ace/Containers.h \ - $(ACE_ROOT)/ace/Containers.i \ - $(ACE_ROOT)/ace/Signal.i \ - $(ACE_ROOT)/ace/Object_Manager.h \ - $(ACE_ROOT)/ace/Object_Manager.i \ - $(ACE_ROOT)/ace/Managed_Object.h \ - $(ACE_ROOT)/ace/Managed_Object.i \ - $(ACE_ROOT)/ace/Mem_Map.h \ - $(ACE_ROOT)/ace/Mem_Map.i \ - $(ACE_ROOT)/ace/Memory_Pool.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp deleted file mode 100644 index b7fe34725e7..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "Semaphore_Test.h" -// $Id$ - -#include "ace/SV_Shared_Memory.h" -#include "ace/SV_Semaphore_Simple.h" - -int -main (void) -{ - ACE_SV_Shared_Memory shm_client (SHM_KEY, - SHMSZ, - ACE_SV_Shared_Memory::ACE_OPEN); - ACE_SV_Semaphore_Simple sem (SEM_KEY_1, - ACE_SV_Semaphore_Simple::ACE_OPEN, 0, 2); - - char *s = (char *) shm_client.get_segment_ptr (); - - if (sem.acquire (0) < 0) - ACE_OS::perror ("client sem.acquire"), ACE_OS::exit (1); - - while (*s != '\0') - putchar (*s++); - - putchar ('\n'); - - if (sem.release (1) < 0) - ACE_OS::perror ("client sem.release"), ACE_OS::exit (1); - - return 0; -} - diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp deleted file mode 100644 index f9931705c26..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// $Id$ - - -#include "ace/SV_Shared_Memory.h" -#include "ace/SV_Semaphore_Simple.h" -#include "ace/Signal.h" -#include "Semaphore_Test.h" - -static ACE_SV_Shared_Memory shm_server (SHM_KEY, SHMSZ, ACE_SV_Shared_Memory::ACE_CREATE); -static ACE_SV_Semaphore_Simple sem (SEM_KEY_1, ACE_SV_Semaphore_Simple::ACE_CREATE, 0, 2); - -extern "C" void -cleanup (int) -{ - if (shm_server.remove () < 0 || sem.remove () < 0) - ACE_ERROR ((LM_ERROR, "%p\n%a", "remove", 1)); - ACE_OS::exit (0); -} - -int -main (void) -{ - // Register a signal handler. - ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT); - - char *s = (char *) shm_server.get_segment_ptr (); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (sem.release (0) < 0) - ESD ("server sem.release", done); - - if (sem.acquire (1) < 0) - ESD ("server sem.acquire", done); - -done: - cleanup (); - return 0; -} diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h b/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h deleted file mode 100644 index 72aab815ff8..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -#include "ace/Log_Msg.h" - -#define SHMSZ 27 -#define SEM_KEY_1 2345 -#define SEM_KEY_2 4321 -#define SHM_KEY 5678 - -#define ESD(MSG,LABEL) do { ACE_ERROR ((LM_ERROR, MSG)); goto LABEL; } while (0) diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp deleted file mode 100644 index b98c664883b..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Illustrates the use of the Semaphore_Complex class. Note that it -// $Id$ - -// doesn't matter whether the parent or the child creates the -// semaphore since Semaphore_Complex will correctly serialize the -// intialization of the mutex and synch objects. -#include "ace/Malloc.h" -#include "ace/SV_Semaphore_Complex.h" -#include "Semaphore_Test.h" - -ACE_Malloc<ACE_Shared_Memory_Pool, ACE_SV_Semaphore_Simple> allocator; -ACE_SV_Semaphore_Complex *mutex = 0; -ACE_SV_Semaphore_Complex *synch = 0; - -/* Pointer to memory shared by both the client and server. */ -static char *shm; - -static int -do_parent (void) -{ - char *s = shm; - - mutex = new ACE_SV_Semaphore_Complex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - synch = new ACE_SV_Semaphore_Complex (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (mutex->release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p", "server mutex.release"), 1); - - if (synch->acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p", "server synch.acquire"), 1); - return 0; -} - -static int -do_child (void) -{ - mutex = new ACE_SV_Semaphore_Complex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - synch = new ACE_SV_Semaphore_Complex (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - while (mutex->tryacquire () == -1) - if (errno == EAGAIN) - ACE_DEBUG ((LM_DEBUG, "spinning in client!\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "client mutex.tryacquire"), 1); - - for (char *s = (char *) shm; *s != '\0'; s++) - putchar (*s); - - putchar ('\n'); - - if (synch->release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "client synch.release"), 1); - return 0; -} - -int -main (void) -{ - shm = (char *) allocator.malloc (27); - - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "fork failed\n"), -1); - /* NOTREACHED */ - case 0: - return do_child (); - default: - { - int result = do_parent (); - - if (wait (0) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "wait"), -1); - - allocator.remove (); - - if (mutex->remove () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "mutex.remove"), -1); - else if (synch->remove () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "synch.remove"), -1); - return result; - } - } -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Malloc<ACE_Shared_Memory_Pool, ACE_SV_Semaphore_Simple>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphores_1.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphores_1.cpp deleted file mode 100644 index 1e5e01c8266..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphores_1.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// $Id$ - -#include "ace/SV_Shared_Memory.h" -#include "ace/SV_Semaphore_Simple.h" -#include "ace/Malloc.h" - -#if defined (ACE_HAS_SYSV_IPC) - -// Shared memory allocator (note that this chews up the -// ACE_DEFAULT_SEM_KEY). -static ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple> alloc; - -const int SEM_KEY = ACE_DEFAULT_SEM_KEY + 1; - -static int -parent (char *shm) -{ - char *s = shm; - - ACE_SV_Semaphore_Complex sem (SEM_KEY, ACE_SV_Semaphore_Complex::ACE_CREATE, 0, 2); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (sem.release (0) == -1) - ACE_ERROR ((LM_ERROR, "%p", "parent sem.release(0)")); - else if (sem.acquire (1) == -1) - ACE_ERROR ((LM_ERROR, "%p", "parent sem.acquire(1)")); - - if (alloc.remove () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "alloc.remove")); - if (sem.remove () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "sem.remove")); - return 0; -} - -static int -child (char *shm) -{ - ACE_SV_Semaphore_Complex sem (SEM_KEY, ACE_SV_Semaphore_Complex::ACE_CREATE, 0, 2); - - while (sem.tryacquire (0) == -1) - if (errno == EAGAIN) - ACE_DEBUG ((LM_DEBUG, "spinning in client!\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "client mutex.tryacquire(0)"), 1); - - for (char *s = (char *) shm; *s != '\0'; s++) - ACE_DEBUG ((LM_DEBUG, "%c", *s)); - - ACE_DEBUG ((LM_DEBUG, "\n")); - - if (sem.release (1) < 0) - ACE_ERROR ((LM_ERROR, "client sem.release(1)")); - return 0; -} - -int -main (int, char *[]) -{ - char *shm = (char *) alloc.malloc (27); - - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "fork failed\n"), -1); - /* NOTREACHED */ - case 0: - // Child. - return child (shm); - default: - return parent (shm); - } -} -#else -int main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, - "SYSV IPC is not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_SYSV_IPC */ - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Guard<ACE_SV_Semaphore_Simple>; -template class ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple>; -template class ACE_Read_Guard<ACE_SV_Semaphore_Simple>; -template class ACE_Write_Guard<ACE_SV_Semaphore_Simple>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Guard<ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Read_Guard<ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Write_Guard<ACE_SV_Semaphore_Simple> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp deleted file mode 100644 index bd7b95231a9..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphores_2.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// $Id$ - -// Illustrates the use of the ACE_SV_Semaphore_Complex class and the -// ACE_Malloc class using the ACE_Shared_Memory_Pool (which uses -// System V shared memory). Note that it doesn't matter whether the -// parent or the child creates the semaphore since Semaphore_Complex -// will correctly serialize the intialization of the mutex and synch -// objects. - -#include "ace/Malloc.h" -#include "ace/SV_Semaphore_Complex.h" - -#if defined (ACE_HAS_SYSV_IPC) - -// Shared memory allocator (note that this chews up the -// ACE_DEFAULT_SEM_KEY). -static ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple> my_alloc; - -const int SEM_KEY_1 = ACE_DEFAULT_SEM_KEY + 1; -const int SEM_KEY_2 = ACE_DEFAULT_SEM_KEY + 2; - -static int -parent (char *shm) -{ - char *s = shm; - - ACE_SV_Semaphore_Complex mutex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - ACE_SV_Semaphore_Complex synch (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (mutex.release () == -1) - ACE_ERROR ((LM_ERROR, "%p", "parent mutex.release")); - else if (synch.acquire () == -1) - ACE_ERROR ((LM_ERROR, "%p", "parent synch.acquire")); - - if (my_alloc.remove () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "my_alloc.remove")); - if (mutex.remove () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "mutex.remove")); - if (synch.remove () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "synch.remove")); - return 0; -} - -static int -child (char *shm) -{ - ACE_SV_Semaphore_Complex mutex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - ACE_SV_Semaphore_Complex synch (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - while (mutex.tryacquire () == -1) - if (errno == EAGAIN) - ACE_DEBUG ((LM_DEBUG, "spinning in child!\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "child mutex.tryacquire"), 1); - - for (char *s = (char *) shm; *s != '\0'; s++) - ACE_DEBUG ((LM_DEBUG, "%c", *s)); - - ACE_DEBUG ((LM_DEBUG, "\n")); - - if (synch.release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "child synch.release"), 1); - return 0; -} - -int -main (int, char *[]) -{ - char *shm = (char *) my_alloc.malloc (27); - - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "fork failed\n"), -1); - /* NOTREACHED */ - case 0: - // Child. - return child (shm); - default: - return parent (shm); - } -} -#else -int main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, - "SYSV IPC is not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_SYSV_IPC */ - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Guard<ACE_SV_Semaphore_Simple>; -template class ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple>; -template class ACE_Read_Guard<ACE_SV_Semaphore_Simple>; -template class ACE_Write_Guard<ACE_SV_Semaphore_Simple>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Guard<ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Read_Guard<ACE_SV_Semaphore_Simple> -#pragma instantiate ACE_Write_Guard<ACE_SV_Semaphore_Simple> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - |