* Replaced the useless InitCheck() method in {Open,Multi}HashTable (it
always returned B_OK) by a Init() method, which sets the initial size and returns an error, if that fails. * Adjusted code using the classes accordingly. Replaced a few InitCheck() methods in the network code by Init(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26127 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
55c692b304
commit
276aa463ef
@ -31,14 +31,16 @@ public:
|
|||||||
typedef typename Definition::KeyType KeyType;
|
typedef typename Definition::KeyType KeyType;
|
||||||
typedef typename Definition::ValueType ValueType;
|
typedef typename Definition::ValueType ValueType;
|
||||||
|
|
||||||
MultiHashTable(size_t initialSize = HashTable::kMinimumSize)
|
MultiHashTable()
|
||||||
: HashTable(initialSize) {}
|
: HashTable() {}
|
||||||
|
|
||||||
MultiHashTable(const Definition& definition,
|
MultiHashTable(const Definition& definition)
|
||||||
size_t initialSize = HashTable::kMinimumSize)
|
: HashTable(definition) {}
|
||||||
: HashTable(definition, initialSize) {}
|
|
||||||
|
|
||||||
status_t InitCheck() const { return HashTable::InitCheck(); }
|
status_t Init(size_t initialSize = HashTable::kMinimumSize)
|
||||||
|
{
|
||||||
|
return HashTable::Init(initialSize);
|
||||||
|
}
|
||||||
|
|
||||||
void Insert(ValueType *value)
|
void Insert(ValueType *value)
|
||||||
{
|
{
|
||||||
@ -103,9 +105,13 @@ public:
|
|||||||
|
|
||||||
ValueIterator Lookup(const KeyType &key) const
|
ValueIterator Lookup(const KeyType &key) const
|
||||||
{
|
{
|
||||||
size_t index = HashTable::fDefinition.HashKey(key)
|
size_t index = 0;
|
||||||
|
ValueType *slot = NULL;
|
||||||
|
if (HashTable::fTableSize > 0) {
|
||||||
|
index = HashTable::fDefinition.HashKey(key)
|
||||||
& (HashTable::fTableSize - 1);
|
& (HashTable::fTableSize - 1);
|
||||||
ValueType *slot = HashTable::fTable[index];
|
slot = HashTable::fTable[index];
|
||||||
|
}
|
||||||
|
|
||||||
while (slot) {
|
while (slot) {
|
||||||
if (HashTable::fDefinition.Compare(key, slot))
|
if (HashTable::fDefinition.Compare(key, slot))
|
||||||
|
@ -59,26 +59,21 @@ public:
|
|||||||
// regrowth factor: 200 / 256 = 78.125%
|
// regrowth factor: 200 / 256 = 78.125%
|
||||||
// 50 / 256 = 19.53125%
|
// 50 / 256 = 19.53125%
|
||||||
|
|
||||||
OpenHashTable(size_t initialSize = kMinimumSize)
|
OpenHashTable()
|
||||||
:
|
:
|
||||||
fTableSize(0),
|
fTableSize(0),
|
||||||
fItemCount(0),
|
fItemCount(0),
|
||||||
fTable(NULL)
|
fTable(NULL)
|
||||||
{
|
{
|
||||||
if (initialSize > 0)
|
|
||||||
_Resize(initialSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenHashTable(const Definition& definition,
|
OpenHashTable(const Definition& definition)
|
||||||
size_t initialSize = kMinimumSize)
|
|
||||||
:
|
:
|
||||||
fDefinition(definition),
|
fDefinition(definition),
|
||||||
fTableSize(0),
|
fTableSize(0),
|
||||||
fItemCount(0),
|
fItemCount(0),
|
||||||
fTable(NULL)
|
fTable(NULL)
|
||||||
{
|
{
|
||||||
if (initialSize > 0)
|
|
||||||
_Resize(initialSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~OpenHashTable()
|
~OpenHashTable()
|
||||||
@ -86,9 +81,11 @@ public:
|
|||||||
delete [] fTable;
|
delete [] fTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t InitCheck() const
|
status_t Init(size_t initialSize = kMinimumSize)
|
||||||
{
|
{
|
||||||
return (fTableSize == 0 || fTable) ? B_OK : B_NO_MEMORY;
|
if (initialSize > 0 && !_Resize(initialSize))
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType *Lookup(const KeyType &key) const
|
ValueType *Lookup(const KeyType &key) const
|
||||||
|
@ -1596,7 +1596,7 @@ init_ipv4()
|
|||||||
goto err4;
|
goto err4;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = sMulticastState->InitCheck();
|
status = sMulticastState->Init();
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
goto err5;
|
goto err5;
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ MulticastGroupInterface<Addressing>::FilterAccepts(net_buffer *buffer) const
|
|||||||
|
|
||||||
template<typename Addressing>
|
template<typename Addressing>
|
||||||
MulticastFilter<Addressing>::MulticastFilter(ProtocolType *socket)
|
MulticastFilter<Addressing>::MulticastFilter(ProtocolType *socket)
|
||||||
: fParent(socket), fStates((size_t)0)
|
: fParent(socket), fStates()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,11 +232,11 @@ EndpointManager::~EndpointManager()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
EndpointManager::InitCheck() const
|
EndpointManager::Init()
|
||||||
{
|
{
|
||||||
status_t status = fConnectionHash.InitCheck();
|
status_t status = fConnectionHash.Init();
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = fEndpointHash.InitCheck();
|
status = fEndpointHash.Init();
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
EndpointManager(net_domain* domain);
|
EndpointManager(net_domain* domain);
|
||||||
~EndpointManager();
|
~EndpointManager();
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t Init();
|
||||||
|
|
||||||
TCPEndpoint* FindConnection(sockaddr* local, sockaddr* peer);
|
TCPEndpoint* FindConnection(sockaddr* local, sockaddr* peer);
|
||||||
|
|
||||||
|
@ -286,9 +286,15 @@ get_endpoint_manager(net_domain* domain)
|
|||||||
return endpointManager;
|
return endpointManager;
|
||||||
|
|
||||||
endpointManager = new (std::nothrow) EndpointManager(domain);
|
endpointManager = new (std::nothrow) EndpointManager(domain);
|
||||||
if (endpointManager)
|
if (endpointManager == NULL)
|
||||||
sEndpointManagers.Add(endpointManager);
|
return NULL;
|
||||||
|
|
||||||
|
if (endpointManager->Init() != B_OK) {
|
||||||
|
delete endpointManager;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sEndpointManagers.Add(endpointManager);
|
||||||
return endpointManager;
|
return endpointManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public:
|
|||||||
UdpDomainSupport(net_domain *domain);
|
UdpDomainSupport(net_domain *domain);
|
||||||
~UdpDomainSupport();
|
~UdpDomainSupport();
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t Init();
|
||||||
|
|
||||||
net_domain *Domain() const { return fDomain; }
|
net_domain *Domain() const { return fDomain; }
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ net_stack_module_info *gStackModule;
|
|||||||
UdpDomainSupport::UdpDomainSupport(net_domain *domain)
|
UdpDomainSupport::UdpDomainSupport(net_domain *domain)
|
||||||
:
|
:
|
||||||
fDomain(domain),
|
fDomain(domain),
|
||||||
fActiveEndpoints(domain->address_module, kNumHashBuckets),
|
fActiveEndpoints(domain->address_module),
|
||||||
fEndpointCount(0)
|
fEndpointCount(0)
|
||||||
{
|
{
|
||||||
mutex_init(&fLock, "udp domain");
|
mutex_init(&fLock, "udp domain");
|
||||||
@ -261,9 +261,9 @@ UdpDomainSupport::~UdpDomainSupport()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
UdpDomainSupport::InitCheck() const
|
UdpDomainSupport::Init()
|
||||||
{
|
{
|
||||||
return fActiveEndpoints.InitCheck();
|
return fActiveEndpoints.Init(kNumHashBuckets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -766,7 +766,7 @@ UdpEndpointManager::_GetDomain(net_domain *domain, bool create)
|
|||||||
|
|
||||||
UdpDomainSupport *domainSupport =
|
UdpDomainSupport *domainSupport =
|
||||||
new (std::nothrow) UdpDomainSupport(domain);
|
new (std::nothrow) UdpDomainSupport(domain);
|
||||||
if (domainSupport == NULL || domainSupport->InitCheck() < B_OK) {
|
if (domainSupport == NULL || domainSupport->Init() < B_OK) {
|
||||||
delete domainSupport;
|
delete domainSupport;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,7 @@ public:
|
|||||||
|
|
||||||
status_t Init()
|
status_t Init()
|
||||||
{
|
{
|
||||||
status_t error = fBoundEndpoints.InitCheck();
|
return fBoundEndpoints.Init();
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Lock()
|
bool Lock()
|
||||||
|
@ -156,7 +156,7 @@ NotificationManager::_Init()
|
|||||||
{
|
{
|
||||||
mutex_init(&fLock, "notification manager");
|
mutex_init(&fLock, "notification manager");
|
||||||
|
|
||||||
return fServiceHash.InitCheck();
|
return fServiceHash.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,10 +327,9 @@ ConditionVariable::_NotifyChecked(bool all, status_t result)
|
|||||||
void
|
void
|
||||||
condition_variable_init()
|
condition_variable_init()
|
||||||
{
|
{
|
||||||
new(&sConditionVariableHash) ConditionVariableHash(
|
new(&sConditionVariableHash) ConditionVariableHash;
|
||||||
kConditionVariableHashSize);
|
|
||||||
|
|
||||||
status_t error = sConditionVariableHash.InitCheck();
|
status_t error = sConditionVariableHash.Init(kConditionVariableHashSize);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
panic("condition_variable_init(): Failed to init hash table: %s",
|
panic("condition_variable_init(): Failed to init hash table: %s",
|
||||||
strerror(error));
|
strerror(error));
|
||||||
|
@ -316,10 +316,10 @@ public:
|
|||||||
|
|
||||||
status_t Init()
|
status_t Init()
|
||||||
{
|
{
|
||||||
status_t error = fNamedSemaphores.InitCheck();
|
status_t error = fNamedSemaphores.Init();
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
return fUnnamedSemaphores.InitCheck();
|
return fUnnamedSemaphores.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t OpenNamedSem(const char* name, int openFlags, mode_t mode,
|
status_t OpenNamedSem(const char* name, int openFlags, mode_t mode,
|
||||||
@ -569,7 +569,7 @@ struct realtime_sem_context {
|
|||||||
status_t Init()
|
status_t Init()
|
||||||
{
|
{
|
||||||
fNextPrivateSemID = -1;
|
fNextPrivateSemID = -1;
|
||||||
return fSemaphores.InitCheck();
|
return fSemaphores.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
realtime_sem_context* Clone()
|
realtime_sem_context* Clone()
|
||||||
|
Loading…
Reference in New Issue
Block a user