-#define io_reference(io) \
-MACRO_BEGIN \
- assert((io)->io_references < IO_MAX_REFERENCES); \
- (io)->io_references++; \
-MACRO_END
+static inline void
+io_reference(ipc_object_t io) {
+ assert((io)->io_references > 0 &&
+ (io)->io_references < IO_MAX_REFERENCES);
+ OSIncrementAtomic(&((io)->io_references));
+}
+
+
+static inline void
+io_release(ipc_object_t io) {
+ assert((io)->io_references > 0 &&
+ (io)->io_references < IO_MAX_REFERENCES);
+ /* If we just removed the last reference count */
+ if ( 1 == OSDecrementAtomic(&((io)->io_references))) {
+ /* Free the object */
+ io_free(io_otype((io)), (io));
+ }
+}
+
+/*
+ * Retrieve a label for use in a kernel call that takes a security
+ * label as a parameter. If necessary, io_getlabel acquires internal
+ * (not io_lock) locks, and io_unlocklabel releases them.
+ */