bfa_wc.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfa_wc.h Generic wait counter.
  19. */
  20. #ifndef __BFA_WC_H__
  21. #define __BFA_WC_H__
  22. typedef void (*bfa_wc_resume_t) (void *cbarg);
  23. struct bfa_wc_s {
  24. bfa_wc_resume_t wc_resume;
  25. void *wc_cbarg;
  26. int wc_count;
  27. };
  28. static inline void
  29. bfa_wc_up(struct bfa_wc_s *wc)
  30. {
  31. wc->wc_count++;
  32. }
  33. static inline void
  34. bfa_wc_down(struct bfa_wc_s *wc)
  35. {
  36. wc->wc_count--;
  37. if (wc->wc_count == 0)
  38. wc->wc_resume(wc->wc_cbarg);
  39. }
  40. /**
  41. * Initialize a waiting counter.
  42. */
  43. static inline void
  44. bfa_wc_init(struct bfa_wc_s *wc, bfa_wc_resume_t wc_resume, void *wc_cbarg)
  45. {
  46. wc->wc_resume = wc_resume;
  47. wc->wc_cbarg = wc_cbarg;
  48. wc->wc_count = 0;
  49. bfa_wc_up(wc);
  50. }
  51. /**
  52. * Wait for counter to reach zero
  53. */
  54. static inline void
  55. bfa_wc_wait(struct bfa_wc_s *wc)
  56. {
  57. bfa_wc_down(wc);
  58. }
  59. #endif