Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/refcount.h
| Show All 22 Lines | |||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| * SUCH DAMAGE. | * SUCH DAMAGE. | ||||
| */ | */ | ||||
| #ifndef __SYS_REFCOUNT_H__ | #ifndef __SYS_REFCOUNT_H__ | ||||
| #define __SYS_REFCOUNT_H__ | #define __SYS_REFCOUNT_H__ | ||||
| #include <machine/atomic.h> | #include <sys/types.h> | ||||
| #include <sys/kassert.h> | |||||
| #include <sys/systm.h> | |||||
| #if !defined(_KERNEL) && !defined(_STANDALONE) | #if !defined(_KERNEL) && !defined(_STANDALONE) | ||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| #endif | #endif | ||||
| #include <machine/atomic.h> | |||||
| #define REFCOUNT_SATURATED(val) (((val) & (1U << 31)) != 0) | #define REFCOUNT_SATURATED(val) (((val) & (1U << 31)) != 0) | ||||
| #define REFCOUNT_SATURATION_VALUE (3U << 30) | #define REFCOUNT_SATURATION_VALUE (3U << 30) | ||||
| /* | /* | ||||
| * Attempt to handle reference count overflow and underflow. Force the counter | * Attempt to handle reference count overflow and underflow. Force the counter | ||||
| * to stay at the saturation value so that a counter overflow cannot trigger | * to stay at the saturation value so that a counter overflow cannot trigger | ||||
| * destruction of the containing object and instead leads to a less harmful | * destruction of the containing object and instead leads to a less harmful | ||||
| * memory leak. | * memory leak. | ||||
| */ | */ | ||||
| static __inline void | static __inline void | ||||
| _refcount_update_saturated(volatile u_int *count) | _refcount_update_saturated(volatile u_int *count) | ||||
kib: u_int comes from machine/atomic.h->sys/atomic_common.h->sys/types.h.
Do we want to rely on this… | |||||
Done Inline ActionsI'd rather replace u_int with unsigned int, but it's a lot of churn. markj: I'd rather replace u_int with unsigned int, but it's a lot of churn. | |||||
Not Done Inline ActionsThat might be only marginally better. You'd avoid the namespace pollution of types.h, since u_int isn't defined in _types.h.. But it would be a lot more churn... imp: That might be only marginally better. You'd avoid the namespace pollution of types.h, since… | |||||
| { | { | ||||
| #ifdef INVARIANTS | #ifdef INVARIANTS | ||||
| panic("refcount %p wraparound", count); | panic("refcount %p wraparound", count); | ||||
| #else | #else | ||||
| atomic_store_int(count, REFCOUNT_SATURATION_VALUE); | atomic_store_int(count, REFCOUNT_SATURATION_VALUE); | ||||
| #endif | #endif | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines | |||||
u_int comes from machine/atomic.h->sys/atomic_common.h->sys/types.h.
Do we want to rely on this, or should sys/types.h included there directly?