Пример #1
0
/**
 * kmem_cache_destroy - delete a cache
 * @cachep: the cache to destroy
 *
 * Remove a struct kmem_cache object from the slab cache.
 * Returns 0 on success.
 *
 * It is expected this function will be called by a module when it is
 * unloaded.  This will remove the cache completely, and avoid a duplicate
 * cache being allocated each time a module is loaded and unloaded, if the
 * module doesn't have persistent in-kernel storage across loads and unloads.
 *
 * The cache must be empty before calling this function.
 *
 * The caller must guarantee that noone will allocate memory from the cache
 * during the kmem_cache_destroy().
 */
void kmem_cache_destroy(struct kmem_cache *cache)
{
	ddekit_log(DEBUG_SLAB, "\"%s\"", cache->name);

	ddekit_slab_destroy(cache->ddekit_slab_cache);
	ddekit_simple_free(cache);
}
Пример #2
0
/*****************************************************************************
 *    remove_timer                                                           *
 ****************************************************************************/
static void remove_timer(int id)
{
	/* removes a timer from the timer list */
	struct ddekit_timer_s *l,*m;  
	
	lock_timer();

	for (l = &list; l &&  l->next && l->next->id!=id; l = l->next )
		;

	if (l && l->next) {
		m = l->next;

		DDEBUG_MSG_VERBOSE(
		    "deleting  timer at for tick: %d fn: %p, (now: %d)\n",
			m->exp, m->fn, jiffies);

		l->next = m->next;
		DDEBUG_MSG_TIMER(m);

		ddekit_simple_free(m); 
	}
	
	unlock_timer();
}
Пример #3
0
/*****************************************************************************
 *      ddekit_minix_deregister_msg_q                                        *
 ****************************************************************************/
void ddekit_minix_deregister_msg_q(struct ddekit_minix_msg_q *mq)
{
	struct ddekit_minix_msg_q *prev =_list, *it;

	for (it = _list->next; it != NULL ; it = it->next) {
		if (it == mq) {
			prev->next = it->next;
			break;
		}
		prev=it;
	}

	ddekit_sem_deinit(mq->msg_r_sem);
	ddekit_sem_deinit(mq->msg_w_sem);

	ddekit_simple_free(mq);

	DDEBUG_MSG_VERBOSE("destroyed msg_q from \n");
}
Пример #4
0
/*****************************************************************************
 *    ddekit_timer_thread                                                    *
 ****************************************************************************/
static void ddekit_timer_thread(void * data)
{
	struct ddekit_timer_s * l;

	/* rock around the clock! */ 
	for ( ; ; )
	{ 
		/* wait for timer interrupts */
		ddekit_sem_down(pending_timer_ints);
		DDEBUG_MSG_VERBOSE("handling timer interrupt");		
		
		/* execute all expired timers */
		while( (l = get_next(jiffies)) != 0 ) { 
			DDEBUG_MSG_TIMER(l);
			if (l->fn) {
				l->fn(l->args);
			}
			ddekit_simple_free(l);
		}
	}
}
Пример #5
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;
}
Пример #6
0
/******************************************************************************
 *       ddekit_lock_deinit                                                   *
 *****************************************************************************/
PUBLIC void ddekit_lock_deinit  (ddekit_lock_t *mtx)
{ 
	ddekit_simple_free(*mtx);
}