freebsd11_network: Combine Unit.cpp and unit.c into unit.cpp.
There's a number of these "C++ wrappers for C code" wrappers in the freebsd_network compat layer, and there don't seem to be very many good reasons to use them. We can just as well declare these C++ functions with C linkage so they can be used from C code directly. So, time to start cleaning this up.
This commit is contained in:
@@ -45,8 +45,7 @@ KernelStaticLibrary libfreebsd11_network.a :
|
|||||||
synch.c
|
synch.c
|
||||||
systm.c
|
systm.c
|
||||||
taskqueue.c
|
taskqueue.c
|
||||||
unit.c
|
unit.cpp
|
||||||
Unit.cpp
|
|
||||||
;
|
;
|
||||||
|
|
||||||
rule MIIHeaderGen
|
rule MIIHeaderGen
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 Colin Günther, [email protected]
|
|
||||||
* All Rights Reserved. Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*! Wrapper functions for accessing the number buffer.*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "unit.h"
|
|
||||||
|
|
||||||
#include <util/RadixBitmap.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define ID_STORE_FULL -1
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
_new_unrhdr_buffer(struct unrhdr* idStore, uint32 maxIdCount)
|
|
||||||
{
|
|
||||||
status_t status = B_OK;
|
|
||||||
|
|
||||||
idStore->idBuffer = radix_bitmap_create(maxIdCount);
|
|
||||||
if (idStore->idBuffer == NULL)
|
|
||||||
status = B_NO_MEMORY;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
_delete_unrhdr_buffer_locked(struct unrhdr* idStore)
|
|
||||||
{
|
|
||||||
radix_bitmap_destroy(idStore->idBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
_alloc_unr_locked(struct unrhdr* idStore)
|
|
||||||
{
|
|
||||||
radix_slot_t slotIndex;
|
|
||||||
int id = ID_STORE_FULL;
|
|
||||||
|
|
||||||
slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1);
|
|
||||||
if (slotIndex != RADIX_SLOT_NONE)
|
|
||||||
id = slotIndex + idStore->idBias;
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
_free_unr_locked(struct unrhdr* idStore, u_int identity)
|
|
||||||
{
|
|
||||||
uint32 slotIndex = (int32)identity - idStore->idBias;
|
|
||||||
|
|
||||||
radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1);
|
|
||||||
}
|
|
||||||
+22
-8
@@ -1,14 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* 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.
|
* Copyright 2018, Haiku, Inc.
|
||||||
*
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*! Implementation of a number allocator.*/
|
/*! Implementation of a number allocator.*/
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
}
|
||||||
|
|
||||||
#include <compat/sys/mutex.h>
|
#include <compat/sys/mutex.h>
|
||||||
|
|
||||||
@@ -16,6 +18,9 @@
|
|||||||
#include <util/RadixBitmap.h>
|
#include <util/RadixBitmap.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define ID_STORE_FULL -1
|
||||||
|
|
||||||
|
|
||||||
extern struct mtx gIdStoreLock;
|
extern struct mtx gIdStoreLock;
|
||||||
|
|
||||||
|
|
||||||
@@ -28,11 +33,12 @@ new_unrhdr(int low, int high, struct mtx* mutex)
|
|||||||
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 = (unrhdr*)malloc(sizeof *idStore);
|
||||||
if (idStore == NULL)
|
if (idStore == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_new_unrhdr_buffer(idStore, maxIdCount) != B_OK) {
|
idStore->idBuffer = radix_bitmap_create(maxIdCount);
|
||||||
|
if (idStore->idBuffer == NULL) {
|
||||||
free(idStore);
|
free(idStore);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,7 @@ delete_unrhdr(struct unrhdr* idStore)
|
|||||||
KASSERT(idStore->idBuffer->root_size == 0,
|
KASSERT(idStore->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);
|
radix_bitmap_destroy(idStore->idBuffer);
|
||||||
mtx_unlock(idStore->storeMutex);
|
mtx_unlock(idStore->storeMutex);
|
||||||
|
|
||||||
free(idStore);
|
free(idStore);
|
||||||
@@ -76,7 +82,14 @@ alloc_unr(struct unrhdr* idStore)
|
|||||||
("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);
|
|
||||||
|
radix_slot_t slotIndex;
|
||||||
|
id = ID_STORE_FULL;
|
||||||
|
|
||||||
|
slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1);
|
||||||
|
if (slotIndex != RADIX_SLOT_NONE)
|
||||||
|
id = slotIndex + idStore->idBias;
|
||||||
|
|
||||||
mtx_unlock(idStore->storeMutex);
|
mtx_unlock(idStore->storeMutex);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
@@ -91,10 +104,11 @@ free_unr(struct unrhdr* idStore, u_int identity)
|
|||||||
|
|
||||||
mtx_lock(idStore->storeMutex);
|
mtx_lock(idStore->storeMutex);
|
||||||
|
|
||||||
KASSERT((int32)identity - idStore->idBias >= 0, ("ID-Store: %s(%p, %u): second "
|
uint32 slotIndex = (int32)identity - idStore->idBias;
|
||||||
|
KASSERT(slotIndex >= 0, ("ID-Store: %s(%p, %u): second "
|
||||||
"parameter is not in interval.", __func__, idStore, identity));
|
"parameter is not in interval.", __func__, idStore, identity));
|
||||||
|
|
||||||
_free_unr_locked(idStore, identity);
|
radix_bitmap_dealloc(idStore->idBuffer, slotIndex, 1);
|
||||||
|
|
||||||
mtx_unlock(idStore->storeMutex);
|
mtx_unlock(idStore->storeMutex);
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
#ifndef UNIT_H_
|
#ifndef UNIT_H_
|
||||||
#define UNIT_H_
|
#define UNIT_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <compat/sys/systm.h>
|
#include <compat/sys/systm.h>
|
||||||
|
|
||||||
@@ -17,10 +20,6 @@ struct unrhdr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#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*);
|
||||||
|
|||||||
Reference in New Issue
Block a user