/* Returns the next event in "free" state, and NULL if none are free. Note that no synchronization is done here, we assume the host_lock will syncrhonze things.  */
static struct srp_event_struct* get_event_struct(struct event_pool *pool)
/* Returns the next event in "free" state, and NULL if none are free. Note that no synchronization is done here, we assume the host_lock will syncrhonze things.  */
static struct srp_event_struct* get_event_struct(struct event_pool *pool)
{
	int i;
	int poolsize = pool->size;
	int offset = pool->next;
	for (i = 0; i < poolsize; i++) {
		offset = (offset + 1) % poolsize;
		if (!atomic_dec_if_positive(&pool->events[offset].free)) {
			pool->next = offset;
			return &pool->events[offset];
		}
	}
	printk(KERN_ERR "ibmvscsi: found no event struct in pool!\n");
	return NULL;
}