* Coding style fixes regarding whitespace usage.
* Copyright style fixes. * Implemented FreeBSD hardclock subsystem, which is needed to update the ticks variable. The previous usage of "#define ticks system_time()" wasn't sufficient anymore, as there are drivers using the ticks name for local scoped variables. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33785 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected]
|
||||
* Copyright 2009 Colin Günther, [email protected]
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ status_t
|
||||
init_condition_variables()
|
||||
{
|
||||
sConditionVariableCache = create_object_cache("condition variables",
|
||||
sizeof (ConditionVariable), 0, NULL, NULL, NULL);
|
||||
sizeof (ConditionVariable), 0, NULL, NULL, NULL);
|
||||
if (sConditionVariableCache == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
@@ -49,8 +49,8 @@ uninit_condition_variables()
|
||||
void
|
||||
_cv_init(struct cv* conditionVariable, const char* description)
|
||||
{
|
||||
conditionVariable->condVar =
|
||||
(ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0);
|
||||
conditionVariable->condVar
|
||||
= (ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0);
|
||||
conditionVariable->condVar->Init(NULL, description);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected].
|
||||
* Copyright 2009 Colin Günther, [email protected]
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
|
||||
status_t
|
||||
_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) {
|
||||
|
||||
_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount)
|
||||
{
|
||||
status_t status = B_OK;
|
||||
|
||||
idStore->idBuffer = radix_bitmap_create(maxIdCount);
|
||||
@@ -31,14 +31,15 @@ _new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) {
|
||||
|
||||
|
||||
void
|
||||
_delete_unrhdr_buffer_locked(struct unrhdr* idStore) {
|
||||
|
||||
_delete_unrhdr_buffer_locked(struct unrhdr* idStore)
|
||||
{
|
||||
radix_bitmap_destroy(idStore->idBuffer);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_alloc_unr_locked(struct unrhdr* idStore) {
|
||||
_alloc_unr_locked(struct unrhdr* idStore)
|
||||
{
|
||||
swap_addr_t slotIndex;
|
||||
int id = ID_STORE_FULL;
|
||||
|
||||
@@ -52,7 +53,8 @@ _alloc_unr_locked(struct unrhdr* idStore) {
|
||||
|
||||
|
||||
void
|
||||
_free_unr_locked(struct unrhdr* idStore, u_int identity) {
|
||||
_free_unr_locked(struct unrhdr* idStore, u_int identity)
|
||||
{
|
||||
uint32 slotIndex = (int32)identity - idStore->idBias;
|
||||
|
||||
radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected].
|
||||
* Copyright 2009, Colin Günther, [email protected]
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -7,34 +7,75 @@
|
||||
#include "device.h"
|
||||
|
||||
|
||||
#define CONVERT_HZ_TO_USECS(hertz) (1000000LL / (hertz))
|
||||
#define FREEBSD_CLOCK_FREQUENCY_IN_HZ 1000
|
||||
|
||||
|
||||
int ticks;
|
||||
struct net_timer hardclockTimer;
|
||||
static sem_id sHardClockSem;
|
||||
static thread_id sHardClockThread;
|
||||
|
||||
|
||||
void hardclock(struct net_timer*, void*);
|
||||
/*!
|
||||
* Implementation of FreeBSD's hardclock timer.
|
||||
*
|
||||
* Note: We are not using the FreeBSD variable hz as the invocation frequency
|
||||
* as it is the case in FreeBSD's hardclock function. This is due to lower
|
||||
* system load. The hz (see compat/sys/kernel.h) variable in the compat layer is
|
||||
* set to 1000000 Hz, whereas it is usually set to 1000 Hz for FreeBSD.
|
||||
*/
|
||||
static status_t
|
||||
hard_clock_thread(void* data)
|
||||
{
|
||||
status_t status = B_OK;
|
||||
const bigtime_t duration
|
||||
= CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ);
|
||||
|
||||
do {
|
||||
bigtime_t timeout = system_time() + duration;
|
||||
status = acquire_sem_etc(sHardClockSem, 1, B_ABSOLUTE_TIMEOUT, timeout);
|
||||
|
||||
if (system_time() >= timeout) {
|
||||
atomic_add((vint32*)&ticks, 1);
|
||||
}
|
||||
} while (status != B_BAD_SEM_ID);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
// TODO use the hardclock function in the compat layer actually.
|
||||
status_t
|
||||
init_clock()
|
||||
init_hard_clock()
|
||||
{
|
||||
gStack->init_timer(&hardclockTimer, &hardclock, NULL);
|
||||
gStack->set_timer(&hardclockTimer, hz);
|
||||
status_t status = B_OK;
|
||||
|
||||
return B_OK;
|
||||
sHardClockSem = create_sem(0, "hard clock wait");
|
||||
if (sHardClockSem < B_OK) {
|
||||
status = sHardClockSem;
|
||||
goto error1;
|
||||
}
|
||||
|
||||
sHardClockThread = spawn_kernel_thread(hard_clock_thread, "hard clock",
|
||||
B_NORMAL_PRIORITY, NULL);
|
||||
if (sHardClockThread < B_OK) {
|
||||
status = sHardClockThread;
|
||||
goto error2;
|
||||
}
|
||||
|
||||
return resume_thread(sHardClockThread);
|
||||
|
||||
error2:
|
||||
delete_sem(sHardClockSem);
|
||||
error1:
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uninit_clock()
|
||||
uninit_hard_clock()
|
||||
{
|
||||
gStack->cancel_timer(&hardclockTimer);
|
||||
}
|
||||
status_t status;
|
||||
|
||||
|
||||
void
|
||||
hardclock(struct net_timer* timer, void* argument)
|
||||
{
|
||||
atomic_add((vint32*)&ticks, 1);
|
||||
gStack->set_timer(&hardclockTimer, hz);
|
||||
delete_sem(sHardClockSem);
|
||||
wait_for_thread(sHardClockThread, &status);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected].
|
||||
* Copyright 2009 Colin Günther, [email protected].
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected]
|
||||
* Copyright 2009 Colin Günther, [email protected]
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef CONDVAR_H_
|
||||
@@ -12,7 +12,7 @@ extern "C" {
|
||||
|
||||
void _cv_init(struct cv*, const char*);
|
||||
void _cv_wait_unlocked(struct cv *);
|
||||
int _cv_timedwait_unlocked(struct cv*, int);
|
||||
int _cv_timedwait_unlocked(struct cv*, int);
|
||||
void _cv_signal(struct cv*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -67,8 +67,8 @@ void uninit_taskqueues(void);
|
||||
status_t init_condition_variables(void);
|
||||
void uninit_condition_variables(void);
|
||||
|
||||
status_t init_clock(void);
|
||||
void uninit_clock(void);
|
||||
status_t init_hard_clock(void);
|
||||
void uninit_hard_clock(void);
|
||||
|
||||
device_t find_root_device(int);
|
||||
|
||||
|
||||
@@ -149,29 +149,33 @@ _fbsd_init_driver(driver_t *driver)
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
status = init_mutexes();
|
||||
status = init_hard_clock();
|
||||
if (status < B_OK)
|
||||
goto err1;
|
||||
|
||||
status = init_mbufs();
|
||||
status = init_mutexes();
|
||||
if (status < B_OK)
|
||||
goto err2;
|
||||
|
||||
status = init_mbufs();
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
|
||||
init_bounce_pages();
|
||||
|
||||
status = init_condition_variables();
|
||||
if (status < B_OK)
|
||||
goto err3;
|
||||
goto err4;
|
||||
|
||||
if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) {
|
||||
status = init_taskqueues();
|
||||
if (status < B_OK)
|
||||
goto err4;
|
||||
goto err5;
|
||||
}
|
||||
|
||||
status = init_wlan_stack();
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
goto err6;
|
||||
|
||||
while (gDeviceCount < MAX_DEVICES) {
|
||||
device_t root, device;
|
||||
@@ -209,15 +213,17 @@ _fbsd_init_driver(driver_t *driver)
|
||||
|
||||
uninit_wlan_stack();
|
||||
|
||||
err5:
|
||||
err6:
|
||||
if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES))
|
||||
uninit_taskqueues();
|
||||
err4:
|
||||
err5:
|
||||
uninit_condition_variables();
|
||||
err3:
|
||||
err4:
|
||||
uninit_mbufs();
|
||||
err2:
|
||||
err3:
|
||||
uninit_mutexes();
|
||||
err2:
|
||||
uninit_hard_clock();
|
||||
err1:
|
||||
put_module(B_PCI_MODULE_NAME);
|
||||
return status;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected]
|
||||
* Copyright 2009 Colin Günther, [email protected]
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, [email protected]
|
||||
* Copyright 2009 Colin Günther, [email protected]
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <compat/sys/sleepqueue.h>
|
||||
|
||||
|
||||
#define ticks_to_msecs(t) (1000 * (t) / hz)
|
||||
#define ticks_to_msecs(t) (1000 * (t) / hz)
|
||||
|
||||
|
||||
int
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de.
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de
|
||||
* Copyright 2007, Hugo Santos. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
@@ -16,9 +16,9 @@
|
||||
#include <compat/sys/haiku-module.h>
|
||||
|
||||
|
||||
#define TQ_FLAGS_ACTIVE (1 << 0)
|
||||
#define TQ_FLAGS_BLOCKED (1 << 1)
|
||||
#define TQ_FLAGS_PENDING (1 << 2)
|
||||
#define TQ_FLAGS_ACTIVE (1 << 0)
|
||||
#define TQ_FLAGS_BLOCKED (1 << 1)
|
||||
#define TQ_FLAGS_PENDING (1 << 2)
|
||||
|
||||
|
||||
struct taskqueue {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de.
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de
|
||||
* Copyright 2007, Hugo Santos. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de.
|
||||
* Copyright 2009 Colin Günther, coling@gmx.de
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
@@ -19,12 +19,13 @@ extern struct mtx gIdStoreLock;
|
||||
|
||||
|
||||
struct unrhdr*
|
||||
new_unrhdr(int low, int high, struct mtx* mutex) {
|
||||
new_unrhdr(int low, int high, struct mtx* mutex)
|
||||
{
|
||||
struct unrhdr* idStore;
|
||||
uint32 maxIdCount = high - low + 1;
|
||||
|
||||
KASSERT(low <= high,
|
||||
("ID-Store: use error: %s(%u, %u)", __func__, low, high));
|
||||
("ID-Store: use error: %s(%u, %u)", __func__, low, high));
|
||||
|
||||
idStore = malloc(sizeof *idStore);
|
||||
if (idStore == NULL)
|
||||
@@ -47,14 +48,15 @@ new_unrhdr(int low, int high, struct mtx* mutex) {
|
||||
|
||||
|
||||
void
|
||||
delete_unrhdr(struct unrhdr* idStore) {
|
||||
delete_unrhdr(struct unrhdr* idStore)
|
||||
{
|
||||
KASSERT(uh != NULL,
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
|
||||
mtx_lock(idStore->storeMutex);
|
||||
|
||||
KASSERT(uh->idBuffer->root_size == 0,
|
||||
("ID-Store: %s: some ids are still in use..", __func__));
|
||||
("ID-Store: %s: some ids are still in use..", __func__));
|
||||
|
||||
_delete_unrhdr_buffer_locked(idStore);
|
||||
mtx_unlock(idStore->storeMutex);
|
||||
@@ -65,11 +67,12 @@ delete_unrhdr(struct unrhdr* idStore) {
|
||||
|
||||
|
||||
int
|
||||
alloc_unr(struct unrhdr* idStore) {
|
||||
alloc_unr(struct unrhdr* idStore)
|
||||
{
|
||||
int id;
|
||||
|
||||
KASSERT(uh != NULL,
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
|
||||
mtx_lock(idStore->storeMutex);
|
||||
id = _alloc_unr_locked(idStore);
|
||||
@@ -80,15 +83,15 @@ alloc_unr(struct unrhdr* idStore) {
|
||||
|
||||
|
||||
void
|
||||
free_unr(struct unrhdr* idStore, u_int identity) {
|
||||
|
||||
free_unr(struct unrhdr* idStore, u_int identity)
|
||||
{
|
||||
KASSERT(uh != NULL,
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
("ID-Store: %s: NULL pointer as argument.", __func__));
|
||||
|
||||
mtx_lock(idStore->storeMutex);
|
||||
|
||||
KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second " +
|
||||
"parameter is not in interval.", __func__, uh, item));
|
||||
KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second "
|
||||
+ "parameter is not in interval.", __func__, uh, item));
|
||||
|
||||
_free_unr_locked(idStore, identity);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de
|
||||
* Copyright 2009 Colin Günther, coling@gmx.de
|
||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef UNIT_H_
|
||||
@@ -21,13 +21,11 @@ struct unrhdr {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
status_t _new_unrhdr_buffer(struct unrhdr*, uint32);
|
||||
void _delete_unrhdr_buffer_locked(struct unrhdr*);
|
||||
int _alloc_unr_locked(struct unrhdr*);
|
||||
void _free_unr_locked(struct unrhdr*, u_int);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user