diff --git a/src/rt/critical.c b/src/rt/critical.c
deleted file mode 100644
index db4d43f24fd..00000000000
--- a/src/rt/critical.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * Implementation of support routines for synchronized blocks.
- *
- * Copyright: Copyright Digital Mars 2000 - 2010.
- * License: Boost License 1.0.
- * Authors: Walter Bright, Sean Kelly
- */
-
-/* Copyright Digital Mars 2000 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-
-/* ================================= Win32 ============================ */
-
-#if _WIN32
-
-#include
-
-/******************************************
- * Enter/exit critical section.
- */
-
-/* We don't initialize critical sections unless we actually need them.
- * So keep a linked list of the ones we do use, and in the static destructor
- * code, walk the list and release them.
- */
-
-typedef struct D_CRITICAL_SECTION
-{
- struct D_CRITICAL_SECTION *next;
- CRITICAL_SECTION cs;
-} D_CRITICAL_SECTION;
-
-static D_CRITICAL_SECTION *dcs_list;
-static D_CRITICAL_SECTION critical_section;
-static volatile int inited;
-
-void _d_criticalenter(D_CRITICAL_SECTION *dcs)
-{
- if (!dcs->next)
- {
- EnterCriticalSection(&critical_section.cs);
- if (!dcs->next) // if, in the meantime, another thread didn't set it
- {
- dcs->next = dcs_list;
- dcs_list = dcs;
- InitializeCriticalSection(&dcs->cs);
- }
- LeaveCriticalSection(&critical_section.cs);
- }
- EnterCriticalSection(&dcs->cs);
-}
-
-void _d_criticalexit(D_CRITICAL_SECTION *dcs)
-{
- LeaveCriticalSection(&dcs->cs);
-}
-
-void _STI_critical_init()
-{
- if (!inited)
- { InitializeCriticalSection(&critical_section.cs);
- dcs_list = &critical_section;
- inited = 1;
- }
-}
-
-void _STD_critical_term()
-{
- if (inited)
- { inited = 0;
- while (dcs_list)
- {
- DeleteCriticalSection(&dcs_list->cs);
- dcs_list = dcs_list->next;
- }
- }
-}
-
-#endif
-
-/* ================================= linux ============================ */
-
-#if linux || __APPLE__ || __FreeBSD__
-
-#include
-#include
-#include
-
-// PTHREAD_MUTEX_RECURSIVE is the "standard" symbol,
-// while the _NP version is specific to Linux
-#if linux
-# ifndef PTHREAD_MUTEX_RECURSIVE
-# define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
-# endif
-#endif
-
-/******************************************
- * Enter/exit critical section.
- */
-
-/* We don't initialize critical sections unless we actually need them.
- * So keep a linked list of the ones we do use, and in the static destructor
- * code, walk the list and release them.
- */
-
-typedef struct D_CRITICAL_SECTION
-{
- struct D_CRITICAL_SECTION *next;
- pthread_mutex_t cs;
-} D_CRITICAL_SECTION;
-
-static D_CRITICAL_SECTION *dcs_list;
-static D_CRITICAL_SECTION critical_section;
-static pthread_mutexattr_t _criticals_attr;
-
-void _STI_critical_init(void);
-void _STD_critical_term(void);
-
-void _d_criticalenter(D_CRITICAL_SECTION *dcs)
-{
- if (!dcs_list)
- { _STI_critical_init();
- atexit(_STD_critical_term);
- }
- //printf("_d_criticalenter(dcs = x%x)\n", dcs);
- if (!dcs->next)
- {
- pthread_mutex_lock(&critical_section.cs);
- if (!dcs->next) // if, in the meantime, another thread didn't set it
- {
- dcs->next = dcs_list;
- dcs_list = dcs;
- pthread_mutex_init(&dcs->cs, &_criticals_attr);
- }
- pthread_mutex_unlock(&critical_section.cs);
- }
- pthread_mutex_lock(&dcs->cs);
-}
-
-void _d_criticalexit(D_CRITICAL_SECTION *dcs)
-{
- //printf("_d_criticalexit(dcs = x%x)\n", dcs);
- pthread_mutex_unlock(&dcs->cs);
-}
-
-void _STI_critical_init()
-{
- if (!dcs_list)
- { //printf("_STI_critical_init()\n");
- pthread_mutexattr_init(&_criticals_attr);
- pthread_mutexattr_settype(&_criticals_attr, PTHREAD_MUTEX_RECURSIVE);
-
- // The global critical section doesn't need to be recursive
- pthread_mutex_init(&critical_section.cs, 0);
- dcs_list = &critical_section;
- }
-}
-
-void _STD_critical_term()
-{
- if (dcs_list)
- { //printf("_STI_critical_term()\n");
- while (dcs_list)
- {
- //printf("\tlooping... %x\n", dcs_list);
- pthread_mutex_destroy(&dcs_list->cs);
- dcs_list = dcs_list->next;
- }
- }
-}
-
-#endif
-
diff --git a/src/rt/critical_.d b/src/rt/critical_.d
index 5f3b951a099..1be9ca17f3f 100644
--- a/src/rt/critical_.d
+++ b/src/rt/critical_.d
@@ -84,6 +84,11 @@ version( Windows )
extern (C) void _d_criticalenter(D_CRITICAL_SECTION *dcs)
{
+ if (!dcs_list)
+ {
+ _STI_critical_init();
+ atexit(&_STD_critical_term);
+ }
debug(PRINTF) printf("_d_criticalenter(dcs = x%x)\n", dcs);
if (!dcs.next)
{
diff --git a/src/rt/dmain2.d b/src/rt/dmain2.d
index 40828c405c8..f7f44f7a676 100644
--- a/src/rt/dmain2.d
+++ b/src/rt/dmain2.d
@@ -272,11 +272,8 @@ extern (C) __gshared bool rt_trapExceptions = true;
void _d_criticalInit()
{
- version (Posix)
- {
- _STI_monitor_staticctor();
- _STI_critical_init();
- }
+ _STI_monitor_staticctor();
+ _STI_critical_init();
}
alias void delegate(Throwable) ExceptionHandler;
@@ -309,11 +306,8 @@ extern (C) bool rt_init(ExceptionHandler dg = null)
void _d_criticalTerm()
{
- version (Posix)
- {
- _STD_critical_term();
- _STD_monitor_staticdtor();
- }
+ _STD_critical_term();
+ _STD_monitor_staticdtor();
}
extern (C) bool rt_term(ExceptionHandler dg = null)
@@ -381,11 +375,8 @@ extern (C) int main(int argc, char** argv)
}
}
- version (Posix)
- {
- _STI_monitor_staticctor();
- _STI_critical_init();
- }
+ _STI_monitor_staticctor();
+ _STI_critical_init();
version (Windows)
{
@@ -561,10 +552,8 @@ extern (C) int main(int argc, char** argv)
tryExec(&runAll);
- version (Posix)
- {
- _STD_critical_term();
- _STD_monitor_staticdtor();
- }
+ _STD_critical_term();
+ _STD_monitor_staticdtor();
+
return result;
}
diff --git a/src/rt/mars.h b/src/rt/mars.h
deleted file mode 100644
index e95038f649e..00000000000
--- a/src/rt/mars.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * Common declarations for runtime implementation.
- *
- * Copyright: Copyright Digital Mars 2000 - 2010.
- * License: Boost License 1.0.
- * Authors: Walter Bright, Sean Kelly
- */
-
-/* Copyright Digital Mars 2000 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-#include
-
-#if __cplusplus
-extern "C" {
-#endif
-
-struct ClassInfo;
-struct Vtbl;
-
-typedef struct Vtbl
-{
- size_t len;
- void **vptr;
-} Vtbl;
-
-typedef struct Interface
-{
- struct ClassInfo *classinfo;
- struct Vtbl vtbl;
- int offset;
-} Interface;
-
-typedef struct Object
-{
- void **vptr;
- void *monitor;
-} Object;
-
-typedef struct ClassInfo
-{
- Object object;
-
- size_t initlen;
- void *init;
-
- size_t namelen;
- char *name;
-
- Vtbl vtbl;
-
- size_t interfacelen;
- Interface *interfaces;
-
- struct ClassInfo *baseClass;
-
- void *destructor;
- void *invariant;
-
- int flags;
-} ClassInfo;
-
-typedef struct Throwable
-{
- Object object;
-
- size_t msglen;
- char* msg;
-
- size_t filelen;
- char* file;
-
- size_t line;
-
- struct Interface *info;
- struct Throwable *next;
-} Throwable;
-
-typedef struct Array
-{
- size_t length;
- void *ptr;
-} Array;
-
-typedef struct Delegate
-{
- void *thisptr;
- void (*funcptr)();
-} Delegate;
-
-void _d_monitorenter(Object *h);
-void _d_monitorexit(Object *h);
-
-int _d_isbaseof(ClassInfo *b, ClassInfo *c);
-Object *_d_dynamic_cast(Object *o, ClassInfo *ci);
-
-Object * _d_newclass(ClassInfo *ci);
-void _d_delclass(Object **p);
-
-void _d_OutOfMemory();
-
-#if __cplusplus
-}
-#endif
diff --git a/src/rt/monitor.c b/src/rt/monitor.c
deleted file mode 100644
index 64314b630a3..00000000000
--- a/src/rt/monitor.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Contains the Windows implementation for object monitors.
- *
- * Copyright: Copyright Digital Mars 2000 - 2012.
- * License: Distributed under the
- * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
- * (See accompanying file LICENSE)
- * Authors: Walter Bright, Sean Kelly
- * Source: $(DRUNTIMESRC src/rt/_monitor.c)
- */
-
-#if _WIN32 /* and Windows 64 */
-
-#include
-#include
-#include
-
-#include
-
-#include "mars.h"
-
-// This is what the monitor reference in Object points to
-typedef struct Monitor
-{
- void* impl; // for user-level monitors
- Array devt; // for internal monitors
- size_t refs; // reference count
-
- CRITICAL_SECTION mon;
-} Monitor;
-
-#define MONPTR(h) (&((Monitor *)(h)->monitor)->mon)
-
-static volatile int inited;
-
-/* =============================== Win32 ============================ */
-
-static CRITICAL_SECTION _monitor_critsec;
-
-void _STI_monitor_staticctor()
-{
- if (!inited)
- { InitializeCriticalSection(&_monitor_critsec);
- inited = 1;
- }
-}
-
-void _STD_monitor_staticdtor()
-{
- if (inited)
- { inited = 0;
- DeleteCriticalSection(&_monitor_critsec);
- }
-}
-
-void _d_monitor_create(Object *h)
-{
- /*
- * NOTE: Assume this is only called when h->monitor is null prior to the
- * call. However, please note that another thread may call this function
- * at the same time, so we can not assert this here. Instead, try and
- * create a lock, and if one already exists then forget about it.
- */
-
- //printf("+_d_monitor_create(%p)\n", h);
- Monitor *cs = NULL;
- assert(h);
- EnterCriticalSection(&_monitor_critsec);
- if (!h->monitor)
- {
- cs = (Monitor *)calloc(sizeof(Monitor), 1);
- assert(cs);
- InitializeCriticalSection(&cs->mon);
- h->monitor = (void *)cs;
- cs->refs = 1;
- cs = NULL;
- }
- LeaveCriticalSection(&_monitor_critsec);
- if (cs)
- free(cs);
- //printf("-_d_monitor_create(%p)\n", h);
-}
-
-void _d_monitor_destroy(Object *h)
-{
- //printf("+_d_monitor_destroy(%p)\n", h);
- assert(h && h->monitor && !(((Monitor*)h->monitor)->impl));
- DeleteCriticalSection(MONPTR(h));
- free((void *)h->monitor);
- h->monitor = NULL;
- //printf("-_d_monitor_destroy(%p)\n", h);
-}
-
-void _d_monitor_lock(Object *h)
-{
- //printf("+_d_monitor_acquire(%p)\n", h);
- assert(h && h->monitor && !(((Monitor*)h->monitor)->impl));
- EnterCriticalSection(MONPTR(h));
- //printf("-_d_monitor_acquire(%p)\n", h);
-}
-
-void _d_monitor_unlock(Object *h)
-{
- //printf("+_d_monitor_release(%p)\n", h);
- assert(h && h->monitor && !(((Monitor*)h->monitor)->impl));
- LeaveCriticalSection(MONPTR(h));
- //printf("-_d_monitor_release(%p)\n", h);
-}
-
-#endif
-
diff --git a/src/rt/monitor_.d b/src/rt/monitor_.d
index 1395ff2d7bc..0c42ed5a58e 100644
--- a/src/rt/monitor_.d
+++ b/src/rt/monitor_.d
@@ -88,7 +88,6 @@ private
version( Windows )
{
- /+
static __gshared CRITICAL_SECTION _monitor_critsec;
extern (C) void _STI_monitor_staticctor()
@@ -166,7 +165,6 @@ version( Windows )
LeaveCriticalSection(&getMonitor(h).mon);
debug(PRINTF) printf("-_d_monitor_release(%p)\n", h);
}
- +/
}
/* =============================== linux ============================ */