iPXE
pool.h
Go to the documentation of this file.
00001 #ifndef _IPXE_POOL_H
00002 #define _IPXE_POOL_H
00003 
00004 /** @file
00005  *
00006  * Pooled connections
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/interface.h>
00013 #include <ipxe/list.h>
00014 #include <ipxe/retry.h>
00015 
00016 /** A pooled connection */
00017 struct pooled_connection {
00018         /** List of pooled connections
00019          *
00020          * Note that each connecton in the pool has a running expiry
00021          * timer which holds a reference to the connection.  We
00022          * therefore do not require the connection pool list to hold a
00023          * reference for each pooled connection.
00024          */
00025         struct list_head list;
00026         /** Expiry timer */
00027         struct retry_timer timer;
00028         /** Close expired pooled connection
00029          *
00030          * @v pool              Pooled connection
00031          */
00032         void ( * expired ) ( struct pooled_connection *pool );
00033         /** Flags */
00034         unsigned int flags;
00035 };
00036 
00037 /** Pooled connection flags */
00038 enum pooled_connection_flags {
00039         /** Connection should be recycled after closing */
00040         POOL_RECYCLABLE = 0x0001,
00041         /** Connection has been recycled */
00042         POOL_RECYCLED = 0x0002,
00043         /** Connection is known to be alive */
00044         POOL_ALIVE = 0x0004,
00045 };
00046 
00047 extern void pool_add ( struct pooled_connection *pool, struct list_head *list,
00048                        unsigned long expiry );
00049 extern void pool_del ( struct pooled_connection *pool );
00050 extern void pool_expired ( struct retry_timer *timer, int over );
00051 
00052 /**
00053  * Initialise a pooled connection
00054  *
00055  * @v pool              Pooled connection
00056  * @v expired           Close expired pooled connection method
00057  * @v refcnt            Containing object reference counter
00058  */
00059 static inline __attribute__ (( always_inline )) void
00060 pool_init ( struct pooled_connection *pool,
00061             void ( * expired ) ( struct pooled_connection *pool ),
00062             struct refcnt *refcnt ) {
00063 
00064         INIT_LIST_HEAD ( &pool->list );
00065         timer_init ( &pool->timer, pool_expired, refcnt );
00066         pool->expired = expired;
00067 }
00068 
00069 /**
00070  * Mark pooled connection as recyclable
00071  *
00072  * @v pool              Pooled connection
00073  */
00074 static inline __attribute__ (( always_inline )) void
00075 pool_recyclable ( struct pooled_connection *pool ) {
00076 
00077         pool->flags |= POOL_RECYCLABLE;
00078 }
00079 
00080 /**
00081  * Mark pooled connection as alive
00082  *
00083  * @v pool              Pooled connection
00084  */
00085 static inline __attribute__ (( always_inline )) void
00086 pool_alive ( struct pooled_connection *pool ) {
00087 
00088         pool->flags |= POOL_ALIVE;
00089 }
00090 
00091 /**
00092  * Check if pooled connection is recyclable
00093  *
00094  * @v pool              Pooled connection
00095  * @ret recyclable      Pooled connection is recyclable
00096  */
00097 static inline __attribute__ (( always_inline )) int
00098 pool_is_recyclable ( struct pooled_connection *pool ) {
00099 
00100         return ( pool->flags & POOL_RECYCLABLE );
00101 }
00102 
00103 /**
00104  * Check if pooled connection is reopenable
00105  *
00106  * @v pool              Pooled connection
00107  * @ret reopenable      Pooled connection is reopenable
00108  */
00109 static inline __attribute__ (( always_inline )) int
00110 pool_is_reopenable ( struct pooled_connection *pool ) {
00111 
00112         /* A connection is reopenable if it has been recycled but is
00113          * not yet known to be alive.
00114          */
00115         return ( ( pool->flags & POOL_RECYCLED ) &&
00116                  ( ! ( pool->flags & POOL_ALIVE ) ) );
00117 }
00118 
00119 extern void pool_recycle ( struct interface *intf );
00120 #define pool_recycle_TYPE( object_type ) \
00121         typeof ( void ( object_type ) )
00122 
00123 extern void pool_reopen ( struct interface *intf );
00124 #define pool_reopen_TYPE( object_type ) \
00125         typeof ( void ( object_type ) )
00126 
00127 #endif /* _IPXE_POOL_H */