1
0

awake_note0.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. void
  21. handler(void *v, char *s)
  22. {
  23. int64_t wakeup;
  24. wakeup = sys_awake(1000);
  25. while(sys_rendezvous(&wakeup, (void*)1) == (void*)~0)
  26. if(jehanne_awakened(wakeup)){
  27. print("PASS\n");
  28. exits(nil);
  29. }
  30. print("FAIL in note handler\n");
  31. exits("FAIL");
  32. }
  33. void
  34. main(int argc, char**argv)
  35. {
  36. int fd, i;
  37. if(argc > 1){
  38. fd = ocreate(argv[1], OWRITE, 0666);
  39. dup(fd, 1);
  40. sys_close(fd);
  41. }
  42. if (sys_notify(handler)){
  43. fprint(2, "%r\n");
  44. exits("sys_notify fails");
  45. }
  46. print("%s %d: waiting for note", argv[0], getpid());
  47. for(i = 0; i < 10*1000*1000; ++i)
  48. if(i % 4999 == 0){
  49. for(fd = 0; fd < 1000000; ++fd)
  50. ;
  51. print(".");
  52. }
  53. print("FAIL\n");
  54. exits("FAIL");
  55. }