* 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:
Colin Günther
2009-10-27 08:14:03 +00:00
parent 94aefa169e
commit 2406849d4a
13 changed files with 116 additions and 66 deletions
+3 -3
View File
@@ -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. * All Rights Reserved. Distributed under the terms of the MIT License.
*/ */
@@ -49,8 +49,8 @@ uninit_condition_variables()
void void
_cv_init(struct cv* conditionVariable, const char* description) _cv_init(struct cv* conditionVariable, const char* description)
{ {
conditionVariable->condVar = conditionVariable->condVar
(ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0); = (ConditionVariable*)object_cache_alloc(sConditionVariableCache, 0);
conditionVariable->condVar->Init(NULL, description); conditionVariable->condVar->Init(NULL, description);
} }
+9 -7
View File
@@ -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. * All Rights Reserved. Distributed under the terms of the MIT License.
* *
*/ */
@@ -18,8 +18,8 @@
status_t status_t
_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) { _new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount)
{
status_t status = B_OK; status_t status = B_OK;
idStore->idBuffer = radix_bitmap_create(maxIdCount); idStore->idBuffer = radix_bitmap_create(maxIdCount);
@@ -31,14 +31,15 @@ _new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount) {
void void
_delete_unrhdr_buffer_locked(struct unrhdr* idStore) { _delete_unrhdr_buffer_locked(struct unrhdr* idStore)
{
radix_bitmap_destroy(idStore->idBuffer); radix_bitmap_destroy(idStore->idBuffer);
} }
int int
_alloc_unr_locked(struct unrhdr* idStore) { _alloc_unr_locked(struct unrhdr* idStore)
{
swap_addr_t slotIndex; swap_addr_t slotIndex;
int id = ID_STORE_FULL; int id = ID_STORE_FULL;
@@ -52,7 +53,8 @@ _alloc_unr_locked(struct unrhdr* idStore) {
void 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; uint32 slotIndex = (int32)identity - idStore->idBias;
radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1); radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1);
+65 -24
View File
@@ -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. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@@ -7,34 +7,75 @@
#include "device.h" #include "device.h"
#define CONVERT_HZ_TO_USECS(hertz) (1000000LL / (hertz))
#define FREEBSD_CLOCK_FREQUENCY_IN_HZ 1000
int ticks; 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.
*
// TODO use the hardclock function in the compat layer actually. * Note: We are not using the FreeBSD variable hz as the invocation frequency
status_t * as it is the case in FreeBSD's hardclock function. This is due to lower
init_clock() * 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)
{ {
gStack->init_timer(&hardclockTimer, &hardclock, NULL); status_t status = B_OK;
gStack->set_timer(&hardclockTimer, hz); const bigtime_t duration
= CONVERT_HZ_TO_USECS(FREEBSD_CLOCK_FREQUENCY_IN_HZ);
return B_OK; do {
} bigtime_t timeout = system_time() + duration;
status = acquire_sem_etc(sHardClockSem, 1, B_ABSOLUTE_TIMEOUT, timeout);
if (system_time() >= timeout) {
void
uninit_clock()
{
gStack->cancel_timer(&hardclockTimer);
}
void
hardclock(struct net_timer* timer, void* argument)
{
atomic_add((vint32*)&ticks, 1); atomic_add((vint32*)&ticks, 1);
gStack->set_timer(&hardclockTimer, hz); }
} while (status != B_BAD_SEM_ID);
return status;
}
status_t
init_hard_clock()
{
status_t status = 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_hard_clock()
{
status_t status;
delete_sem(sHardClockSem);
wait_for_thread(sHardClockThread, &status);
} }
+1 -1
View File
@@ -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. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
+1 -1
View File
@@ -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. * All Rights Reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef CONDVAR_H_ #ifndef CONDVAR_H_
+2 -2
View File
@@ -67,8 +67,8 @@ void uninit_taskqueues(void);
status_t init_condition_variables(void); status_t init_condition_variables(void);
void uninit_condition_variables(void); void uninit_condition_variables(void);
status_t init_clock(void); status_t init_hard_clock(void);
void uninit_clock(void); void uninit_hard_clock(void);
device_t find_root_device(int); device_t find_root_device(int);
+15 -9
View File
@@ -149,29 +149,33 @@ _fbsd_init_driver(driver_t *driver)
if (status < B_OK) if (status < B_OK)
return status; return status;
status = init_mutexes(); status = init_hard_clock();
if (status < B_OK) if (status < B_OK)
goto err1; goto err1;
status = init_mbufs(); status = init_mutexes();
if (status < B_OK) if (status < B_OK)
goto err2; goto err2;
status = init_mbufs();
if (status < B_OK)
goto err3;
init_bounce_pages(); init_bounce_pages();
status = init_condition_variables(); status = init_condition_variables();
if (status < B_OK) if (status < B_OK)
goto err3; goto err4;
if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) { if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) {
status = init_taskqueues(); status = init_taskqueues();
if (status < B_OK) if (status < B_OK)
goto err4; goto err5;
} }
status = init_wlan_stack(); status = init_wlan_stack();
if (status < B_OK) if (status < B_OK)
goto err5; goto err6;
while (gDeviceCount < MAX_DEVICES) { while (gDeviceCount < MAX_DEVICES) {
device_t root, device; device_t root, device;
@@ -209,15 +213,17 @@ _fbsd_init_driver(driver_t *driver)
uninit_wlan_stack(); uninit_wlan_stack();
err5: err6:
if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES)) if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES))
uninit_taskqueues(); uninit_taskqueues();
err4: err5:
uninit_condition_variables(); uninit_condition_variables();
err3: err4:
uninit_mbufs(); uninit_mbufs();
err2: err3:
uninit_mutexes(); uninit_mutexes();
err2:
uninit_hard_clock();
err1: err1:
put_module(B_PCI_MODULE_NAME); put_module(B_PCI_MODULE_NAME);
return status; return status;
+1 -1
View File
@@ -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. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
+1 -1
View File
@@ -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. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Colin Günther, [email protected]. * Copyright 2009, Colin Günther, [email protected]
* Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2009, Colin Günther, [email protected]. * Copyright 2009, Colin Günther, [email protected]
* Copyright 2007, Hugo Santos. All Rights Reserved. * Copyright 2007, Hugo Santos. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
+11 -8
View File
@@ -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. * All Rights Reserved. Distributed under the terms of the MIT License.
* *
*/ */
@@ -19,7 +19,8 @@ extern struct mtx gIdStoreLock;
struct unrhdr* struct unrhdr*
new_unrhdr(int low, int high, struct mtx* mutex) { new_unrhdr(int low, int high, struct mtx* mutex)
{
struct unrhdr* idStore; struct unrhdr* idStore;
uint32 maxIdCount = high - low + 1; uint32 maxIdCount = high - low + 1;
@@ -47,7 +48,8 @@ new_unrhdr(int low, int high, struct mtx* mutex) {
void void
delete_unrhdr(struct unrhdr* idStore) { delete_unrhdr(struct unrhdr* idStore)
{
KASSERT(uh != NULL, KASSERT(uh != NULL,
("ID-Store: %s: NULL pointer as argument.", __func__)); ("ID-Store: %s: NULL pointer as argument.", __func__));
@@ -65,7 +67,8 @@ delete_unrhdr(struct unrhdr* idStore) {
int int
alloc_unr(struct unrhdr* idStore) { alloc_unr(struct unrhdr* idStore)
{
int id; int id;
KASSERT(uh != NULL, KASSERT(uh != NULL,
@@ -80,15 +83,15 @@ alloc_unr(struct unrhdr* idStore) {
void void
free_unr(struct unrhdr* idStore, u_int identity) { free_unr(struct unrhdr* idStore, u_int identity)
{
KASSERT(uh != NULL, KASSERT(uh != NULL,
("ID-Store: %s: NULL pointer as argument.", __func__)); ("ID-Store: %s: NULL pointer as argument.", __func__));
mtx_lock(idStore->storeMutex); mtx_lock(idStore->storeMutex);
KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second " + KASSERT((int32)item - uh->idBias >= 0, ("ID-Store: %s(%p, %u): second "
"parameter is not in interval.", __func__, uh, item)); + "parameter is not in interval.", __func__, uh, item));
_free_unr_locked(idStore, identity); _free_unr_locked(idStore, identity);
+1 -3
View File
@@ -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. * All Rights Reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef UNIT_H_ #ifndef UNIT_H_
@@ -21,13 +21,11 @@ struct unrhdr {
extern "C" { extern "C" {
#endif #endif
status_t _new_unrhdr_buffer(struct unrhdr*, uint32); status_t _new_unrhdr_buffer(struct unrhdr*, uint32);
void _delete_unrhdr_buffer_locked(struct unrhdr*); void _delete_unrhdr_buffer_locked(struct unrhdr*);
int _alloc_unr_locked(struct unrhdr*); int _alloc_unr_locked(struct unrhdr*);
void _free_unr_locked(struct unrhdr*, u_int); void _free_unr_locked(struct unrhdr*, u_int);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif