mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 05:21:49 +03:00
Do not hold self-references. This then avoids the problem of having to
ensure that we only drop our self-reference exactly once. To maintain the guarantee that an object won't go out of scope unexpectedly while one of its event handlers is being called, the event-calling functions now automatically obtain and drop extra references.
This commit is contained in:
@@ -34,7 +34,8 @@ struct interface {
|
||||
* @v intf Interface
|
||||
* @ret intf Interface
|
||||
*/
|
||||
static inline struct interface * intf_get ( struct interface *intf ) {
|
||||
static inline __attribute__ (( always_inline )) struct interface *
|
||||
intf_get ( struct interface *intf ) {
|
||||
ref_get ( intf->refcnt );
|
||||
return intf;
|
||||
}
|
||||
@@ -44,7 +45,8 @@ static inline struct interface * intf_get ( struct interface *intf ) {
|
||||
*
|
||||
* @v intf Interface
|
||||
*/
|
||||
static inline void intf_put ( struct interface *intf ) {
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
intf_put ( struct interface *intf ) {
|
||||
ref_put ( intf->refcnt );
|
||||
}
|
||||
|
||||
|
||||
@@ -104,14 +104,24 @@ intf_to_job ( struct interface *intf ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get destination job control interface
|
||||
* Get reference to destination job control interface
|
||||
*
|
||||
* @v job Job control interface
|
||||
* @ret dest Destination interface
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) struct job_interface *
|
||||
job_dest ( struct job_interface *job ) {
|
||||
return intf_to_job ( job->intf.dest );
|
||||
job_get_dest ( struct job_interface *job ) {
|
||||
return intf_to_job ( intf_get ( job->intf.dest ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop reference to job control interface
|
||||
*
|
||||
* @v job Job control interface
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
job_put ( struct job_interface *job ) {
|
||||
intf_put ( &job->intf );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -173,14 +173,24 @@ intf_to_xfer ( struct interface *intf ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get destination data transfer interface
|
||||
* Get reference to destination data transfer interface
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @ret dest Destination interface
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) struct xfer_interface *
|
||||
xfer_dest ( struct xfer_interface *xfer ) {
|
||||
return intf_to_xfer ( xfer->intf.dest );
|
||||
xfer_get_dest ( struct xfer_interface *xfer ) {
|
||||
return intf_to_xfer ( intf_get ( xfer->intf.dest ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop reference to data transfer interface
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
xfer_put ( struct xfer_interface *xfer ) {
|
||||
intf_put ( &xfer->intf );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,8 +199,8 @@ xfer_dest ( struct xfer_interface *xfer ) {
|
||||
* @v xfer Data transfer interface
|
||||
* @v dest New destination interface
|
||||
*/
|
||||
static inline void xfer_plug ( struct xfer_interface *xfer,
|
||||
struct xfer_interface *dest ) {
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
xfer_plug ( struct xfer_interface *xfer, struct xfer_interface *dest ) {
|
||||
plug ( &xfer->intf, &dest->intf );
|
||||
}
|
||||
|
||||
@@ -200,8 +210,8 @@ static inline void xfer_plug ( struct xfer_interface *xfer,
|
||||
* @v a Data transfer interface A
|
||||
* @v b Data transfer interface B
|
||||
*/
|
||||
static inline void xfer_plug_plug ( struct xfer_interface *a,
|
||||
struct xfer_interface *b ) {
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
xfer_plug_plug ( struct xfer_interface *a, struct xfer_interface *b ) {
|
||||
plug_plug ( &a->intf, &b->intf );
|
||||
}
|
||||
|
||||
@@ -210,7 +220,8 @@ static inline void xfer_plug_plug ( struct xfer_interface *a,
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
*/
|
||||
static inline void xfer_unplug ( struct xfer_interface *xfer ) {
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
xfer_unplug ( struct xfer_interface *xfer ) {
|
||||
plug ( &xfer->intf, &null_xfer.intf );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user