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