/*
* Copyright (c) 2007 Jan Hudecek
* Copyright (c) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup genericddi
* @{
*/
/** @file tasklet.h
* @brief Tasklets declarations
*/
#ifndef KERN_TASKLET_H_
#define KERN_TASKLET_H_
#include <arch/types.h>
#include <proc/task.h>
/** Structure describing a tasklet*/
typedef struct tasklet_descriptor {
/** callback to call */
void (*func)(void* data);
/** parameters to pass to func */
void* data;
/** state of the tasklet one of tasklet_state_enum */
uint32_t state;
struct tasklet_descriptor *next;
} tasklet_descriptor_t;
/** Initializes tasklets - except for the tasklet thread */
void tasklet_init(void);
/**
* Creates and runs the tasklet thread
*
* @param kernel_task Pointer to the kernel task - for create_thread
*/
void tasklet_run_tasklet_thread(task_t * kernel_task);
/** Thread which keeps executing scheduled enabled tasklets
* @param data not used
*/
void tasklet_thread(void* data);
/** Executes scheduled enabled tasklets */
void tasklet_do(void);
/** Initializes tasklet structure
* @param func tasklet callback function to be called
* @param data pointer to be passed to the tasklet function
*/
tasklet_descriptor_t* tasklet_register(void (*func)(void* data), void* data);
/** Schedules the tasklet for execution on current CPU
* @param t tasklet to be scheduled
*/
void tasklet_schedule(tasklet_descriptor_t* t);
/** Schedules the tasklet for execution on id CPU
* @param t tasklet to be scheduled
* @param id CPU id on which the tasklet will be scheduled
*/
void tasklet_schedule_SMP(tasklet_descriptor_t* t, uint32_t id);
/** Tasklet will not be run, even if scheduled
* @param t tasklet to be disabled
*/
void tasklet_disable(tasklet_descriptor_t* t);
/** Tasklet will be run if scheduled
* @param t tasklet to be enabled
*/
void tasklet_enable(tasklet_descriptor_t* t);
/** Frees the tasklet structure when no longer needed. The function doesn't provide
* any synchronization, the caller must be sure, the tasklet is not scheduled.
*
* @param tasklet to be freed
*/
void tasklet_free(tasklet_descriptor_t* t);
#endif
/** @}
*/