DPRINT_ENTER(VMBUS);
- nextGpadlHandle = gVmbusConnection.NextGpadlHandle;
- InterlockedIncrement((int*)&gVmbusConnection.NextGpadlHandle);
+ nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
+ atomic_inc(&gVmbusConnection.NextGpadlHandle);
VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
ASSERT(msgInfo != NULL);
struct VMBUS_CONNECTION gVmbusConnection = {
.ConnectState = Disconnected,
- .NextGpadlHandle = 0xE1E10,
+ .NextGpadlHandle = ATOMIC_INIT(0xE1E10),
};
return NULL;
/* Set to 2 to allow both inbound and outbound traffic */
- InterlockedCompareExchange(&netDevice->RefCount, 2, 0);
+ atomic_cmpxchg(&netDevice->RefCount, 0, 2);
netDevice->Device = Device;
Device->Extension = netDevice;
static inline void FreeNetDevice(struct NETVSC_DEVICE *Device)
{
- ASSERT(Device->RefCount == 0);
+ ASSERT(atomic_read(&Device->RefCount) == 0);
Device->Device->Extension = NULL;
kfree(Device);
}
struct NETVSC_DEVICE *netDevice;
netDevice = (struct NETVSC_DEVICE*)Device->Extension;
- if (netDevice && netDevice->RefCount > 1)
- {
- InterlockedIncrement(&netDevice->RefCount);
- }
+ if (netDevice && atomic_read(&netDevice->RefCount) > 1)
+ atomic_inc(&netDevice->RefCount);
else
- {
netDevice = NULL;
- }
return netDevice;
}
struct NETVSC_DEVICE *netDevice;
netDevice = (struct NETVSC_DEVICE*)Device->Extension;
- if (netDevice && netDevice->RefCount)
- {
- InterlockedIncrement(&netDevice->RefCount);
- }
+ if (netDevice && atomic_read(&netDevice->RefCount))
+ atomic_inc(&netDevice->RefCount);
else
- {
netDevice = NULL;
- }
return netDevice;
}
netDevice = (struct NETVSC_DEVICE*)Device->Extension;
ASSERT(netDevice);
- InterlockedDecrement(&netDevice->RefCount);
+ atomic_dec(&netDevice->RefCount);
}
static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device)
return NULL;
/* Busy wait until the ref drop to 2, then set it to 1 */
- while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2)
+ while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2)
{
udelay(100);
}
return NULL;
/* Busy wait until the ref drop to 1, then set it to 0 */
- while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1)
+ while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1)
{
udelay(100);
}
}
/* Wait for all send completions */
- while (netDevice->NumOutstandingSends)
+ while (atomic_read(&netDevice->NumOutstandingSends))
{
- DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends);
+ DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", atomic_read(&netDevice->NumOutstandingSends));
udelay(100);
}
/* Notify the layer above us */
nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext);
- InterlockedDecrement(&netDevice->NumOutstandingSends);
+ atomic_dec(&netDevice->NumOutstandingSends);
}
else
{
DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret);
}
- InterlockedIncrement(&netDevice->NumOutstandingSends);
+ atomic_inc(&netDevice->NumOutstandingSends);
PutNetDevice(Device);
DPRINT_EXIT(NETVSC);
struct NETVSC_DEVICE {
struct hv_device *Device;
- int RefCount;
-
- int NumOutstandingSends;
+ atomic_t RefCount;
+ atomic_t NumOutstandingSends;
/* List of free preallocated hv_netvsc_packet to represent receive packet */
LIST_ENTRY ReceivePacketList;
spinlock_t receive_packet_list_lock;
RNDIS_DEVICE_STATE State;
u32 LinkStatus;
- u32 NewRequestId;
+ atomic_t NewRequestId;
spinlock_t request_lock;
LIST_ENTRY RequestList;
/* Set the request id. This field is always after the rndis header for request/response packet types so */
/* we just used the SetRequest as a template */
set = &rndisMessage->Message.SetRequest;
- set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId);
+ set->RequestId = atomic_inc_return(&Device->NewRequestId);
/* Add to the request list */
spin_lock_irqsave(&Device->request_lock, flags);
/* Setup the rndis set */
halt = &request->RequestMessage.Message.HaltRequest;
- halt->RequestId = InterlockedIncrement((int*)&Device->NewRequestId);
+ halt->RequestId = atomic_inc_return(&Device->NewRequestId);
/* Ignore return since this msg is optional. */
RndisFilterSendRequest(Device, request);
typedef struct _STORVSC_DEVICE{
struct hv_device *Device;
- int RefCount; /* 0 indicates the device is being destroyed */
+ atomic_t RefCount; /* 0 indicates the device is being destroyed */
- int NumOutstandingRequests;
+ atomic_t NumOutstandingRequests;
/*
* Each unique Port/Path/Target represents 1 channel ie scsi
/* Set to 2 to allow both inbound and outbound traffics */
/* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */
- InterlockedCompareExchange(&storDevice->RefCount, 2, 0);
+ atomic_cmpxchg(&storDevice->RefCount, 0, 2);
storDevice->Device = Device;
Device->Extension = storDevice;
static inline void FreeStorDevice(STORVSC_DEVICE *Device)
{
- ASSERT(Device->RefCount == 0);
+ ASSERT( atomic_read(&Device->RefCount) == 0);
kfree(Device);
}
STORVSC_DEVICE *storDevice;
storDevice = (STORVSC_DEVICE*)Device->Extension;
- if (storDevice && storDevice->RefCount > 1)
- {
- InterlockedIncrement(&storDevice->RefCount);
- }
+ if (storDevice && atomic_read(&storDevice->RefCount) > 1)
+ atomic_inc(&storDevice->RefCount);
else
- {
storDevice = NULL;
- }
return storDevice;
}
STORVSC_DEVICE *storDevice;
storDevice = (STORVSC_DEVICE*)Device->Extension;
- if (storDevice && storDevice->RefCount)
- {
- InterlockedIncrement(&storDevice->RefCount);
- }
+ if (storDevice && atomic_read(&storDevice->RefCount))
+ atomic_inc(&storDevice->RefCount);
else
- {
storDevice = NULL;
- }
return storDevice;
}
storDevice = (STORVSC_DEVICE*)Device->Extension;
ASSERT(storDevice);
- InterlockedDecrement(&storDevice->RefCount);
- ASSERT(storDevice->RefCount);
+ atomic_dec(&storDevice->RefCount);
+ ASSERT(atomic_read(&storDevice->RefCount));
}
/* Drop ref count to 1 to effectively disable GetStorDevice() */
ASSERT(storDevice);
/* Busy wait until the ref drop to 2, then set it to 1 */
- while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2)
+ while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2)
{
udelay(100);
}
ASSERT(storDevice);
/* Busy wait until the ref drop to 1, then set it to 0 */
- while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1)
+ while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1)
{
udelay(100);
}
* only allow inbound traffic (responses) to proceed so that
* outstanding requests can be completed.
*/
- while (storDevice->NumOutstandingRequests)
+ while (atomic_read(&storDevice->NumOutstandingRequests))
{
- DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests);
+ DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", atomic_read(&storDevice->NumOutstandingRequests));
udelay(100);
}
DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret);
}
- InterlockedIncrement(&storDevice->NumOutstandingRequests);
+ atomic_inc(&storDevice->NumOutstandingRequests);
PutStorDevice(Device);
request->OnIOCompletion(request);
- InterlockedDecrement(&storDevice->NumOutstandingRequests);
+ atomic_dec(&storDevice->NumOutstandingRequests);
PutStorDevice(Device);
enum VMBUS_CONNECT_STATE ConnectState;
- u32 NextGpadlHandle;
+ atomic_t NextGpadlHandle;
/*
* Represents channel interrupts. Each bit position represents
/* Osd routines */
-extern int InterlockedIncrement(int *val);
-extern int InterlockedDecrement(int *val);
-extern int InterlockedCompareExchange(int *val, int new, int curr);
-
extern void* VirtualAllocExec(unsigned int size);
extern void VirtualFree(void* VirtAddr);
void *data;
};
-int InterlockedIncrement(int *val)
-{
- return atomic_inc_return((atomic_t*)val);
-}
-
-int InterlockedDecrement(int *val)
-{
- return atomic_dec_return((atomic_t*)val);
-}
-
-#ifndef atomic_cmpxchg
-#define atomic_cmpxchg(v, old, new) ((int)cmpxchg(&((v)->counter), old, new))
-#endif
-int InterlockedCompareExchange(int *val, int new, int curr)
-{
- /* return ((int)cmpxchg(((atomic_t*)val), curr, new)); */
- return atomic_cmpxchg((atomic_t*)val, curr, new);
-
-}
-
void* VirtualAllocExec(unsigned int size)
{
#ifdef __x86_64__
int ret=0;
struct device_context *root_device_ctx = to_device_context(root_device_obj);
struct device_context *child_device_ctx = to_device_context(child_device_obj);
- static int device_num=0;
+ static atomic_t device_num = ATOMIC_INIT(0);
DPRINT_ENTER(VMBUS_DRV);
}
/* Set the device bus id. Otherwise, device_register()will fail. */
- dev_set_name(&child_device_ctx->device, "vmbus_0_%d", InterlockedIncrement(&device_num));
+ dev_set_name(&child_device_ctx->device, "vmbus_0_%d", atomic_inc_return(&device_num));
/* The new device belongs to this bus */
child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */