Make allocators shared

This commit is contained in:
2016-10-04 18:19:48 +02:00
parent be9181698a
commit 698660c4c8
14 changed files with 504 additions and 448 deletions

View File

@ -12,8 +12,6 @@ module tanya.container.buffer;
import tanya.memory;
@nogc:
version (unittest)
{
private int fillBuffer(void* buffer,
@ -42,7 +40,6 @@ version (unittest)
*/
interface Buffer
{
@nogc:
/**
* Returns: The size of the internal buffer.
*/
@ -74,7 +71,6 @@ interface Buffer
*/
class ReadBuffer : Buffer
{
@nogc:
/// Internal buffer.
protected ubyte[] _buffer;
@ -87,7 +83,7 @@ class ReadBuffer : Buffer
/// Size by which the buffer will grow.
protected immutable size_t blockSize;
private Allocator allocator;
private shared Allocator allocator;
invariant
{
@ -107,7 +103,7 @@ class ReadBuffer : Buffer
*/
this(size_t size = 8192,
size_t minAvailable = 1024,
Allocator allocator = defaultAllocator)
shared Allocator allocator = defaultAllocator)
{
this.allocator = allocator;
this.minAvailable = minAvailable;
@ -294,7 +290,6 @@ class ReadBuffer : Buffer
*/
class WriteBuffer : Buffer
{
@nogc:
/// Internal buffer.
protected ubyte[] _buffer;
@ -310,7 +305,7 @@ class WriteBuffer : Buffer
/// The position of the free area in the buffer.
protected size_t position;
private Allocator allocator;
private shared Allocator allocator;
invariant
{
@ -325,7 +320,7 @@ class WriteBuffer : Buffer
* will grow.
*/
this(size_t size = 8192,
Allocator allocator = defaultAllocator)
shared Allocator allocator = defaultAllocator)
{
this.allocator = allocator;
blockSize = size;

View File

@ -20,7 +20,6 @@ import tanya.memory;
*/
class SList(T)
{
@nogc:
/**
* Creates a new $(D_PSYMBOL SList).
*
@ -28,7 +27,7 @@ class SList(T)
* allocator = The allocator should be used for the element
* allocations.
*/
this(Allocator allocator = defaultAllocator)
this(shared Allocator allocator = defaultAllocator)
{
this.allocator = allocator;
reset();
@ -241,7 +240,7 @@ class SList(T)
* Params:
* dg = $(D_KEYWORD foreach) body.
*/
int opApply(int delegate(ref size_t i, ref T) @nogc dg)
int opApply(int delegate(ref size_t i, ref T) dg)
{
int result;
size_t i;
@ -280,7 +279,7 @@ class SList(T)
}
/// Ditto.
int opApply(int delegate(ref T) @nogc dg)
int opApply(int delegate(ref T) dg)
{
int result;
@ -389,7 +388,7 @@ class SList(T)
/// Current position in the list.
protected Entry* position;
private Allocator allocator;
private shared Allocator allocator;
}
interface Stuff

View File

@ -20,7 +20,6 @@ import tanya.memory;
*/
class Queue(T)
{
@nogc:
/**
* Creates a new $(D_PSYMBOL Queue).
*
@ -28,7 +27,7 @@ class Queue(T)
* allocator = The allocator should be used for the element
* allocations.
*/
this(Allocator allocator = defaultAllocator)
this(shared Allocator allocator = defaultAllocator)
{
this.allocator = allocator;
}
@ -207,7 +206,7 @@ class Queue(T)
/// The last element of the list.
protected Entry* rear;
private Allocator allocator;
private shared Allocator allocator;
}
///

View File

@ -12,8 +12,6 @@ module tanya.container.vector;
import tanya.memory;
@nogc:
/**
* One dimensional array. It allocates automatically if needed.
*
@ -34,7 +32,6 @@ import tanya.memory;
*/
class Vector(T)
{
@nogc:
/**
* Creates a new $(D_PSYMBOL Vector).
*
@ -43,14 +40,14 @@ class Vector(T)
* allocator = The allocator should be used for the element
* allocations.
*/
this(size_t length, Allocator allocator = defaultAllocator)
this(size_t length, shared Allocator allocator = defaultAllocator)
{
this.allocator = allocator;
vector = makeArray!T(allocator, length);
}
/// Ditto.
this(Allocator allocator = defaultAllocator)
this(shared Allocator allocator = defaultAllocator)
{
this(0, allocator);
}
@ -194,7 +191,7 @@ class Vector(T)
* Params:
* dg = $(D_KEYWORD foreach) body.
*/
int opApply(int delegate(ref T) @nogc dg)
int opApply(int delegate(ref T) dg)
{
int result;
@ -211,7 +208,7 @@ class Vector(T)
}
/// Ditto.
int opApply(int delegate(ref size_t i, ref T) @nogc dg)
int opApply(int delegate(ref size_t i, ref T) dg)
{
int result;
@ -408,7 +405,7 @@ class Vector(T)
/// Container.
protected T[] vector;
private Allocator allocator;
private shared Allocator allocator;
}
///