tcp: no longer need recursive locking.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21216 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -190,7 +190,7 @@ WaitList::InitCheck() const
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
WaitList::Wait(RecursiveLocker &locker, bigtime_t timeout, bool wakeNext)
|
WaitList::Wait(MutexLocker &locker, bigtime_t timeout, bool wakeNext)
|
||||||
{
|
{
|
||||||
locker.Unlock();
|
locker.Unlock();
|
||||||
|
|
||||||
@@ -252,8 +252,8 @@ TCPEndpoint::TCPEndpoint(net_socket *socket)
|
|||||||
{
|
{
|
||||||
//gStackModule->init_timer(&fTimer, _TimeWait, this);
|
//gStackModule->init_timer(&fTimer, _TimeWait, this);
|
||||||
|
|
||||||
recursive_lock_init(&fLock, "tcp lock");
|
// TODO: to be replaced with a real locking strategy!
|
||||||
// TODO: to be replaced with a real locking strategy!
|
mutex_init(&fLock, "tcp lock");
|
||||||
|
|
||||||
gStackModule->init_timer(&fPersistTimer, TCPEndpoint::_PersistTimer, this);
|
gStackModule->init_timer(&fPersistTimer, TCPEndpoint::_PersistTimer, this);
|
||||||
gStackModule->init_timer(&fRetransmitTimer, TCPEndpoint::_RetransmitTimer, this);
|
gStackModule->init_timer(&fRetransmitTimer, TCPEndpoint::_RetransmitTimer, this);
|
||||||
@@ -265,7 +265,7 @@ TCPEndpoint::TCPEndpoint(net_socket *socket)
|
|||||||
|
|
||||||
TCPEndpoint::~TCPEndpoint()
|
TCPEndpoint::~TCPEndpoint()
|
||||||
{
|
{
|
||||||
recursive_lock_lock(&fLock);
|
mutex_lock(&fLock);
|
||||||
|
|
||||||
gStackModule->cancel_timer(&fRetransmitTimer);
|
gStackModule->cancel_timer(&fRetransmitTimer);
|
||||||
gStackModule->cancel_timer(&fPersistTimer);
|
gStackModule->cancel_timer(&fPersistTimer);
|
||||||
@@ -277,7 +277,7 @@ TCPEndpoint::~TCPEndpoint()
|
|||||||
return_endpoint_manager(fManager);
|
return_endpoint_manager(fManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
recursive_lock_destroy(&fLock);
|
mutex_destroy(&fLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ TCPEndpoint::Close()
|
|||||||
{
|
{
|
||||||
TRACE("Close()");
|
TRACE("Close()");
|
||||||
|
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
|
|
||||||
if (fState == LISTEN)
|
if (fState == LISTEN)
|
||||||
delete_sem(fAcceptSemaphore);
|
delete_sem(fAcceptSemaphore);
|
||||||
@@ -363,7 +363,7 @@ TCPEndpoint::Free()
|
|||||||
{
|
{
|
||||||
TRACE("Free()");
|
TRACE("Free()");
|
||||||
|
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
|
|
||||||
if (fState <= SYNCHRONIZE_SENT || fState == TIME_WAIT)
|
if (fState <= SYNCHRONIZE_SENT || fState == TIME_WAIT)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -384,7 +384,7 @@ TCPEndpoint::Connect(const sockaddr *address)
|
|||||||
{
|
{
|
||||||
TRACE("Connect() on address %s", PrintAddress(address));
|
TRACE("Connect() on address %s", PrintAddress(address));
|
||||||
|
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
// Can only call connect() from CLOSED or LISTEN states
|
// Can only call connect() from CLOSED or LISTEN states
|
||||||
// otherwise endpoint is considered already connected
|
// otherwise endpoint is considered already connected
|
||||||
@@ -436,7 +436,7 @@ TCPEndpoint::Accept(struct net_socket **_acceptedSocket)
|
|||||||
{
|
{
|
||||||
TRACE("Accept()");
|
TRACE("Accept()");
|
||||||
|
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
status_t status;
|
status_t status;
|
||||||
bigtime_t timeout = absolute_timeout(socket->receive.timeout);
|
bigtime_t timeout = absolute_timeout(socket->receive.timeout);
|
||||||
@@ -465,7 +465,7 @@ TCPEndpoint::Bind(const sockaddr *address)
|
|||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
|
|
||||||
TRACE("Bind() on address %s", PrintAddress(address));
|
TRACE("Bind() on address %s", PrintAddress(address));
|
||||||
|
|
||||||
@@ -481,7 +481,7 @@ TCPEndpoint::Unbind(struct sockaddr *address)
|
|||||||
{
|
{
|
||||||
TRACE("Unbind()");
|
TRACE("Unbind()");
|
||||||
|
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
return fManager->Unbind(this);
|
return fManager->Unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,7 +491,7 @@ TCPEndpoint::Listen(int count)
|
|||||||
{
|
{
|
||||||
TRACE("Listen()");
|
TRACE("Listen()");
|
||||||
|
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
|
|
||||||
if (fState != CLOSED)
|
if (fState != CLOSED)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -517,7 +517,7 @@ TCPEndpoint::Shutdown(int direction)
|
|||||||
{
|
{
|
||||||
TRACE("Shutdown(%i)", direction);
|
TRACE("Shutdown(%i)", direction);
|
||||||
|
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
|
|
||||||
if (direction == SHUT_RD || direction == SHUT_RDWR)
|
if (direction == SHUT_RD || direction == SHUT_RDWR)
|
||||||
fFlags |= FLAG_NO_RECEIVE;
|
fFlags |= FLAG_NO_RECEIVE;
|
||||||
@@ -535,7 +535,7 @@ TCPEndpoint::Shutdown(int direction)
|
|||||||
status_t
|
status_t
|
||||||
TCPEndpoint::SendData(net_buffer *buffer)
|
TCPEndpoint::SendData(net_buffer *buffer)
|
||||||
{
|
{
|
||||||
RecursiveLocker lock(fLock);
|
MutexLocker lock(fLock);
|
||||||
|
|
||||||
TRACE("SendData(buffer %p, size %lu, flags %lx) [total %lu bytes, has %lu]",
|
TRACE("SendData(buffer %p, size %lu, flags %lx) [total %lu bytes, has %lu]",
|
||||||
buffer, buffer->size, buffer->flags, fSendQueue.Size(),
|
buffer, buffer->size, buffer->flags, fSendQueue.Size(),
|
||||||
@@ -582,7 +582,7 @@ TCPEndpoint::SendData(net_buffer *buffer)
|
|||||||
ssize_t
|
ssize_t
|
||||||
TCPEndpoint::SendAvailable()
|
TCPEndpoint::SendAvailable()
|
||||||
{
|
{
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
ssize_t available;
|
ssize_t available;
|
||||||
|
|
||||||
@@ -599,7 +599,7 @@ TCPEndpoint::SendAvailable()
|
|||||||
status_t
|
status_t
|
||||||
TCPEndpoint::FillStat(net_stat *stat)
|
TCPEndpoint::FillStat(net_stat *stat)
|
||||||
{
|
{
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
|
|
||||||
strlcpy(stat->state, name_for_state(fState), sizeof(stat->state));
|
strlcpy(stat->state, name_for_state(fState), sizeof(stat->state));
|
||||||
stat->receive_queue_size = fReceiveQueue.Available();
|
stat->receive_queue_size = fReceiveQueue.Available();
|
||||||
@@ -614,7 +614,7 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
|
|||||||
{
|
{
|
||||||
TRACE("ReadData(%lu bytes, flags 0x%x)", numBytes, (unsigned int)flags);
|
TRACE("ReadData(%lu bytes, flags 0x%x)", numBytes, (unsigned int)flags);
|
||||||
|
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
*_buffer = NULL;
|
*_buffer = NULL;
|
||||||
|
|
||||||
@@ -698,7 +698,7 @@ TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
|
|||||||
ssize_t
|
ssize_t
|
||||||
TCPEndpoint::ReadAvailable()
|
TCPEndpoint::ReadAvailable()
|
||||||
{
|
{
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
TRACE("ReadAvailable(): %li", _AvailableData());
|
TRACE("ReadAvailable(): %li", _AvailableData());
|
||||||
|
|
||||||
@@ -709,7 +709,7 @@ TCPEndpoint::ReadAvailable()
|
|||||||
status_t
|
status_t
|
||||||
TCPEndpoint::SetSendBufferSize(size_t length)
|
TCPEndpoint::SetSendBufferSize(size_t length)
|
||||||
{
|
{
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
fSendQueue.SetMaxBytes(length);
|
fSendQueue.SetMaxBytes(length);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -718,7 +718,7 @@ TCPEndpoint::SetSendBufferSize(size_t length)
|
|||||||
status_t
|
status_t
|
||||||
TCPEndpoint::SetReceiveBufferSize(size_t length)
|
TCPEndpoint::SetReceiveBufferSize(size_t length)
|
||||||
{
|
{
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
fReceiveQueue.SetMaxBytes(length);
|
fReceiveQueue.SetMaxBytes(length);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -735,7 +735,7 @@ TCPEndpoint::SetOption(int option, const void *_value, int length)
|
|||||||
|
|
||||||
const int *value = (const int *)_value;
|
const int *value = (const int *)_value;
|
||||||
|
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
if (*value)
|
if (*value)
|
||||||
fOptions |= TCP_NODELAY;
|
fOptions |= TCP_NODELAY;
|
||||||
else
|
else
|
||||||
@@ -844,7 +844,7 @@ int32
|
|||||||
TCPEndpoint::Spawn(TCPEndpoint *parent, tcp_segment_header &segment,
|
TCPEndpoint::Spawn(TCPEndpoint *parent, tcp_segment_header &segment,
|
||||||
net_buffer *buffer)
|
net_buffer *buffer)
|
||||||
{
|
{
|
||||||
RecursiveLocker _(fLock);
|
MutexLocker _(fLock);
|
||||||
|
|
||||||
// TODO error checking
|
// TODO error checking
|
||||||
ProtocolSocket::Open();
|
ProtocolSocket::Open();
|
||||||
@@ -883,8 +883,7 @@ TCPEndpoint::Spawn(TCPEndpoint *parent, tcp_segment_header &segment,
|
|||||||
void
|
void
|
||||||
TCPEndpoint::DumpInternalState() const
|
TCPEndpoint::DumpInternalState() const
|
||||||
{
|
{
|
||||||
kprintf("Lock: { sem: %ld, holder: %ld, recursion: %i }\n",
|
kprintf("Lock: { sem: %ld, holder: %ld }\n", fLock.sem, fLock.holder);
|
||||||
fLock.sem, fLock.holder, fLock.recursion);
|
|
||||||
kprintf("AcceptSem: %ld\n", fAcceptSemaphore);
|
kprintf("AcceptSem: %ld\n", fAcceptSemaphore);
|
||||||
kprintf("Options: 0x%lx\n", (uint32)fOptions);
|
kprintf("Options: 0x%lx\n", (uint32)fOptions);
|
||||||
kprintf("SendWindowShift: %lu\n", (uint32)fSendWindowShift);
|
kprintf("SendWindowShift: %lu\n", (uint32)fSendWindowShift);
|
||||||
@@ -955,7 +954,7 @@ TCPEndpoint::_SynchronizeSentReceive(tcp_segment_header &segment, net_buffer *bu
|
|||||||
int32
|
int32
|
||||||
TCPEndpoint::SegmentReceived(tcp_segment_header &segment, net_buffer *buffer)
|
TCPEndpoint::SegmentReceived(tcp_segment_header &segment, net_buffer *buffer)
|
||||||
{
|
{
|
||||||
RecursiveLocker locker(fLock);
|
MutexLocker locker(fLock);
|
||||||
|
|
||||||
TRACE("SegmentReceived(): buffer %p (%lu bytes) address %s to %s",
|
TRACE("SegmentReceived(): buffer %p (%lu bytes) address %s to %s",
|
||||||
buffer, buffer->size, PrintAddress(buffer->source),
|
buffer, buffer->size, PrintAddress(buffer->source),
|
||||||
@@ -1628,7 +1627,7 @@ TCPEndpoint::_MarkEstablished()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
TCPEndpoint::_WaitForEstablished(RecursiveLocker &locker, bigtime_t timeout)
|
TCPEndpoint::_WaitForEstablished(MutexLocker &locker, bigtime_t timeout)
|
||||||
{
|
{
|
||||||
while (fState != ESTABLISHED) {
|
while (fState != ESTABLISHED) {
|
||||||
status_t status = fSendList.Wait(locker, timeout);
|
status_t status = fSendList.Wait(locker, timeout);
|
||||||
@@ -1843,7 +1842,7 @@ TCPEndpoint::_RetransmitTimer(net_timer *timer, void *data)
|
|||||||
{
|
{
|
||||||
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
||||||
|
|
||||||
RecursiveLocker locker(endpoint->fLock);
|
MutexLocker locker(endpoint->fLock);
|
||||||
if (!locker.IsLocked())
|
if (!locker.IsLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1856,7 +1855,7 @@ TCPEndpoint::_PersistTimer(net_timer *timer, void *data)
|
|||||||
{
|
{
|
||||||
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
||||||
|
|
||||||
RecursiveLocker locker(endpoint->fLock);
|
MutexLocker locker(endpoint->fLock);
|
||||||
if (!locker.IsLocked())
|
if (!locker.IsLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1869,7 +1868,7 @@ TCPEndpoint::_DelayedAcknowledgeTimer(struct net_timer *timer, void *data)
|
|||||||
{
|
{
|
||||||
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
||||||
|
|
||||||
RecursiveLocker locker(endpoint->fLock);
|
MutexLocker locker(endpoint->fLock);
|
||||||
if (!locker.IsLocked())
|
if (!locker.IsLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1882,7 +1881,7 @@ TCPEndpoint::_TimeWaitTimer(struct net_timer *timer, void *data)
|
|||||||
{
|
{
|
||||||
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
TCPEndpoint *endpoint = (TCPEndpoint *)data;
|
||||||
|
|
||||||
if (recursive_lock_lock(&endpoint->fLock) < B_OK)
|
if (mutex_lock(&endpoint->fLock) < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
endpoint->DeleteSocket();
|
endpoint->DeleteSocket();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
status_t Wait(RecursiveLocker &, bigtime_t timeout, bool wakeNext = true);
|
status_t Wait(MutexLocker &, bigtime_t timeout, bool wakeNext = true);
|
||||||
void Signal();
|
void Signal();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -107,7 +107,7 @@ class TCPEndpoint : public net_protocol, public ProtocolSocket {
|
|||||||
void _UpdateTimestamps(tcp_segment_header& segment,
|
void _UpdateTimestamps(tcp_segment_header& segment,
|
||||||
size_t segmentLength);
|
size_t segmentLength);
|
||||||
void _MarkEstablished();
|
void _MarkEstablished();
|
||||||
status_t _WaitForEstablished(RecursiveLocker &lock, bigtime_t timeout);
|
status_t _WaitForEstablished(MutexLocker &lock, bigtime_t timeout);
|
||||||
void _AddData(tcp_segment_header &segment, net_buffer *buffer);
|
void _AddData(tcp_segment_header &segment, net_buffer *buffer);
|
||||||
void _PrepareReceivePath(tcp_segment_header &segment);
|
void _PrepareReceivePath(tcp_segment_header &segment);
|
||||||
status_t _PrepareSendPath(const sockaddr *peer);
|
status_t _PrepareSendPath(const sockaddr *peer);
|
||||||
@@ -130,7 +130,7 @@ class TCPEndpoint : public net_protocol, public ProtocolSocket {
|
|||||||
friend class ConnectionHashDefinition;
|
friend class ConnectionHashDefinition;
|
||||||
friend class EndpointHashDefinition;
|
friend class EndpointHashDefinition;
|
||||||
|
|
||||||
recursive_lock fLock;
|
mutex fLock;
|
||||||
WaitList fReceiveList;
|
WaitList fReceiveList;
|
||||||
WaitList fSendList;
|
WaitList fSendList;
|
||||||
sem_id fAcceptSemaphore;
|
sem_id fAcceptSemaphore;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ net_stack_module_info *gStackModule;
|
|||||||
// protocol cookie, so we don't have to go through the list
|
// protocol cookie, so we don't have to go through the list
|
||||||
// for each segment.
|
// for each segment.
|
||||||
typedef DoublyLinkedList<EndpointManager> EndpointManagerList;
|
typedef DoublyLinkedList<EndpointManager> EndpointManagerList;
|
||||||
static recursive_lock sEndpointManagersLock;
|
static mutex sEndpointManagersLock;
|
||||||
static EndpointManagerList sEndpointManagers;
|
static EndpointManagerList sEndpointManagers;
|
||||||
|
|
||||||
|
|
||||||
@@ -633,7 +633,7 @@ tcp_receive_data(net_buffer *buffer)
|
|||||||
bufferHeader.Remove(headerLength);
|
bufferHeader.Remove(headerLength);
|
||||||
// we no longer need to keep the header around
|
// we no longer need to keep the header around
|
||||||
|
|
||||||
RecursiveLocker _(sEndpointManagersLock);
|
MutexLocker _(sEndpointManagersLock);
|
||||||
|
|
||||||
EndpointManager *endpointManager = endpoint_manager_for(domain);
|
EndpointManager *endpointManager = endpoint_manager_for(domain);
|
||||||
if (endpointManager == NULL)
|
if (endpointManager == NULL)
|
||||||
@@ -707,7 +707,7 @@ dump_endpoint(int argc, char *argv[])
|
|||||||
static status_t
|
static status_t
|
||||||
tcp_init()
|
tcp_init()
|
||||||
{
|
{
|
||||||
status_t status = recursive_lock_init(&sEndpointManagersLock,
|
status_t status = mutex_init(&sEndpointManagersLock,
|
||||||
"endpoint managers lock");
|
"endpoint managers lock");
|
||||||
|
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@@ -746,7 +746,7 @@ tcp_uninit()
|
|||||||
{
|
{
|
||||||
remove_debugger_command("tcp_endpoint", dump_endpoint);
|
remove_debugger_command("tcp_endpoint", dump_endpoint);
|
||||||
remove_debugger_command("tcp_endpoints", dump_endpoints);
|
remove_debugger_command("tcp_endpoints", dump_endpoints);
|
||||||
recursive_lock_destroy(&sEndpointManagersLock);
|
mutex_destroy(&sEndpointManagersLock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user