home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
463.lha
/
SemLibrary
/
test.c
< prev
Wrap
C/C++ Source or Header
|
1991-01-04
|
2KB
|
104 lines
/*
* TEST.C
*
* TEST the semaphore library. If DICE_AUTO_TEST is defined then also
* tests DICE's auto-library openning/closing feature. If not set then
* this source will compile under any compiler, including DICE.
*/
#include "defs.h"
#include <stdio.h>
long Sem;
#ifndef DICE_AUTO_TEST
long SemBase;
#endif
void
myexit(void)
{
if (Sem) {
DeleteSem(Sem);
Sem = 0;
}
#ifndef DICE_AUTO_TEST
if (SemBase) {
CloseLibrary(SemBase);
SemBase = 0;
}
#endif
}
main(ac, av)
char *av[];
{
char buf[256];
if (ac == 1) {
fputs("TEST sem [r/x/rw/xw/s/u [n]]\n", stderr);
exit(1);
}
atexit(myexit);
#ifndef DICE_AUTO_TEST
if (SemBase = OpenLibrary(SEMNAME, 0)) {
#else
{
#endif
Sem = CreateSem(av[1]);
if (ac >= 3) {
switch(av[2][0]) {
case 'r':
printf("read: ");
fflush(stdout);
SharSem(Sem);
puts("ok");
break;
case 'x':
printf("eXcl: ");
fflush(stdout);
ExclSem(Sem);
puts("ok");
break;
case 's':
printf("Sign: ");
fflush(stdout);
SigsSem(Sem, (av[3] ? atoi(av[3]) : 1));
puts("ok");
break;
case 'u':
printf("unlk: ");
fflush(stdout);
RelsSem(Sem);
puts("ok");
break;
default:
puts("huh?");
break;
}
if (av[2][1] == 'w') {
printf("(wait) ");
fflush(stdout);
WaitSem(Sem);
puts("ok");
}
}
{
GlobSem *gs = (GlobSem *)Sem;
printf("sem %08lx W=%08lx S=%08lx Refs=%d Lck=%d Task=%08lx\n",
gs,
GetHead(&gs->gs_WaitList),
GetHead(&gs->gs_SigsList),
gs->gs_RefCnt,
gs->gs_Locked,
gs->gs_Task
);
}
}
return(0);
}