You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/FASTER/Allocator/PendingFlushList.cs

57 lines
1.5 KiB

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Threading;
namespace FASTER.core
{
class PendingFlushList
{
const int maxSize = 8;
const int maxRetries = 10;
public PageAsyncFlushResult<Empty>[] list;
public PendingFlushList()
{
list = new PageAsyncFlushResult<Empty>[maxSize];
}
public void Add(PageAsyncFlushResult<Empty> t)
{
int retries = 0;
do
{
for (int i = 0; i < maxSize; i++)
{
if (list[i] == default)
{
if (Interlocked.CompareExchange(ref list[i], t, default) == default)
{
return;
}
}
}
} while (retries++ < maxRetries);
throw new Exception("Unable to add item to list");
}
public bool RemoveAdjacent(long address, out PageAsyncFlushResult<Empty> request)
{
for (int i=0; i<maxSize; i++)
{
request = list[i];
if (request?.fromAddress == address)
{
if (Interlocked.CompareExchange(ref list[i], null, request) == request)
{
return true;
}
}
}
request = null;
return false;
}
}
}

Powered by TurnKey Linux.