+}
+
+/*
+ * Routine: semaphore_destroy
+ *
+ * Destroys a semaphore and consume the caller's reference on the
+ * semaphore.
+ */
+kern_return_t
+semaphore_destroy(
+ task_t task,
+ semaphore_t semaphore)
+{
+ spl_t spl_level;
+
+ if (semaphore == SEMAPHORE_NULL) {
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ if (task == TASK_NULL) {
+ semaphore_dereference(semaphore);
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ task_lock(task);
+ spl_level = splsched();
+ semaphore_lock(semaphore);
+
+ if (semaphore->owner != task) {
+ semaphore_unlock(semaphore);
+ semaphore_dereference(semaphore);
+ splx(spl_level);
+ task_unlock(task);
+ return KERN_INVALID_ARGUMENT;
+ }
+
+ semaphore_destroy_internal(task, semaphore);
+ /* semaphore unlocked */
+