예제 #1
0
파일: lock.c 프로젝트: DragonQuan/minix3
/******************************************************************************
 *       ddekit_lock_init_unlocked                                            *
 *****************************************************************************/
PUBLIC void ddekit_lock_init_unlocked(ddekit_lock_t *mtx) 
{ 
	(*mtx) = (struct ddekit_lock *) 
		ddekit_simple_malloc(sizeof(struct ddekit_lock));  
	(*mtx)->owner      = NULL; 
	(*mtx)->wait_queue = NULL;
}
예제 #2
0
파일: timer.c 프로젝트: AgamAgarwal/minix
/*****************************************************************************
 *    ddekit_add_timer                                                       *
 ****************************************************************************/
int ddekit_add_timer
(void (*fn)(void *), void *args, unsigned long timeout)
{
	struct ddekit_timer_s *t;
	
	t = (struct ddekit_timer_s *) 
	    ddekit_simple_malloc(sizeof(struct ddekit_timer_s ));
	
	t->fn   = fn;
	t->args = args;
	t->exp = (myclock_t) timeout;

	return insert_timer(t);
}
예제 #3
0
파일: msg_queue.c 프로젝트: Sciumo/minix
/*****************************************************************************
 *      ddekit_minix_create_msg_q                                            *
 ****************************************************************************/
struct ddekit_minix_msg_q *
ddekit_minix_create_msg_q(unsigned from, unsigned to)
{
	struct ddekit_minix_msg_q *mq =  (struct ddekit_minix_msg_q *)
	    ddekit_simple_malloc(sizeof(struct ddekit_minix_msg_q));
	
	mq->from = from;
	mq->to   = to;
	mq->msg_w_pos = 0;
	mq->msg_r_pos = 0;

	mq->msg_r_sem = ddekit_sem_init(0);
	mq->msg_w_sem = ddekit_sem_init(MESSAGE_QUEUE_SIZE);

	/* TODO: check for overlapping message ranges */
	mq->next = _list;
	_list     = mq;
	
	DDEBUG_MSG_VERBOSE("created msg_q from %x to %x\n", from , to);

	return mq;	
}
예제 #4
0
/**
 * kmem_cache_create - Create a cache.
 * @name: A string which is used in /proc/slabinfo to identify this cache.
 * @size: The size of objects to be created in this cache.
 * @align: The required alignment for the objects.
 * @flags: SLAB flags
 * @ctor: A constructor for the objects.
 *
 * Returns a ptr to the cache on success, NULL on failure.
 * Cannot be called within a int, but can be interrupted.
 * The @ctor is run when new pages are allocated by the cache
 * and the @dtor is run before the pages are handed back.
 *
 * @name must be valid until the cache is destroyed. This implies that
 * the module calling this has to destroy the cache before getting unloaded.
 *
 * The flags are
 *
 * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5)
 * to catch references to uninitialised memory.
 *
 * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check
 * for buffer overruns.
 *
 * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware
 * cacheline.  This can be beneficial if you're counting cycles as closely
 * as davem.
 */
struct kmem_cache * kmem_cache_create(const char *name, size_t size, size_t align,
                                      unsigned long flags,
                                      void (*ctor)(void *))
{
	ddekit_log(DEBUG_SLAB, "\"%s\" obj_size=%d", name, size);

	struct kmem_cache *cache;

	if (!name) {
		printk("kmem_cache name reqeuired\n");
		return 0;
	}

	cache = ddekit_simple_malloc(sizeof(*cache));
	if (!cache) {
		printk("No memory for slab cache\n");
		return 0;
	}

	/* Initialize a physically contiguous cache for kmem */
	if (!(cache->ddekit_slab_cache = ddekit_slab_init(size, 1))) {
		printk("DDEKit slab init failed\n");
		ddekit_simple_free(cache);
		return 0;
	}

	cache->name = name;
	cache->size = size;
	cache->ctor = ctor;

	ddekit_lock_init_unlocked(&cache->cache_lock);

	ddekit_printf("Created cache %p with lock %p\n", cache, &cache->cache_lock);
	
	return cache;
}