mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-25 23:20:45 +00:00
MINOR: xref: Add a new xref system
xref is used to create a relation between two elements. Once an element is released, it breaks the relation. If the relation is already broken, it frees the xref struct. The pointer between two elements is a sort of refcount with max value 1. The relation is only between two elements. The pointer and the type of element a and b are conventional. Note that xref is initialised from Lua files because Lua is the only one user.
This commit is contained in:
parent
b01d28f976
commit
3c65b7a916
38
include/common/xref.h
Normal file
38
include/common/xref.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef __XREF_H__
|
||||||
|
#define __XREF_H__
|
||||||
|
|
||||||
|
/* xref is used to create relation between two elements.
|
||||||
|
* Once an element is released, it breaks the relation. If the
|
||||||
|
* relation is already broken, it frees the xref struct.
|
||||||
|
* The pointer between two elements is sort of a refcount with
|
||||||
|
* max value 1. The relation is only between two elements.
|
||||||
|
* The pointer and the type of elements a and b are conventional.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct xref {
|
||||||
|
struct xref *peer;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void xref_create(struct xref *xref_a, struct xref *xref_b)
|
||||||
|
{
|
||||||
|
xref_a->peer = xref_b;
|
||||||
|
xref_b->peer = xref_a;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct xref *xref_get_peer(struct xref *xref)
|
||||||
|
{
|
||||||
|
if (!xref->peer)
|
||||||
|
return NULL;
|
||||||
|
return xref->peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xref_disconnect(struct xref *xref)
|
||||||
|
{
|
||||||
|
if (!xref->peer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xref->peer->peer = NULL;
|
||||||
|
xref->peer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __XREF_H__ */
|
Loading…
Reference in New Issue
Block a user