#include <stdio.h>
#include <errno.h>
#include "semaphore.hh"
#include "timer.hh"
Include dependency graph for testsem.cc:
Go to the source code of this file.
Defines | |
#define | BUFFERSIZE 80 |
Functions | |
int | main (int argc, char **argv) |
|
|
|
Definition at line 48 of file testsem.cc. 00050 { 00051 RCS_SEMAPHORE *sem; 00052 00053 #if defined (VXWORKS) 00054 sem = new RCS_SEMAPHORE (0x100, RCS_SEMAPHORE_CREATE, 0664, 0); 00055 taskSpawn ("semtaker", 100, VX_FP_TASK, 8000, (FUNCPTR) semtaker); 00056 #else 00057 if (argc > 1) 00058 { 00059 /* any cmd line args mean this is the semaphore creator */ 00060 sem = new RCS_SEMAPHORE (0x100, RCS_SEMAPHORE_CREATE, 0664, 0); 00061 } 00062 else 00063 { 00064 sem = new RCS_SEMAPHORE (0x100, RCS_SEMAPHORE_NOCREATE); 00065 } 00066 #endif 00067 00068 /* run give and take, interactively */ 00069 while (!feof (stdin)) 00070 { 00071 #define BUFFERSIZE 80 00072 char buf[BUFFERSIZE]; 00073 fputs ("give, take, or quit (g/t/q)? ", stdout); 00074 fgets (buf, BUFFERSIZE, stdin); 00075 00076 if (buf[0] == 'q') 00077 break; 00078 if (buf[0] == 'g') 00079 { 00080 /* give it */ 00081 if (sem->post () == -1) 00082 { 00083 fputs ("can't give it\n", stdout); 00084 } 00085 else 00086 { 00087 fputs ("gave it\n", stdout); 00088 printf ("val = %d\n", sem->getvalue ()); 00089 } 00090 } 00091 if (buf[0] == 't') 00092 { 00093 /* take it */ 00094 if (sem->wait () == -1) 00095 { 00096 fputs ("can't give it\n", stdout); 00097 } 00098 else 00099 { 00100 fputs ("took it\n", stdout); 00101 printf ("val = %d\n", sem->getvalue ()); 00102 } 00103 } 00104 } 00105 00106 #if defined (VXWORKS) 00107 semtaker_done = 1; 00108 #endif 00109 00110 delete sem; 00111 } |