2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 #include <exec/types.h>
12 #include <proto/dos.h>
14 #include <proto/exec.h>
18 struct SignalSemaphore sem
;
25 struct Task
*this = FindTask(NULL
);
26 Wait(SIGBREAKF_CTRL_C
);
27 int *counter
= this->tc_UserData
;
29 struct Library
*DOSBase
;
31 DOSBase
= OpenLibrary("dos.library", 0);
35 ObtainSemaphore(&sem
);
36 fd
= open(tmpname
, O_RDONLY
);
37 ReleaseSemaphore(&sem
);
39 for(i
= 0; i
< ITERATIONS
; i
++)
41 if(!flock(fd
, LOCK_EX
))
46 printf("\rprogress: %.2f%%", *counter
* 100.0 / (NPROCS
* ITERATIONS
));
58 CloseLibrary(DOSBase
);
64 tmpname
= mktemp("T:flockXXXXXX");
65 int fd
= open(tmpname
, O_CREAT
);
68 TEST((flock(fd
, LOCK_SH
|LOCK_NB
) == 0));
69 TEST((flock(fd
, LOCK_UN
) == 0));
71 TEST((flock(fd
, LOCK_EX
|LOCK_NB
) == 0));
72 TEST((flock(fd
, LOCK_UN
) == 0));
74 TEST((flock(fd
, LOCK_SH
) == 0));
75 TEST((flock(fd
, LOCK_UN
) == 0));
77 TEST((flock(fd
, LOCK_EX
) == 0));
78 TEST((flock(fd
, LOCK_UN
) == 0));
82 /* Create NPROCS processes increasing counter ITERATIONS times in an ugly
85 struct Process
*procs
[NPROCS
];
87 struct TagItem tags
[] =
89 { NP_Entry
, (IPTR
) entry
},
90 { NP_Name
, (IPTR
) "flocker" },
91 { NP_Output
, (IPTR
) Output() },
92 { NP_CloseOutput
, (IPTR
) FALSE
},
93 { NP_UserData
, (IPTR
) &counter
},
94 { NP_NotifyOnDeath
, (IPTR
) TRUE
},
100 for(i
= 0; i
< NPROCS
; i
++)
102 procs
[i
] = CreateNewProc(tags
);
104 ids
[i
] = GetETask(procs
[i
])->et_UniqueID
;
105 Signal((struct Task
*)procs
[i
], SIGBREAKF_CTRL_C
);
108 for(i
= 0; i
< NPROCS
; i
++)
115 TEST((counter
== NPROCS
* ITERATIONS
));