Esempio n. 1
0
static int semaphore1_do_test(struct vmm_chardev *cdev)
{
	int rc, failures = 0;

	/* Initialize semaphores */
	INIT_SEMAPHORE(&s1, 1, 1);
	INIT_SEMAPHORE(&s2, 1, 0);

	/* s1 semaphore should be available */
	if (!vmm_semaphore_avail(&s1)) {
		failures++;
	}

	/* s2 semaphore should not be available */
	if (vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Acquire s1 semaphore */
	rc = vmm_semaphore_down(&s1);
	if (rc) {
		return rc;
	}

	/* Start workers */
	vmm_threads_start(workers[0]);

	/* Wait for worker0 block on s1 semaphore */
	vmm_msleep(SLEEP_MSECS * 10);

	/* s2 semaphore should not be available */
	if (vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Release s1 semaphore */
	rc = vmm_semaphore_up(&s1);
	if (rc) {
		return rc;
	}

	/* Wait for worker0 wakeup and release s2 semaphore */
	vmm_msleep(SLEEP_MSECS * 10);

	/* s2 semaphore should be available */
	if (!vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Stop workers */
	vmm_threads_stop(workers[0]);

	return (failures) ? VMM_EFAIL : 0;
}
Esempio n. 2
0
struct super *super_get(struct vfs_fstype *type, struct blkdev *blkdev)
{
	struct super *sb;

	sb = objcache_alloc0(supers);
	if ( NULL == sb )
		return NULL;

	sb->s_type = type;
	sb->s_dev = blkdev;
	sb->s_inode_cache.rb_node = NULL;
	INIT_SEMAPHORE(&sb->s_sem, 1);
	if ( sb->s_type->read_super(sb) ) {
		printk("vfs: error mounting root filesystem\n");
		objcache_free2(supers, sb);
		return NULL;
	}

	list_add(&sb->s_list, &superblocks);
	return sb;
}