-/*
- * Ulock ownership MACROS
- *
- * Assumes: ulock internal lock is held
- */
-
-#define ulock_ownership_set(ul, th) \
- MACRO_BEGIN \
- thread_mtx_lock(th); \
- enqueue (&th->held_ulocks, (queue_entry_t) (ul)); \
- thread_mtx_unlock(th); \
- (ul)->holder = th; \
- MACRO_END
-
-#define ulock_ownership_clear(ul) \
- MACRO_BEGIN \
- thread_t th; \
- th = (ul)->holder; \
- if (th->active) { \
- thread_mtx_lock(th); \
- remqueue(&th->held_ulocks, \
- (queue_entry_t) (ul)); \
- thread_mtx_unlock(th); \
- } else { \
- remqueue(&th->held_ulocks, \
- (queue_entry_t) (ul)); \
- } \
- (ul)->holder = THREAD_NULL; \
- MACRO_END
-
-/*
- * Lock set ownership MACROS
- */
-
-#define lock_set_ownership_set(ls, t) \
- MACRO_BEGIN \
- task_lock((t)); \
- enqueue_head(&(t)->lock_set_list, (queue_entry_t) (ls));\
- (t)->lock_sets_owned++; \
- task_unlock((t)); \
- (ls)->owner = (t); \
- MACRO_END
-
-#define lock_set_ownership_clear(ls, t) \
- MACRO_BEGIN \
- task_lock((t)); \
- remqueue(&(t)->lock_set_list, (queue_entry_t) (ls)); \
- (t)->lock_sets_owned--; \
- task_unlock((t)); \
- MACRO_END
-
-unsigned int lock_set_event;
-#define LOCK_SET_EVENT ((event64_t)&lock_set_event)
-
-unsigned int lock_set_handoff;
-#define LOCK_SET_HANDOFF ((event64_t)&lock_set_handoff)
-
-/*
- * ROUTINE: lock_set_init [private]
- *
- * Initialize the lock_set subsystem.
- *
- * For now, we don't have anything to do here.
- */
-void
-lock_set_init(void)
-{
- return;
-}
-
-
-/*
- * ROUTINE: lock_set_create [exported]
- *
- * Creates a lock set.
- * The port representing the lock set is returned as a parameter.
- */
-kern_return_t
-lock_set_create (
- task_t task,
- lock_set_t *new_lock_set,
- int n_ulocks,
- int policy)
-{
- lock_set_t lock_set = LOCK_SET_NULL;
- ulock_t ulock;
- vm_size_t size;
- int x;
-
- *new_lock_set = LOCK_SET_NULL;
-
- if (task == TASK_NULL || n_ulocks <= 0 || policy > SYNC_POLICY_MAX)
- return KERN_INVALID_ARGUMENT;
-
- if ((VM_MAX_ADDRESS - sizeof(struct lock_set))/sizeof(struct ulock) < (unsigned)n_ulocks)
- return KERN_RESOURCE_SHORTAGE;
-
- size = sizeof(struct lock_set) + (sizeof(struct ulock) * (n_ulocks-1));
- lock_set = (lock_set_t) kalloc (size);
-
- if (lock_set == LOCK_SET_NULL)
- return KERN_RESOURCE_SHORTAGE;
-
-
- lock_set_lock_init(lock_set);
- lock_set->n_ulocks = n_ulocks;
- lock_set->ref_count = 1;
-
- /*
- * Create and initialize the lock set port
- */
- lock_set->port = ipc_port_alloc_kernel();
- if (lock_set->port == IP_NULL) {
- /* This will deallocate the lock set */
- lock_set_dereference(lock_set);
- return KERN_RESOURCE_SHORTAGE;
- }
-
- ipc_kobject_set (lock_set->port,
- (ipc_kobject_t) lock_set,
- IKOT_LOCK_SET);
-
- /*
- * Initialize each ulock in the lock set
- */
-
- for (x=0; x < n_ulocks; x++) {
- ulock = (ulock_t) &lock_set->ulock_list[x];
- ulock_lock_init(ulock);
- ulock->lock_set = lock_set;
- ulock->holder = THREAD_NULL;
- ulock->blocked = FALSE;
- ulock->unstable = FALSE;
- ulock->ho_wait = FALSE;
- wait_queue_init(&ulock->wait_queue, policy);
- }
-
- lock_set_ownership_set(lock_set, task);
-
- lock_set->active = TRUE;
- *new_lock_set = lock_set;