Added a new timer function which can be used similar to the BeOS kernel add_timer function.

The difference is that these callback functions will be executed in thread (not interrupt) context,
and that they shouldn't crash (as add_timer does).
Integrated the timer funtions into the timeout() and untimeout() FreeBSD emulation framework.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7474 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2004-05-09 18:58:17 +00:00
parent 25993bbe98
commit 0ec64b89a9
6 changed files with 125 additions and 39 deletions

View File

@ -7,13 +7,14 @@ SubDirCcFlags -Wall ;
UsePrivateHeaders net ;
R5KernelAddon ipro1000 : kernel drivers bin :
driver.c
device.c
if_compat.c
driver.c
device.c
if_compat.c
if_em.c
if_em_hw.c
if_em_osdep.c
mempool.c
if_em_osdep.c
mempool.c
timer.c
util.c
;

View File

@ -25,6 +25,7 @@
//#define DEBUG
#include "debug.h"
#include "timer.h"
#include "device.h"
#include "driver.h"
#include "mempool.h"
@ -130,7 +131,7 @@ init_driver(void)
if (info) {
char name[64];
sprintf(name, "net/ipro1000/%d", cards);
TRACE("/dev/%s is a %s\n", name, info);
PRINT("/dev/%s is a %s\n", name, info);
gDevList[cards] = item;
gDevNameList[cards] = strdup(name);
gDevNameList[cards + 1] = NULL;
@ -148,16 +149,24 @@ init_driver(void)
free(item);
if (!cards)
goto err;
goto err_cards;
if (initialize_timer() != B_OK) {
ERROR("timer init failed\n");
goto err_timer;
}
if (mempool_init(cards * 768) != 0) {
TRACE("mempool init failed\n");
goto err;
if (mempool_init(cards * 768) != B_OK) {
ERROR("mempool init failed\n");
goto err_mempool;
}
return B_OK;
err:
err_mempool:
terminate_timer();
err_timer:
err_cards:
put_module(B_PCI_MODULE_NAME);
return B_ERROR;
}
@ -169,6 +178,8 @@ uninit_driver(void)
int32 i;
TRACE("uninit_driver()\n");
terminate_timer();
mempool_exit();

View File

@ -50,38 +50,24 @@ contigfree(void *p, int p1, int p2)
delete_area(area_for(p));
}
static int32
timer_dispatch_hook(timer *t)
{
struct callout_handle *h = (struct callout_handle *)t;
TRACE("timer_dispatch_hook\n");
h->func(h->cookie);
return 0;
}
void
callout_handle_init(struct callout_handle *handle)
{
memset(handle, 0, sizeof(*handle));
handle->timer = -1;
}
struct callout_handle
timeout(timeout_func func, void *cookie, bigtime_t timeout)
timeout(timer_function func, void *cookie, bigtime_t timeout)
{
struct callout_handle h;
h.func = func;
h.cookie = cookie;
// add_timer(&h.t, timer_dispatch_hook, timeout, B_ONE_SHOT_RELATIVE_TIMER);
return h;
struct callout_handle handle;
handle.timer = create_timer(func, cookie, timeout, B_ONE_SHOT_RELATIVE_TIMER);
return handle;
}
void
untimeout(timeout_func func, void *cookie, struct callout_handle handle)
untimeout(timer_function func, void *cookie, struct callout_handle handle)
{
// cancel_timer(&handle.t);
delete_timer(handle.timer);
}
struct resource *

View File

@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "driver.h"
#include "device.h"
#include "debug.h"
#include "timer.h"
#define DBG 0
@ -159,18 +160,14 @@ static inline unsigned long vtophys(unsigned long virtual_addr)
#define PAGE_SIZE 4096
typedef void (*timeout_func)(void *);
struct callout_handle
{
struct timer t; // must be on top
timeout_func func;
void *cookie;
timer_id timer;
};
void callout_handle_init(struct callout_handle *handle);
struct callout_handle timeout(timeout_func func, void *cookie, bigtime_t timeout);
void untimeout(timeout_func func, void *cookie, struct callout_handle handle);
struct callout_handle timeout(timer_function func, void *cookie, bigtime_t timeout);
void untimeout(timer_function func, void *cookie, struct callout_handle handle);
// resource management

View File

@ -0,0 +1,49 @@
/* Intel PRO/1000 Family Driver
* Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies, and that both the
* copyright notice and this permission notice appear in supporting documentation.
*
* Marcus Overhagen makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*
* MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
* OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <Errors.h>
#include <OS.h>
#include <string.h>
#include "debug.h"
#include "timer.h"
timer_id
create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags)
{
return 0;
}
status_t
delete_timer(timer_id id)
{
return B_OK;
}
status_t
initialize_timer(void)
{
return B_OK;
}
status_t
terminate_timer(void)
{
return B_OK;
}

View File

@ -0,0 +1,42 @@
/* Intel PRO/1000 Family Driver
* Copyright (C) 2004 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies, and that both the
* copyright notice and this permission notice appear in supporting documentation.
*
* Marcus Overhagen makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*
* MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
* OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __TIMER_H
#define __TIMER_H
#include <KernelExport.h>
// Since the BeOS kernel timers are executed in interrupt context,
// a new timer has been created. The timers are executed in thread
// context, and are passed a cookie.
typedef int32 timer_id;
typedef void (*timer_function)(void *cookie);
// create_timer() cannot be called from interrupt context.
// flags can be B_ONE_SHOT_ABSOLUTE_TIMER, B_ONE_SHOT_RELATIVE_TIMER or B_PERIODIC_TIMER
timer_id create_timer(timer_function func, void *cookie, bigtime_t period, uint32 flags);
status_t delete_timer(timer_id id);
status_t initialize_timer(void);
status_t terminate_timer(void);
#endif