* 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::ValueType ValueType;
|
||||
|
||||
MultiHashTable(size_t initialSize = HashTable::kMinimumSize)
|
||||
: HashTable(initialSize) {}
|
||||
MultiHashTable()
|
||||
: HashTable() {}
|
||||
|
||||
MultiHashTable(const Definition& definition,
|
||||
size_t initialSize = HashTable::kMinimumSize)
|
||||
: HashTable(definition, initialSize) {}
|
||||
MultiHashTable(const Definition& definition)
|
||||
: HashTable(definition) {}
|
||||
|
||||
status_t InitCheck() const { return HashTable::InitCheck(); }
|
||||
status_t Init(size_t initialSize = HashTable::kMinimumSize)
|
||||
{
|
||||
return HashTable::Init(initialSize);
|
||||
}
|
||||
|
||||
void Insert(ValueType *value)
|
||||
{
|
||||
@ -103,9 +105,13 @@ public:
|
||||
|
||||
ValueIterator Lookup(const KeyType &key) const
|
||||
{
|
||||
size_t index = HashTable::fDefinition.HashKey(key)
|
||||
& (HashTable::fTableSize - 1);
|
||||
ValueType *slot = HashTable::fTable[index];
|
||||
size_t index = 0;
|
||||
ValueType *slot = NULL;
|
||||
if (HashTable::fTableSize > 0) {
|
||||
index = HashTable::fDefinition.HashKey(key)
|
||||
& (HashTable::fTableSize - 1);
|
||||
slot = HashTable::fTable[index];
|
||||
}
|
||||
|
||||
while (slot) {
|
||||
if (HashTable::fDefinition.Compare(key, slot))
|
||||
|
@ -59,26 +59,21 @@ public:
|
||||
// regrowth factor: 200 / 256 = 78.125%
|
||||
// 50 / 256 = 19.53125%
|
||||
|
||||
OpenHashTable(size_t initialSize = kMinimumSize)
|
||||
OpenHashTable()
|
||||
:
|
||||
fTableSize(0),
|
||||
fItemCount(0),
|
||||
fTable(NULL)
|
||||
{
|
||||
if (initialSize > 0)
|
||||
_Resize(initialSize);
|
||||
}
|
||||
|
||||
OpenHashTable(const Definition& definition,
|
||||
size_t initialSize = kMinimumSize)
|
||||
OpenHashTable(const Definition& definition)
|
||||
:
|
||||
fDefinition(definition),
|
||||
fTableSize(0),
|
||||
fItemCount(0),
|
||||
fTable(NULL)
|
||||
{
|
||||
if (initialSize > 0)
|
||||
_Resize(initialSize);
|
||||
}
|
||||
|
||||
~OpenHashTable()
|
||||
@ -86,9 +81,11 @@ public:
|
||||
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
|
||||
|
@ -1596,7 +1596,7 @@ init_ipv4()
|
||||
goto err4;
|
||||
}
|
||||
|
||||
status = sMulticastState->InitCheck();
|
||||
status = sMulticastState->Init();
|
||||
if (status < B_OK)
|
||||
goto err5;
|
||||
|
||||
|
@ -142,7 +142,7 @@ MulticastGroupInterface<Addressing>::FilterAccepts(net_buffer *buffer) const
|
||||
|
||||
template<typename Addressing>
|
||||
MulticastFilter<Addressing>::MulticastFilter(ProtocolType *socket)
|
||||
: fParent(socket), fStates((size_t)0)
|
||||
: fParent(socket), fStates()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -232,11 +232,11 @@ EndpointManager::~EndpointManager()
|
||||
|
||||
|
||||
status_t
|
||||
EndpointManager::InitCheck() const
|
||||
EndpointManager::Init()
|
||||
{
|
||||
status_t status = fConnectionHash.InitCheck();
|
||||
status_t status = fConnectionHash.Init();
|
||||
if (status == B_OK)
|
||||
status = fEndpointHash.InitCheck();
|
||||
status = fEndpointHash.Init();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
EndpointManager(net_domain* domain);
|
||||
~EndpointManager();
|
||||
|
||||
status_t InitCheck() const;
|
||||
status_t Init();
|
||||
|
||||
TCPEndpoint* FindConnection(sockaddr* local, sockaddr* peer);
|
||||
|
||||
|
@ -286,9 +286,15 @@ get_endpoint_manager(net_domain* domain)
|
||||
return endpointManager;
|
||||
|
||||
endpointManager = new (std::nothrow) EndpointManager(domain);
|
||||
if (endpointManager)
|
||||
sEndpointManagers.Add(endpointManager);
|
||||
if (endpointManager == NULL)
|
||||
return NULL;
|
||||
|
||||
if (endpointManager->Init() != B_OK) {
|
||||
delete endpointManager;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sEndpointManagers.Add(endpointManager);
|
||||
return endpointManager;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ public:
|
||||
UdpDomainSupport(net_domain *domain);
|
||||
~UdpDomainSupport();
|
||||
|
||||
status_t InitCheck() const;
|
||||
status_t Init();
|
||||
|
||||
net_domain *Domain() const { return fDomain; }
|
||||
|
||||
@ -245,7 +245,7 @@ net_stack_module_info *gStackModule;
|
||||
UdpDomainSupport::UdpDomainSupport(net_domain *domain)
|
||||
:
|
||||
fDomain(domain),
|
||||
fActiveEndpoints(domain->address_module, kNumHashBuckets),
|
||||
fActiveEndpoints(domain->address_module),
|
||||
fEndpointCount(0)
|
||||
{
|
||||
mutex_init(&fLock, "udp domain");
|
||||
@ -261,9 +261,9 @@ UdpDomainSupport::~UdpDomainSupport()
|
||||
|
||||
|
||||
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 =
|
||||
new (std::nothrow) UdpDomainSupport(domain);
|
||||
if (domainSupport == NULL || domainSupport->InitCheck() < B_OK) {
|
||||
if (domainSupport == NULL || domainSupport->Init() < B_OK) {
|
||||
delete domainSupport;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -52,11 +52,7 @@ public:
|
||||
|
||||
status_t Init()
|
||||
{
|
||||
status_t error = fBoundEndpoints.InitCheck();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return B_OK;
|
||||
return fBoundEndpoints.Init();
|
||||
}
|
||||
|
||||
bool Lock()
|
||||
|
@ -156,7 +156,7 @@ NotificationManager::_Init()
|
||||
{
|
||||
mutex_init(&fLock, "notification manager");
|
||||
|
||||
return fServiceHash.InitCheck();
|
||||
return fServiceHash.Init();
|
||||
}
|
||||
|
||||
|
||||
|
@ -327,10 +327,9 @@ ConditionVariable::_NotifyChecked(bool all, status_t result)
|
||||
void
|
||||
condition_variable_init()
|
||||
{
|
||||
new(&sConditionVariableHash) ConditionVariableHash(
|
||||
kConditionVariableHashSize);
|
||||
new(&sConditionVariableHash) ConditionVariableHash;
|
||||
|
||||
status_t error = sConditionVariableHash.InitCheck();
|
||||
status_t error = sConditionVariableHash.Init(kConditionVariableHashSize);
|
||||
if (error != B_OK) {
|
||||
panic("condition_variable_init(): Failed to init hash table: %s",
|
||||
strerror(error));
|
||||
|
@ -316,10 +316,10 @@ public:
|
||||
|
||||
status_t Init()
|
||||
{
|
||||
status_t error = fNamedSemaphores.InitCheck();
|
||||
status_t error = fNamedSemaphores.Init();
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
return fUnnamedSemaphores.InitCheck();
|
||||
return fUnnamedSemaphores.Init();
|
||||
}
|
||||
|
||||
status_t OpenNamedSem(const char* name, int openFlags, mode_t mode,
|
||||
@ -569,7 +569,7 @@ struct realtime_sem_context {
|
||||
status_t Init()
|
||||
{
|
||||
fNextPrivateSemID = -1;
|
||||
return fSemaphores.InitCheck();
|
||||
return fSemaphores.Init();
|
||||
}
|
||||
|
||||
realtime_sem_context* Clone()
|
||||
|
Loading…
Reference in New Issue
Block a user