module rt.gc.cdgc.bits;
-import rt.gc.cdgc.alloc: os_mem_map, os_mem_unmap, Vis;
+import os = rt.gc.cdgc.os;
import cstring = tango.stdc.string;
return (nwords + 2) * uint.sizeof; // +2 for sentinels
}
- void Dtor(Vis vis = Vis.PRIV)
+ void Dtor(os.Vis vis = os.Vis.PRIV)
{
- // Even when os_mem_unmap() can be called with a null pointer, the
- // extra call might be significant. On hard GC benchmarks making the
- // test for null here (i.e. not making the call) can reduce the GC time
- // by almost ~5%.
+ // Even when os.dealloc() can be called with a null pointer, the extra
+ // call might be significant. On hard GC benchmarks making the test for
+ // null here (i.e. not making the call) can reduce the GC time by
+ // almost ~5%.
if (data)
{
- os_mem_unmap(data, data_size, vis);
+ os.dealloc(data, data_size, vis);
data = null;
}
}
}
}
- void alloc(size_t nbits, Vis vis = Vis.PRIV)
+ void alloc(size_t nbits, os.Vis vis = os.Vis.PRIV)
{
this.nbits = nbits;
this.nwords = (nbits + (BITS_PER_WORD - 1)) >> BITS_SHIFT;
- this.data = cast(uint*) os_mem_map(data_size, vis);
+ this.data = cast(uint*) os.alloc(data_size, vis);
if (!data)
onOutOfMemoryError();
}
import rt.gc.cdgc.bits: GCBits;
import rt.gc.cdgc.stats: GCStats, Stats;
import dynarray = rt.gc.cdgc.dynarray;
-import alloc = rt.gc.cdgc.alloc;
+import os = rt.gc.cdgc.os;
import opts = rt.gc.cdgc.opts;
import cstdlib = tango.stdc.stdlib;
{
size_t poolsize = npages * PAGESIZE;
assert(poolsize >= POOLSIZE);
- baseAddr = cast(byte *) alloc.os_mem_map(poolsize);
+ baseAddr = cast(byte *) os.alloc(poolsize);
// Some of the code depends on page alignment of memory pools
assert((cast(size_t)baseAddr & (PAGESIZE - 1)) == 0);
if (npages)
{
- result = alloc.os_mem_unmap(baseAddr, npages * PAGESIZE);
+ result = os.dealloc(baseAddr, npages * PAGESIZE);
assert(result);
npages = 0;
}
* be misrepresented as being the original software.
* o This notice may not be removed or altered from any source
* distribution.
- * Authors: Walter Bright, David Friedman, Sean Kelly
+ * Authors: Walter Bright, David Friedman, Sean Kelly, Leandro Lucarella
*/
-module rt.gc.cdgc.alloc;
+module rt.gc.cdgc.os;
+
+
+// Fork
+////////////////////////////////////////////////////////////////////////
+
+// Public interface/Documentation
+
+version (D_Ddoc) {
+
+/**
+ * Indicates if an implementation support fork().
+ *
+ * The value shown here is just demostrative, the real value is defined based
+ * on the OS it's being compiled in.
+ */
+const HAVE_FORK = true;
+
+public import tango.stdc.posix.unistd: pid_t, fork;
+public import tango.stdc.posix.sys.wait: waitpid;
+
+}
+
+// Implementations
+else version (Posix) {
+ enum { HAVE_FORK = true }
+ public import tango.stdc.posix.unistd: pid_t, fork;
+ public import tango.stdc.posix.sys.wait: waitpid;
+}
+
+else {
+ enum { HAVE_FORK = false }
+ alias int pid_t;
+ pid_t fork() { assert (false); return -1; }
+ pid_t waitpid(pid_t, int*, int) { assert (false); return -1; }
+}
+
+
+// Allocation
+////////////////////////////////////////////////////////////////////////
version (Win32)
import tango.sys.win32.UserGdi;
/**
* Map memory.
*/
-void* os_mem_map(size_t nbytes, Vis vis = Vis.PRIV);
+void* alloc(size_t nbytes, Vis vis = Vis.PRIV);
/**
- * Unmap memory allocated with os_mem_map().
+ * Unmap memory allocated with alloc().
* Returns:
* true success
* false failure
*/
-bool os_mem_unmap(void* base, size_t nbytes, Vis vis = Vis.PRIV);
+bool dealloc(void* base, size_t nbytes, Vis vis = Vis.PRIV);
}
else static if (is(typeof(VirtualAlloc))) {
enum { HAVE_SHARED = false }
- void* os_mem_map(size_t nbytes, Vis vis = Vis.PRIV)
+ void* alloc(size_t nbytes, Vis vis = Vis.PRIV)
{
assert (vis == Vis.PRIV);
return VirtualAlloc(null, nbytes, MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
}
- bool os_mem_unmap(void* base, size_t nbytes, Vis vis = Vis.PRIV)
+ bool dealloc(void* base, size_t nbytes, Vis vis = Vis.PRIV)
{
assert (vis == Vis.PRIV);
return VirtualFree(base, 0, MEM_RELEASE) != 0;
else static if (is(typeof(mmap)) && is(typeof(MAP_ANON))) {
enum { HAVE_SHARED = true }
- void* os_mem_map(size_t nbytes, Vis vis = Vis.PRIV)
+ void* alloc(size_t nbytes, Vis vis = Vis.PRIV)
{
auto flags = MAP_ANON;
if (vis == Vis.SHARED)
return (p == MAP_FAILED) ? null : p;
}
- bool os_mem_unmap(void* base, size_t nbytes, Vis vis = Vis.PRIV)
+ bool dealloc(void* base, size_t nbytes, Vis vis = Vis.PRIV)
{
// vis is not necessary to unmap
return munmap(base, nbytes) == 0;
const size_t PAGE_MASK = PAGESIZE - 1;
- void* os_mem_map(size_t nbytes, Vis vis = Vis.PRIV)
+ void* alloc(size_t nbytes, Vis vis = Vis.PRIV)
{
assert (vis == Vis.PRIV);
byte* p, q;
return q;
}
- bool os_mem_unmap(void* base, size_t nbytes, Vis vis = Vis.PRIV)
+ bool dealloc(void* base, size_t nbytes, Vis vis = Vis.PRIV)
{
assert (vis == Vis.PRIV);
free(*cast(void**)(cast(byte*) base + nbytes));