Steven Chamberlain patch to fix jack_port_type.
[jack2.git] / tests / testSynchroClient.cpp
blobaf31aa498589f469226eb294fe83bb49d426103d
1 /*
2 Copyright (C) 2004-2006 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifdef WIN32
22 #else
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <sys/mman.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <semaphore.h>
32 #include <sys/time.h>
33 #include <time.h>
35 #endif
37 #ifdef __APPLE__
38 #include "JackMachSemaphore.h"
39 #include "JackMachThread.h"
40 #endif
42 #ifdef WIN32
43 #include "JackWinThread.h"
44 #include "JackWinEvent.h"
45 #endif
47 #ifdef linux
48 #include "JackPosixThread.h"
49 #include "JackPosixSemaphore.h"
50 #include "JackFifo.h"
51 #endif
53 #define ITER 1000
55 #define SERVER "serveur3"
56 #define CLIENT "client3"
58 using namespace Jack;
60 class Test2 : public JackRunnableInterface
63 private:
65 JackSynchro* fSynchro1;
66 JackSynchro* fSynchro2;
68 public:
70 Test2(JackSynchro* synchro1, JackSynchro* synchro2)
71 : fSynchro1(synchro1), fSynchro2(synchro2)
74 bool Execute()
76 int a = 1;
77 for (int i = 0; i < ITER; i++) {
78 fSynchro2->Wait();
79 for (int j = 0; j < 2000000; j++) {
80 a += j;
82 fSynchro1->Signal();
84 return true;
89 int main(int ac, char *av [])
91 Test2* obj;
92 JackSynchro* sem1 = NULL;
93 JackSynchro* sem2 = NULL;
94 JackThread* thread;
96 printf("Test of synchronization primitives : client side\n");
97 printf("type -s to test Posix semaphore\n");
98 printf("type -f to test Fifo\n");
99 printf("type -m to test Mach semaphore\n");
100 printf("type -e to test Windows event\n");
102 #ifdef __APPLE__
103 if (strcmp(av[1], "-m") == 0) {
104 printf("Mach semaphore\n");
105 sem1 = new JackMachSemaphore();
106 sem2 = new JackMachSemaphore();
108 #endif
110 #ifdef WIN32
111 if (strcmp(av[1], "-e") == 0) {
112 printf("Win event\n");
113 sem1 = new JackWinEvent();
114 sem2 = new JackWinEvent();
116 #endif
118 #ifdef linux
119 if (strcmp(av[1], "-s") == 0) {
120 printf("Posix semaphore\n");
121 sem1 = new JackPosixSemaphore();
122 sem2 = new JackPosixSemaphore();
125 if (strcmp(av[1], "-f") == 0) {
126 printf("Fifo\n");
127 sem1 = new JackFifo();
128 sem2 = new JackFifo();
130 #endif
132 sem1->ConnectOutput(SERVER);
133 sem2->ConnectInput(CLIENT);
135 obj = new Test2(sem1, sem2);
137 #ifdef __APPLE__
138 thread = new JackMachThread(obj, 10000 * 1000, 500 * 1000, 10000 * 1000);
139 #endif
141 #ifdef WIN32
142 thread = new JackWinThread(obj);
143 #endif
145 #ifdef linux
146 thread = new JackPosixThread(obj, false, 50, PTHREAD_CANCEL_DEFERRED);
147 #endif
149 thread->Start();
150 thread->AcquireRealTime();
151 #ifdef WIN32
152 Sleep(30 * 1000);
153 #else
154 sleep(30);
155 #endif
156 //thread->Stop();
157 thread->Kill();
158 sem1->Disconnect();
159 sem2->Disconnect();
160 delete obj;
161 delete thread;
162 delete sem1;
163 delete sem2;
164 return 0;