btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / waitfor.cpp
blob280978872509bbf3be25db27220d23eee3d01dd6
1 /* waitfor.c - waits for a given threadname
2 * (c) 2002, François Revol (mmu_man) for OpenBeOS
3 * released under the MIT licence.
5 * ChangeLog:
6 * 04-26-2002 v1.0
7 * Initial.
9 * waitfor threadname
10 * thesnooze() time is the same as the original, found using bdb waitfor foobar,
11 * and stepping until the snooze() call returns, the value is at the push
12 * instruction just before the call.
15 #include <stdio.h>
16 #include <string.h>
18 #include <Messenger.h>
21 #define SNOOZE_TIME 100000
24 int
25 main(int argc, char** argv)
27 if (argc == 2) {
28 while (find_thread(argv[1]) < 0) {
29 if (snooze(SNOOZE_TIME) != B_OK)
30 return 1;
32 } else if (argc == 3 && strcmp(argv[1], "-e") == 0) {
33 while (find_thread(argv[2]) >= 0) {
34 if (snooze(SNOOZE_TIME) != B_OK)
35 return 1;
37 } else if (argc == 3 && strcmp(argv[1], "-m") == 0) {
38 while (true) {
39 BMessenger messenger(argv[2]);
40 if (messenger.IsValid())
41 break;
42 if (snooze(SNOOZE_TIME) != B_OK)
43 return 1;
45 } else {
46 fprintf(stderr,
47 "Usage:\n"
48 " %s <thread_name>\n"
49 " wait until a thread with 'thread_name' has been started.\n\n"
50 " %s -e <thread_name>\n"
51 " wait until all threads with thread_name have ended.\n\n"
52 " %s -m <app_signature>\n"
53 " wait until the application specified by 'app_signature' is "
54 "is ready to receive messages.\n", argv[0], argv[0], argv[0]);
55 return 1;
58 return 0;