6 #include <exec/types.h>
9 #include <proto/exec.h>
13 struct SignalSemaphore sem
;
20 struct Task
*this = FindTask(NULL
);
21 Wait(SIGBREAKF_CTRL_C
);
22 int *counter
= this->tc_UserData
;
24 struct Library
*DOSBase
;
26 DOSBase
= OpenLibrary("dos.library", 0);
30 ObtainSemaphore(&sem
);
31 fd
= open(tmpname
, O_RDONLY
);
32 ReleaseSemaphore(&sem
);
34 for(i
= 0; i
< ITERATIONS
; i
++)
36 if(!flock(fd
, LOCK_EX
))
41 printf("\rprogress: %.2f%%", *counter
* 100.0 / (NPROCS
* ITERATIONS
));
53 CloseLibrary(DOSBase
);
59 tmpname
= mktemp("T:flockXXXXXX");
60 int fd
= open(tmpname
, O_CREAT
);
63 TEST((flock(fd
, LOCK_SH
|LOCK_NB
) == 0));
64 TEST((flock(fd
, LOCK_UN
) == 0));
66 TEST((flock(fd
, LOCK_EX
|LOCK_NB
) == 0));
67 TEST((flock(fd
, LOCK_UN
) == 0));
69 TEST((flock(fd
, LOCK_SH
) == 0));
70 TEST((flock(fd
, LOCK_UN
) == 0));
72 TEST((flock(fd
, LOCK_EX
) == 0));
73 TEST((flock(fd
, LOCK_UN
) == 0));
77 /* Create NPROCS processes increasing counter ITERATIONS times in an ugly
80 struct Process
*procs
[NPROCS
];
82 struct TagItem tags
[] =
84 { NP_Entry
, (IPTR
) entry
},
85 { NP_Name
, (IPTR
) "flocker" },
86 { NP_Output
, (IPTR
) Output() },
87 { NP_CloseOutput
, (IPTR
) FALSE
},
88 { NP_UserData
, (IPTR
) &counter
},
89 { NP_NotifyOnDeath
, (IPTR
) TRUE
},
95 for(i
= 0; i
< NPROCS
; i
++)
97 procs
[i
] = CreateNewProc(tags
);
99 ids
[i
] = GetETask(procs
[i
])->et_UniqueID
;
100 Signal((struct Task
*)procs
[i
], SIGBREAKF_CTRL_C
);
103 for(i
= 0; i
< NPROCS
; i
++)
110 TEST((counter
== NPROCS
* ITERATIONS
));