/drivers/staging/tidspbridge/include/dspbridge/sync.h

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C Header · 119 lines · 36 code · 18 blank · 65 comment · 3 complexity · af790eb95286bbe008aada7233792a77 MD5 · raw file

  1. /*
  2. * sync.h
  3. *
  4. * DSP-BIOS Bridge driver support functions for TI OMAP processors.
  5. *
  6. * Provide synchronization services.
  7. *
  8. * Copyright (C) 2005-2006 Texas Instruments, Inc.
  9. *
  10. * This package is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18. #ifndef _SYNC_H
  19. #define _SYNC_H
  20. #include <dspbridge/dbdefs.h>
  21. #include <dspbridge/host_os.h>
  22. /* Special timeout value indicating an infinite wait: */
  23. #define SYNC_INFINITE 0xffffffff
  24. /**
  25. * struct sync_object - the basic sync_object structure
  26. * @comp: use to signal events
  27. * @multi_comp: use to signal multiple events.
  28. *
  29. */
  30. struct sync_object{
  31. struct completion comp;
  32. struct completion *multi_comp;
  33. };
  34. /**
  35. * sync_init_event() - set initial state for a sync_event element
  36. * @event: event to be initialized.
  37. *
  38. * Set the initial state for a sync_event element.
  39. */
  40. static inline void sync_init_event(struct sync_object *event)
  41. {
  42. init_completion(&event->comp);
  43. event->multi_comp = NULL;
  44. }
  45. /**
  46. * sync_reset_event() - reset a sync_event element
  47. * @event: event to be reset.
  48. *
  49. * This function reset to the initial state to @event.
  50. */
  51. static inline void sync_reset_event(struct sync_object *event)
  52. {
  53. INIT_COMPLETION(event->comp);
  54. event->multi_comp = NULL;
  55. }
  56. /**
  57. * sync_set_event() - set or signal and specified event
  58. * @event: Event to be set..
  59. *
  60. * set the @event, if there is an thread waiting for the event
  61. * it will be waken up, this function only wakes one thread.
  62. */
  63. void sync_set_event(struct sync_object *event);
  64. /**
  65. * sync_wait_on_event() - waits for a event to be set.
  66. * @event: events to wait for it.
  67. * @timeout timeout on waiting for the evetn.
  68. *
  69. * This functios will wait until @event is set or until timeout. In case of
  70. * success the function will return 0 and
  71. * in case of timeout the function will return -ETIME
  72. * in case of signal the function will return -ERESTARTSYS
  73. */
  74. static inline int sync_wait_on_event(struct sync_object *event,
  75. unsigned timeout)
  76. {
  77. int res;
  78. res = wait_for_completion_interruptible_timeout(&event->comp,
  79. msecs_to_jiffies(timeout));
  80. if (!res)
  81. res = -ETIME;
  82. else if (res > 0)
  83. res = 0;
  84. return res;
  85. }
  86. /**
  87. * sync_wait_on_multiple_events() - waits for multiple events to be set.
  88. * @events: Array of events to wait for them.
  89. * @count: number of elements of the array.
  90. * @timeout timeout on waiting for the evetns.
  91. * @pu_index index of the event set.
  92. *
  93. * This functios will wait until any of the array element is set or until
  94. * timeout. In case of success the function will return 0 and
  95. * @pu_index will store the index of the array element set and in case
  96. * of timeout the function will return -ETIME.
  97. */
  98. int sync_wait_on_multiple_events(struct sync_object **events,
  99. unsigned count, unsigned timeout,
  100. unsigned *index);
  101. #endif /* _SYNC_H */