[haiku-commits] r33785 - haiku/trunk/src/libs/compat/freebsd_network

  • From: coling@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 27 Oct 2009 09:14:03 +0100 (CET)

Author: colin
Date: 2009-10-27 09:14:03 +0100 (Tue, 27 Oct 2009)
New Revision: 33785
Changeset: http://dev.haiku-os.org/changeset/33785/haiku

Modified:
   haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp
   haiku/trunk/src/libs/compat/freebsd_network/Unit.cpp
   haiku/trunk/src/libs/compat/freebsd_network/clock.c
   haiku/trunk/src/libs/compat/freebsd_network/condvar.c
   haiku/trunk/src/libs/compat/freebsd_network/condvar.h
   haiku/trunk/src/libs/compat/freebsd_network/device.h
   haiku/trunk/src/libs/compat/freebsd_network/driver.c
   haiku/trunk/src/libs/compat/freebsd_network/sleepqueue.c
   haiku/trunk/src/libs/compat/freebsd_network/synch.c
   haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c
   haiku/trunk/src/libs/compat/freebsd_network/timeout.c
   haiku/trunk/src/libs/compat/freebsd_network/unit.c
   haiku/trunk/src/libs/compat/freebsd_network/unit.h
Log:
* 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.


Modified: haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp     2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/Condvar.cpp     2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * All Rights Reserved. Distributed under the terms of the MIT License.
  */
 
@@ -29,7 +29,7 @@
 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 @@
 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);
 }
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/Unit.cpp
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/Unit.cpp        2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/Unit.cpp        2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * 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 @@
 
 
 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 @@
 
 
 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);

Modified: haiku/trunk/src/libs/compat/freebsd_network/clock.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/clock.c 2009-10-27 05:36:14 UTC 
(rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/clock.c 2009-10-27 08:14:03 UTC 
(rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009, Colin Günther, coling@xxxxxx
  * 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);
 
-// TODO use the hardclock function in the compat layer actually.
+               if (system_time() >= timeout) {
+                       atomic_add((vint32*)&ticks, 1);
+               }
+       } while (status != B_BAD_SEM_ID);
+
+       return status;
+}
+
+
 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;
+       }
 
-void
-uninit_clock()
-{
-       gStack->cancel_timer(&hardclockTimer);
+       return resume_thread(sHardClockThread);
+
+error2:
+       delete_sem(sHardClockSem);
+error1:
+       return status;
 }
 
 
 void
-hardclock(struct net_timer* timer, void* argument)
+uninit_hard_clock()
 {
-       atomic_add((vint32*)&ticks, 1);
-       gStack->set_timer(&hardclockTimer, hz);
+       status_t status;
+
+       delete_sem(sHardClockSem);
+       wait_for_thread(sHardClockThread, &status);
 }

Modified: haiku/trunk/src/libs/compat/freebsd_network/condvar.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/condvar.c       2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/condvar.c       2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxxx
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/condvar.h
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/condvar.h       2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/condvar.h       2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * All Rights Reserved. Distributed under the terms of the MIT License.
  */
 #ifndef CONDVAR_H_
@@ -12,7 +12,7 @@
 
 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

Modified: haiku/trunk/src/libs/compat/freebsd_network/device.h
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/device.h        2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/device.h        2009-10-27 
08:14:03 UTC (rev 33785)
@@ -67,8 +67,8 @@
 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);
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/driver.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/driver.c        2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/driver.c        2009-10-27 
08:14:03 UTC (rev 33785)
@@ -149,29 +149,33 @@
        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 @@
 
        uninit_wlan_stack();
 
-err5:
+err6:
        if (HAIKU_DRIVER_REQUIRES(FBSD_TASKQUEUES))
                uninit_taskqueues();
+err5:
+       uninit_condition_variables();
 err4:
-       uninit_condition_variables();
+       uninit_mbufs();
 err3:
-       uninit_mbufs();
+       uninit_mutexes();
 err2:
-       uninit_mutexes();
+       uninit_hard_clock();
 err1:
        put_module(B_PCI_MODULE_NAME);
        return status;

Modified: haiku/trunk/src/libs/compat/freebsd_network/sleepqueue.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/sleepqueue.c    2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/sleepqueue.c    2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * All rights reserved. Distributed under the terms of the MIT License.
  */
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/synch.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/synch.c 2009-10-27 05:36:14 UTC 
(rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/synch.c 2009-10-27 08:14:03 UTC 
(rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * 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

Modified: haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c     2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/taskqueue.c     2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009, Colin Günther, coling@xxxxxx
  * 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 {

Modified: haiku/trunk/src/libs/compat/freebsd_network/timeout.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/timeout.c       2009-10-27 
05:36:14 UTC (rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/timeout.c       2009-10-27 
08:14:03 UTC (rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009, Colin Günther, coling@xxxxxx
  * Copyright 2007, Hugo Santos. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  */

Modified: haiku/trunk/src/libs/compat/freebsd_network/unit.c
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/unit.c  2009-10-27 05:36:14 UTC 
(rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/unit.c  2009-10-27 08:14:03 UTC 
(rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * All Rights Reserved. Distributed under the terms of the MIT License.
  *
  */
@@ -19,12 +19,13 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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 @@
 
 
 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);
 

Modified: haiku/trunk/src/libs/compat/freebsd_network/unit.h
===================================================================
--- haiku/trunk/src/libs/compat/freebsd_network/unit.h  2009-10-27 05:36:14 UTC 
(rev 33784)
+++ haiku/trunk/src/libs/compat/freebsd_network/unit.h  2009-10-27 08:14:03 UTC 
(rev 33785)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009, Colin Günther, coling@xxxxxx
+ * Copyright 2009 Colin Günther, coling@xxxxxx
  * All Rights Reserved. Distributed under the terms of the MIT License.
  */
 #ifndef UNIT_H_
@@ -21,13 +21,11 @@
 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


Other related posts: