Hi- I've got a queue which has a semaphore whose value is equal to the number of items in the queue. The queue read function calls down_interruptible() on the semaphore, so that if the queue is empty, the semaphore has value 0 and the read blocks. The queue write function calls up().

However, although I don't need to protect against concurrent queue reads, I do need to protect against concurrent queue writes. The write code is fairly simple, so I'm using a spinlock_t. Very simplified code:

Code:
queue_read(q)
    down_interruptible(q->count_sem) /* decrement queue's item count */
    return next item on q

queue_write(q, item)
    spin_lock(&q->write_lock);
    add item to q
    up(&q->count_sem); /* increment queue's item count */
    spin_unlock(&q->write_lock);
I know you cannot do anything which might sleep while holding a spinlock, but I'm not sure whether up() can sleep or not. Is this ok?

John