* 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
+4 -4
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.
*/ */
@@ -29,7 +29,7 @@ status_t
init_condition_variables() init_condition_variables()
{ {
sConditionVariableCache = create_object_cache("condition variables", sConditionVariableCache = create_object_cache("condition variables",
sizeof (ConditionVariable), 0, NULL, NULL, NULL); sizeof (ConditionVariable), 0, NULL, NULL, NULL);
if (sConditionVariableCache == NULL) if (sConditionVariableCache == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -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);
+58 -17
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.
*
* 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 status_t
init_clock() init_hard_clock()
{ {
gStack->init_timer(&hardclockTimer, &hardclock, NULL); status_t status = B_OK;
gStack->set_timer(&hardclockTimer, hz);
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 void
uninit_clock() uninit_hard_clock()
{ {
gStack->cancel_timer(&hardclockTimer); status_t status;
}
delete_sem(sHardClockSem);
void wait_for_thread(sHardClockThread, &status);
hardclock(struct net_timer* timer, void* argument)
{
atomic_add((vint32*)&ticks, 1);
gStack->set_timer(&hardclockTimer, hz);
} }
+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.
*/ */
+2 -2
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_
@@ -12,7 +12,7 @@ extern "C" {
void _cv_init(struct cv*, const char*); void _cv_init(struct cv*, const char*);
void _cv_wait_unlocked(struct cv *); 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*); void _cv_signal(struct cv*);
#ifdef __cplusplus #ifdef __cplusplus
+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.
*/ */
+2 -2
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.
*/ */
@@ -9,7 +9,7 @@
#include <compat/sys/sleepqueue.h> #include <compat/sys/sleepqueue.h>
#define ticks_to_msecs(t) (1000 * (t) / hz) #define ticks_to_msecs(t) (1000 * (t) / hz)
int int
+4 -4
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.
* *
@@ -16,9 +16,9 @@
#include <compat/sys/haiku-module.h> #include <compat/sys/haiku-module.h>
#define TQ_FLAGS_ACTIVE (1 << 0) #define TQ_FLAGS_ACTIVE (1 << 0)
#define TQ_FLAGS_BLOCKED (1 << 1) #define TQ_FLAGS_BLOCKED (1 << 1)
#define TQ_FLAGS_PENDING (1 << 2) #define TQ_FLAGS_PENDING (1 << 2)
struct taskqueue { struct taskqueue {
+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.
*/ */
+16 -13
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,12 +19,13 @@ 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;
KASSERT(low <= high, 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); idStore = malloc(sizeof *idStore);
if (idStore == NULL) if (idStore == NULL)
@@ -47,14 +48,15 @@ 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__));
mtx_lock(idStore->storeMutex); mtx_lock(idStore->storeMutex);
KASSERT(uh->idBuffer->root_size == 0, 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); _delete_unrhdr_buffer_locked(idStore);
mtx_unlock(idStore->storeMutex); mtx_unlock(idStore->storeMutex);
@@ -65,11 +67,12 @@ 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,
("ID-Store: %s: NULL pointer as argument.", __func__)); ("ID-Store: %s: NULL pointer as argument.", __func__));
mtx_lock(idStore->storeMutex); mtx_lock(idStore->storeMutex);
id = _alloc_unr_locked(idStore); id = _alloc_unr_locked(idStore);
@@ -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