semobj.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library 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 GNU
  12. * Lesser General Public License for more details.
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  16. */
  17. #ifndef _COPPERPLATE_SEMOBJ_H
  18. #define _COPPERPLATE_SEMOBJ_H
  19. #include <boilerplate/compiler.h>
  20. #include <copperplate/reference.h>
  21. struct semobj_waitentry {
  22. pid_t pid;
  23. char name[32];
  24. };
  25. #ifdef CONFIG_XENO_COBALT
  26. #include <semaphore.h>
  27. struct semobj_corespec {
  28. sem_t sem;
  29. };
  30. #else /* CONFIG_XENO_MERCURY */
  31. #include <copperplate/syncobj.h>
  32. struct semobj_corespec {
  33. struct syncobj sobj;
  34. int flags;
  35. int value;
  36. };
  37. #endif /* CONFIG_XENO_MERCURY */
  38. struct semobj {
  39. struct semobj_corespec core;
  40. fnref_type(void (*)(struct semobj *smobj)) finalizer;
  41. };
  42. #define SEMOBJ_PRIO 0x1
  43. #define SEMOBJ_PULSE 0x2
  44. #define SEMOBJ_WARNDEL 0x4
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. int semobj_init(struct semobj *smobj,
  49. int flags, int value,
  50. fnref_type(void (*)(struct semobj *smobj)) finalizer);
  51. int semobj_destroy(struct semobj *smobj);
  52. void semobj_uninit(struct semobj *smobj);
  53. int semobj_post(struct semobj *smobj);
  54. int semobj_broadcast(struct semobj *smobj);
  55. int semobj_wait(struct semobj *smobj,
  56. const struct timespec *timeout) __must_check;
  57. int semobj_getvalue(struct semobj *smobj, int *sval);
  58. int semobj_inquire(struct semobj *smobj, size_t waitsz,
  59. struct semobj_waitentry *waitlist,
  60. int *val_r);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* _COPPERPLATE_SEMOBJ_H */