bulletin.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2017-2018 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Minimalist publish-subscribe mechanism.
  19. */
  20. #ifndef KERN_BULLETIN_H
  21. #define KERN_BULLETIN_H
  22. #include <stdint.h>
  23. #include <kern/macros.h>
  24. #include <kern/work.h>
  25. /*
  26. * Type for bulletin notification functions.
  27. *
  28. * The value is passed from the publisher unmodified, and can safely be
  29. * cast into a pointer. Notification functions run in the context of the
  30. * publisher.
  31. */
  32. typedef void (*bulletin_notif_fn_t)(uintptr_t value, void *arg);
  33. #include <kern/bulletin_i.h>
  34. struct bulletin;
  35. /*
  36. * Bulletin subscriber.
  37. */
  38. struct bulletin_sub;
  39. void bulletin_init(struct bulletin *bulletin);
  40. /*
  41. * Subscribe to a bulletin.
  42. *
  43. * Once subscribed, the notification function is called with its argument
  44. * each time the bulletin is published.
  45. */
  46. void bulletin_subscribe(struct bulletin *bulletin, struct bulletin_sub *sub,
  47. bulletin_notif_fn_t notif_fn, void *arg);
  48. /*
  49. * Unsubscribe from a bulletin.
  50. *
  51. * On return, the subscriber notification function may not be called any more.
  52. *
  53. * This function synchronizes with RCU.
  54. */
  55. void bulletin_unsubscribe(struct bulletin *bulletin, struct bulletin_sub *sub);
  56. /*
  57. * Publish a bulletin.
  58. *
  59. * All subscribers are notified by calling their notification function, with
  60. * the given value passed unmodified.
  61. */
  62. void bulletin_publish(struct bulletin *bulletin, uintptr_t value);
  63. #endif /* KERN_BULLETIN_H */