- dev->num_waiting--; /* no longer waiting */
- }
-}
-
-/*
- * Check if the device is blocked or not
- */
-int device_is_unmounted(DEVICE *dev)
-{
- int stat;
- P(dev->mutex);
- stat = (dev->dev_blocked == BST_UNMOUNTED) ||
- (dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
- V(dev->mutex);
- return stat;
-}
-
-void _unlock_device(const char *file, int line, DEVICE *dev)
-{
- Dmsg2(500, "unlock from %s:%d\n", file, line);
- V(dev->mutex);
-}
-
-/*
- * Block all other threads from using the device
- * Device must already be locked. After this call,
- * the device is blocked to any thread calling lock_device(),
- * but the device is not locked (i.e. no P on device). Also,
- * the current thread can do slip through the lock_device()
- * calls without blocking.
- */
-void _block_device(const char *file, int line, DEVICE *dev, int state)
-{
- Dmsg3(500, "block set %d from %s:%d\n", state, file, line);
- ASSERT(dev->dev_blocked == BST_NOT_BLOCKED);
- dev->dev_blocked = state; /* make other threads wait */
- dev->no_wait_id = pthread_self(); /* allow us to continue */
-}
-
-
-
-/*
- * Unblock the device, and wake up anyone who went to sleep.
- */
-void _unblock_device(const char *file, int line, DEVICE *dev)
-{
- Dmsg3(500, "unblock %d from %s:%d\n", dev->dev_blocked, file, line);
- ASSERT(dev->dev_blocked);
- dev->dev_blocked = BST_NOT_BLOCKED;
- dev->no_wait_id = 0;
- if (dev->num_waiting > 0) {
- pthread_cond_broadcast(&dev->wait); /* wake them up */
- }
-}
-
-/*
- * Enter with device locked and blocked
- * Exit with device unlocked and blocked by us.
- */
-void _steal_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state)
-{
- Dmsg4(500, "steal lock. old=%d new=%d from %s:%d\n", dev->dev_blocked, state,
- file, line);
- hold->dev_blocked = dev->dev_blocked;
- hold->dev_prev_blocked = dev->dev_prev_blocked;
- hold->no_wait_id = dev->no_wait_id;
- dev->dev_blocked = state;
- dev->no_wait_id = pthread_self();
- V(dev->mutex);
-}
-
-/*
- * Enter with device blocked by us but not locked
- * Exit with device locked, and blocked by previous owner
- */
-void _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold)
-{
- Dmsg4(500, "return lock. old=%d new=%d from %s:%d\n",
- dev->dev_blocked, hold->dev_blocked, file, line);
- P(dev->mutex);
- dev->dev_blocked = hold->dev_blocked;
- dev->dev_prev_blocked = hold->dev_prev_blocked;
- dev->no_wait_id = hold->no_wait_id;
- if (dev->dev_blocked == BST_NOT_BLOCKED && dev->num_waiting > 0) {
- pthread_cond_broadcast(&dev->wait); /* wake them up */