Skip to content

Commit

Permalink
Revert "Replaced spin locks with mutex"
Browse files Browse the repository at this point in the history
This reverts commit 386e096.
  • Loading branch information
nefarius committed Jan 13, 2021
1 parent ad42e19 commit 6ae5df6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
32 changes: 28 additions & 4 deletions BthPS3/Connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,20 @@ ClientConnections_CreateAndInsert(
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = connectionObject;

ExInitializeFastMutex(&connectionCtx->HidControlChannel.ConnectionStateLock);

status = WdfSpinLockCreate(
&attributes,
&connectionCtx->HidControlChannel.ConnectionStateLock
);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR,
TRACE_CONNECTION,
"WdfSpinLockCreate for HidControlChannel failed with status %!STATUS!",
status
);

goto exitFailure;
}

connectionCtx->HidControlChannel.ConnectionState = ConnectionStateInitialized;

//
Expand Down Expand Up @@ -153,8 +165,20 @@ ClientConnections_CreateAndInsert(
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = connectionObject;

ExInitializeFastMutex(&connectionCtx->HidInterruptChannel.ConnectionStateLock);

status = WdfSpinLockCreate(
&attributes,
&connectionCtx->HidInterruptChannel.ConnectionStateLock
);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR,
TRACE_CONNECTION,
"WdfSpinLockCreate for HidInterruptChannel failed with status %!STATUS!",
status
);

goto exitFailure;
}

connectionCtx->HidInterruptChannel.ConnectionState = ConnectionStateInitialized;

//
Expand Down
2 changes: 1 addition & 1 deletion BthPS3/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct _BTHPS3_CLIENT_L2CAP_CHANNEL
{
BTHPS3_CONNECTION_STATE ConnectionState;

FAST_MUTEX ConnectionStateLock;
WDFSPINLOCK ConnectionStateLock;

L2CAP_CHANNEL_HANDLE ChannelHandle;

Expand Down
52 changes: 26 additions & 26 deletions BthPS3/L2CAP.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ L2CAP_PS3_ControlConnectResponseCompleted(
//
if (NT_SUCCESS(status))
{
ExAcquireFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock);
{
clientConnection->HidControlChannel.ConnectionState = ConnectionStateConnected;
WdfSpinLockAcquire(clientConnection->HidControlChannel.ConnectionStateLock);

//
// This will be set again once disconnect has occurred
//
//KeClearEvent(&clientConnection->HidControlChannel.DisconnectEvent);
}
ExReleaseFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock);
clientConnection->HidControlChannel.ConnectionState = ConnectionStateConnected;

//
// This will be set again once disconnect has occurred
//
//KeClearEvent(&clientConnection->HidControlChannel.DisconnectEvent);

WdfSpinLockRelease(clientConnection->HidControlChannel.ConnectionStateLock);

TraceEvents(TRACE_LEVEL_INFORMATION,
TRACE_L2CAP,
Expand Down Expand Up @@ -492,16 +492,16 @@ L2CAP_PS3_InterruptConnectResponseCompleted(
//
if (NT_SUCCESS(status))
{
ExAcquireFastMutex(&clientConnection->HidInterruptChannel.ConnectionStateLock);
{
clientConnection->HidInterruptChannel.ConnectionState = ConnectionStateConnected;
WdfSpinLockAcquire(clientConnection->HidInterruptChannel.ConnectionStateLock);

clientConnection->HidInterruptChannel.ConnectionState = ConnectionStateConnected;

//
// This will be set again once disconnect has occurred
//
//KeClearEvent(&clientConnection->HidInterruptChannel.DisconnectEvent);

//
// This will be set again once disconnect has occurred
//
//KeClearEvent(&clientConnection->HidInterruptChannel.DisconnectEvent);
}
ExReleaseFastMutex(&clientConnection->HidInterruptChannel.ConnectionStateLock);
WdfSpinLockRelease(clientConnection->HidInterruptChannel.ConnectionStateLock);

TraceEvents(TRACE_LEVEL_INFORMATION,
TRACE_L2CAP,
Expand All @@ -511,9 +511,9 @@ L2CAP_PS3_InterruptConnectResponseCompleted(
//
// Control channel is expected to be established by now
//
ExAcquireFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock);
WdfSpinLockAcquire(clientConnection->HidControlChannel.ConnectionStateLock);
controlState = clientConnection->HidInterruptChannel.ConnectionState;
ExReleaseFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock);
WdfSpinLockRelease(clientConnection->HidControlChannel.ConnectionStateLock);

if (controlState != ConnectionStateConnected)
{
Expand Down Expand Up @@ -948,7 +948,7 @@ L2CAP_PS3_RemoteDisconnect(
{
struct _BRB_L2CA_CLOSE_CHANNEL* disconnectBrb = NULL;

ExAcquireFastMutex(&Channel->ConnectionStateLock);
WdfSpinLockAcquire(Channel->ConnectionStateLock);

if (Channel->ConnectionState == ConnectionStateConnecting)
{
Expand All @@ -967,7 +967,7 @@ L2CAP_PS3_RemoteDisconnect(
//
KeClearEvent(&Channel->DisconnectEvent);

ExReleaseFastMutex(&Channel->ConnectionStateLock);
WdfSpinLockRelease(Channel->ConnectionStateLock);
return TRUE;
}

Expand All @@ -977,12 +977,12 @@ L2CAP_PS3_RemoteDisconnect(
// Do nothing if we are not connected
//

ExReleaseFastMutex(&Channel->ConnectionStateLock);
WdfSpinLockRelease(Channel->ConnectionStateLock);
return FALSE;
}

Channel->ConnectionState = ConnectionStateDisconnecting;
ExReleaseFastMutex(&Channel->ConnectionStateLock);
WdfSpinLockRelease(Channel->ConnectionStateLock);

//
// We are now sending the disconnect, so clear the event.
Expand Down Expand Up @@ -1036,9 +1036,9 @@ L2CAP_PS3_ChannelDisconnectCompleted(
TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_L2CAP, "%!FUNC! Entry (%!STATUS!)",
Params->IoStatus.Status);

ExAcquireFastMutex(&channel->ConnectionStateLock);
WdfSpinLockAcquire(channel->ConnectionStateLock);
channel->ConnectionState = ConnectionStateDisconnected;
ExReleaseFastMutex(&channel->ConnectionStateLock);
WdfSpinLockRelease(channel->ConnectionStateLock);

//
// Disconnect complete, set the event
Expand Down

0 comments on commit 6ae5df6

Please sign in to comment.