bfa_wc.h 1.4 KB

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