awake_note1.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. forgivewkp(wakeup);
  31. print("FAIL in note handler\n");
  32. exits("FAIL");
  33. }
  34. void
  35. main(int argc, char**argv)
  36. {
  37. int fd, i;
  38. if(argc > 1){
  39. fd = ocreate(argv[1], OWRITE, 0666);
  40. dup(fd, 1);
  41. sys_close(fd);
  42. }
  43. if (sys_notify(handler)){
  44. fprint(2, "%r\n");
  45. exits("sys_notify fails");
  46. }
  47. print("%s %d: waiting for note", argv[0], getpid());
  48. for(i = 0; i < 10*1000*1000; ++i)
  49. if(i % 4999 == 0){
  50. sleep(100);
  51. print(".");
  52. }
  53. print("FAIL\n");
  54. exits("FAIL");
  55. }