2 Copyright (C) 2004-2008 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.
26 #include "JackMachSemaphore.h"
29 #include "JackPosixSemaphore.h"
32 #include "JackPlatformPlug.h"
38 struct ServerThread
: public JackRunnableInterface
{
41 detail::JackSynchro
* fServerSem
;
42 detail::JackSynchro
* fClientSem
;
46 fServerSem
->Allocate("JackSemServer", "default", 0);
47 fClientSem
->Allocate("JackSemClient", "default", 0);
48 //fThread = new JackMachThread(this);
49 fThread
->SetParams(0, 500*1000, 500*1000);
51 //fThread->AcquireRealTime();
54 virtual ~ServerThread()
62 printf("Execute Server\n");
63 for (int i
= 0; i
< ITER
; i
++) {
72 struct ClientThread
: public JackRunnableInterface
{
75 detail::JackSynchro
* fServerSem
;
76 detail::JackSynchro
* fClientSem
;
80 fServerSem
->Connect("JackSemServer", "default");
81 fClientSem
->Connect("JackSemClient", "default");
82 //fThread = new JackMachThread(this);
83 fThread
->SetParams(0, 500*1000, 500*1000);
85 //fThread->AcquireRealTime();
88 virtual ~ClientThread()
96 struct timeval T0
, T1
;
97 printf("Execute Client\n");
101 for (int i
= 0; i
< ITER
; i
++) {
102 fServerSem
->Signal();
106 gettimeofday(&T1
, 0);
107 printf("%5.1lf usec\n", (1e6
* T1
.tv_sec
- 1e6
* T0
.tv_sec
+ T1
.tv_usec
- T0
.tv_usec
) / (2.0 * ITER
));
113 void server(detail::JackSynchro
* sem
)
118 sem
->Allocate("JackSem", "default", 0);
120 while (((c
= getchar()) != 'q')) {
125 printf("SynchroSignal....\n");
128 printf("SynchroSignal OK\n");
132 printf("SemaphoreWait....\n");
134 printf("SemaphoreWait OK\n");
140 void client(detail::JackSynchro
* sem
)
145 sem
->Connect("JackSem", "default");
147 while (((c
= getchar()) != 'q')) {
152 printf("SemaphoreSignal....\n");
154 printf("SemaphoreSignal OK\n");
158 printf("SemaphoreWait....\n");
160 printf("SemaphoreWait OK\n");
166 int main (int argc
, char * const argv
[])
169 ServerThread
* serverthread
= NULL
;
170 ClientThread
* clientthread
= NULL
;
171 detail::JackSynchro
* sem1
= NULL
;
173 if (strcmp(argv
[1],"-s") == 0) {
174 printf("Posix semaphore\n");
175 sem1
= new JackPosixSemaphore();
178 if (strcmp(argv
[1],"-f") == 0) {
180 sem1
= new JackFifo();
184 if (strcmp(argv
[1],"-m") == 0) {
185 printf("Mach semaphore\n");
186 sem1
= new JackMachSemaphore();
191 if (strcmp(argv[2], "server") == 0) {
192 serverthread = new ServerThread();
194 clientthread = new ClientThread();
198 if (strcmp(argv
[2], "server") == 0) {
204 while (((c
= getchar()) != 'q')) {}