+ if (ref_count == 1) {
+ ipc_port_t port = semaphore->port;
+
+ if (IP_VALID(port) &&
+ OSCompareAndSwapPtr(port, IP_NULL, &semaphore->port)) {
+ /*
+ * We get to disassociate the port from the sema and
+ * drop the port's reference on the sema.
+ */
+ ipc_port_dealloc_kernel(port);
+ ref_count = hw_atomic_sub(&semaphore->ref_count, 1);
+ }
+ }