1 /* waitfor.c - waits for a given threadname 2 * (c) 2002, François Revol (mmu_man) for Haiku 3 * released under the MIT licence. 4 * 5 * ChangeLog: 6 * 04-26-2002 v1.0 7 * Initial. 8 * 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. 13 */ 14 15 #include <stdio.h> 16 #include <string.h> 17 18 #include <Messenger.h> 19 20 21 #define SNOOZE_TIME 100000 22 23 24 int 25 main(int argc, char** argv) 26 { 27 if (argc == 2) { 28 while (find_thread(argv[1]) < 0) { 29 if (snooze(SNOOZE_TIME) != B_OK) 30 return 1; 31 } 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; 36 } 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; 44 } 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; 56 } 57 58 return 0; 59 } 60 61