You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pool.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _IPXE_POOL_H
  2. #define _IPXE_POOL_H
  3. /** @file
  4. *
  5. * Pooled connections
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/interface.h>
  10. #include <ipxe/list.h>
  11. #include <ipxe/retry.h>
  12. /** A pooled connection */
  13. struct pooled_connection {
  14. /** List of pooled connections
  15. *
  16. * Note that each connecton in the pool has a running expiry
  17. * timer which holds a reference to the connection. We
  18. * therefore do not require the connection pool list to hold a
  19. * reference for each pooled connection.
  20. */
  21. struct list_head list;
  22. /** Expiry timer */
  23. struct retry_timer timer;
  24. /** Close expired pooled connection
  25. *
  26. * @v pool Pooled connection
  27. */
  28. void ( * expired ) ( struct pooled_connection *pool );
  29. /** Flags */
  30. unsigned int flags;
  31. };
  32. /** Pooled connection flags */
  33. enum pooled_connection_flags {
  34. /** Connection should be recycled after closing */
  35. POOL_RECYCLABLE = 0x0001,
  36. /** Connection has been recycled */
  37. POOL_RECYCLED = 0x0002,
  38. /** Connection is known to be alive */
  39. POOL_ALIVE = 0x0004,
  40. };
  41. extern void pool_add ( struct pooled_connection *pool, struct list_head *list,
  42. unsigned long expiry );
  43. extern void pool_del ( struct pooled_connection *pool );
  44. extern void pool_expired ( struct retry_timer *timer, int over );
  45. /**
  46. * Initialise a pooled connection
  47. *
  48. * @v pool Pooled connection
  49. * @v expired Close expired pooled connection method
  50. * @v refcnt Containing object reference counter
  51. */
  52. static inline __attribute__ (( always_inline )) void
  53. pool_init ( struct pooled_connection *pool,
  54. void ( * expired ) ( struct pooled_connection *pool ),
  55. struct refcnt *refcnt ) {
  56. INIT_LIST_HEAD ( &pool->list );
  57. timer_init ( &pool->timer, pool_expired, refcnt );
  58. pool->expired = expired;
  59. }
  60. /**
  61. * Mark pooled connection as recyclable
  62. *
  63. * @v pool Pooled connection
  64. */
  65. static inline __attribute__ (( always_inline )) void
  66. pool_recyclable ( struct pooled_connection *pool ) {
  67. pool->flags |= POOL_RECYCLABLE;
  68. }
  69. /**
  70. * Mark pooled connection as alive
  71. *
  72. * @v pool Pooled connection
  73. */
  74. static inline __attribute__ (( always_inline )) void
  75. pool_alive ( struct pooled_connection *pool ) {
  76. pool->flags |= POOL_ALIVE;
  77. }
  78. /**
  79. * Check if pooled connection is recyclable
  80. *
  81. * @v pool Pooled connection
  82. * @ret recyclable Pooled connection is recyclable
  83. */
  84. static inline __attribute__ (( always_inline )) int
  85. pool_is_recyclable ( struct pooled_connection *pool ) {
  86. return ( pool->flags & POOL_RECYCLABLE );
  87. }
  88. /**
  89. * Check if pooled connection is reopenable
  90. *
  91. * @v pool Pooled connection
  92. * @ret reopenable Pooled connection is reopenable
  93. */
  94. static inline __attribute__ (( always_inline )) int
  95. pool_is_reopenable ( struct pooled_connection *pool ) {
  96. /* A connection is reopenable if it has been recycled but is
  97. * not yet known to be alive.
  98. */
  99. return ( ( pool->flags & POOL_RECYCLED ) &
  100. ( ! ( pool->flags & POOL_ALIVE ) ) );
  101. }
  102. extern void pool_recycle ( struct interface *intf );
  103. #define pool_recycle_TYPE( object_type ) \
  104. typeof ( void ( object_type ) )
  105. extern void pool_reopen ( struct interface *intf );
  106. #define pool_reopen_TYPE( object_type ) \
  107. typeof ( void ( object_type ) )
  108. #endif /* _IPXE_POOL_H */