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
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_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 */
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 */
42 /** Connection has been recycled */
43 POOL_RECYCLED = 0x0002,
44 /** Connection is known to be alive */
45 POOL_ALIVE = 0x0004,
46};
47
48extern void pool_add ( struct pooled_connection *pool, struct list_head *list,
49 unsigned long expiry );
50extern void pool_del ( struct pooled_connection *pool );
51extern 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 */
60static inline __attribute__ (( always_inline )) void
61pool_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 */
75static inline __attribute__ (( always_inline )) void
76pool_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 */
86static inline __attribute__ (( always_inline )) void
87pool_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 */
98static inline __attribute__ (( always_inline )) int
99pool_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 */
110static inline __attribute__ (( always_inline )) int
111pool_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
120extern void pool_recycle ( struct interface *intf );
121#define pool_recycle_TYPE( object_type ) \
122 typeof ( void ( object_type ) )
123
124extern void pool_reopen ( struct interface *intf );
125#define pool_reopen_TYPE( object_type ) \
126 typeof ( void ( object_type ) )
127
128#endif /* _IPXE_POOL_H */
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
Object interfaces.
Linked lists.
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void pool_expired(struct retry_timer *timer, int over __unused)
Close expired pooled connection.
Definition pool.c:102
static void(* expired)(struct pooled_connection *pool)
Definition pool.h:62
void pool_add(struct pooled_connection *pool, struct list_head *list, unsigned long expiry)
Add connection to pool.
Definition pool.c:64
pooled_connection_flags
Pooled connection flags.
Definition pool.h:39
@ POOL_ALIVE
Connection is known to be alive.
Definition pool.h:45
@ POOL_RECYCLED
Connection has been recycled.
Definition pool.h:43
@ POOL_RECYCLABLE
Connection should be recycled after closing.
Definition pool.h:41
void pool_recycle(struct interface *intf)
Recycle this connection after closing.
Definition pool.c:42
void pool_del(struct pooled_connection *pool)
Remove connection from pool.
Definition pool.c:83
timer_init & pool
Definition pool.h:66
void pool_reopen(struct interface *intf)
Reopen a defunct connection.
Definition pool.c:52
void pool_expired(struct retry_timer *timer, int over)
Close expired pooled connection.
Definition pool.c:102
Retry timers.
An object interface.
Definition interface.h:125
A doubly-linked list entry (or list head)
Definition list.h:19
A pooled connection.
Definition pool.h:18
struct retry_timer timer
Expiry timer.
Definition pool.h:28
void(* expired)(struct pooled_connection *pool)
Close expired pooled connection.
Definition pool.h:33
struct list_head list
List of pooled connections.
Definition pool.h:26
unsigned int flags
Flags.
Definition pool.h:35
A reference counter.
Definition refcnt.h:27
A retry timer.
Definition retry.h:22
A timer.
Definition timer.h:29