Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finish conversion from critical.c and monitor.d to their .d versions

  • Loading branch information...
commit 031f65b587f2041b1030147fa83db2a31a820037 1 parent eddc043
@braddr braddr authored
View
10 posix.mak
@@ -153,7 +153,7 @@ MANIFEST= \
src/rt/compiler.d \
src/rt/complex.c \
src/rt/cover.d \
- src/rt/critical.c \
+ src/rt/critical_.d \
src/rt/deh.d \
src/rt/deh2.d \
src/rt/dmain2.d \
@@ -163,12 +163,11 @@ MANIFEST= \
src/rt/invariant_.d \
src/rt/lifetime.d \
src/rt/llmath.d \
- src/rt/mars.h \
src/rt/memory.d \
src/rt/memory_osx.c \
src/rt/memset.d \
src/rt/minit.asm \
- src/rt/monitor.c \
+ src/rt/monitor_.d \
src/rt/obj.d \
src/rt/qsort.d \
src/rt/qsort2.d \
@@ -283,6 +282,7 @@ SRC_D_MODULES = \
rt/cast_ \
rt/cmath2 \
rt/cover \
+ rt/critical_ \
rt/deh2 \
rt/dmain2 \
rt/invariant \
@@ -291,6 +291,7 @@ SRC_D_MODULES = \
rt/llmath \
rt/memory \
rt/memset \
+ rt/monitor_ \
rt/obj \
rt/qsort \
rt/switch_ \
@@ -343,8 +344,7 @@ SRC_D_MODULES = \
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux
-OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o $(OBJDIR)/complex.o \
-$(OBJDIR)/critical.o $(OBJDIR)/memory_osx.o $(OBJDIR)/monitor.o
+OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o $(OBJDIR)/complex.o $(OBJDIR)/memory_osx.o
DOCS=\
$(DOCDIR)/object.html \
View
176 src/rt/critical.c
@@ -1,176 +0,0 @@
-/**
- * Implementation of support routines for synchronized blocks.
- *
- * Copyright: Copyright Digital Mars 2000 - 2010.
- * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
- * Authors: Walter Bright, Sean Kelly
- */
-
-/* Copyright Digital Mars 2000 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-
-/* ================================= Win32 ============================ */
-
-#if _WIN32
-
-#include <windows.h>
-
-/******************************************
- * 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__ || __sun&&__SVR4
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-
-// 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
-
View
107 src/rt/mars.h
@@ -1,107 +0,0 @@
-/**
- * Common declarations for runtime implementation.
- *
- * Copyright: Copyright Digital Mars 2000 - 2010.
- * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
- * Authors: Walter Bright, Sean Kelly
- */
-
-/* Copyright Digital Mars 2000 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-#include <stddef.h>
-#include <sys/types.h>
-
-#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;
- ptrdiff_t 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
View
221 src/rt/monitor.c
@@ -1,221 +0,0 @@
-/**
- * Contains the implementation for object monitors.
- *
- * Copyright: Copyright Digital Mars 2000 - 2010.
- * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
- * Authors: Walter Bright, Sean Kelly
- */
-
-/* Copyright Digital Mars 2000 - 2010.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#if _WIN32
-#elif linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
-#define USE_PTHREADS 1
-#else
-#endif
-
-#if _WIN32
-#include <windows.h>
-#endif
-
-#if USE_PTHREADS
-#include <pthread.h>
-#endif
-
-#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
-
-#if _WIN32
- CRITICAL_SECTION mon;
-#endif
-
-#if USE_PTHREADS
- pthread_mutex_t mon;
-#endif
-} Monitor;
-
-#define MONPTR(h) (&((Monitor *)(h)->monitor)->mon)
-
-static volatile int inited;
-
-/* =============================== Win32 ============================ */
-
-#if _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);
- assert(h);
- Monitor *cs = NULL;
- 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);
-}
-
-int _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
-
-/* =============================== linux ============================ */
-
-#if USE_PTHREADS
-
-#ifdef linux
-# ifndef PTHREAD_MUTEX_RECURSIVE
-# define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
-# endif
-#endif
-
-// Includes attribute fixes from David Friedman's GDC port
-
-static pthread_mutex_t _monitor_critsec;
-static pthread_mutexattr_t _monitors_attr;
-
-void _STI_monitor_staticctor()
-{
- if (!inited)
- {
- pthread_mutexattr_init(&_monitors_attr);
- pthread_mutexattr_settype(&_monitors_attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&_monitor_critsec, &_monitors_attr);
- inited = 1;
- }
-}
-
-void _STD_monitor_staticdtor()
-{
- if (inited)
- { inited = 0;
- pthread_mutex_destroy(&_monitor_critsec);
- pthread_mutexattr_destroy(&_monitors_attr);
- }
-}
-
-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);
- assert(h);
- Monitor *cs = NULL;
- pthread_mutex_lock(&_monitor_critsec);
- if (!h->monitor)
- {
- cs = (Monitor *)calloc(sizeof(Monitor), 1);
- assert(cs);
- pthread_mutex_init(&cs->mon, & _monitors_attr);
- h->monitor = (void *)cs;
- cs->refs = 1;
- cs = NULL;
- }
- pthread_mutex_unlock(&_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));
- pthread_mutex_destroy(MONPTR(h));
- free((void *)h->monitor);
- h->monitor = NULL;
- //printf("-_d_monitor_destroy(%p)\n", h);
-}
-
-int _d_monitor_lock(Object *h)
-{
- //printf("+_d_monitor_acquire(%p)\n", h);
- assert(h && h->monitor && !(((Monitor*)h->monitor)->impl));
- pthread_mutex_lock(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));
- pthread_mutex_unlock(MONPTR(h));
- //printf("-_d_monitor_release(%p)\n", h);
-}
-
-#endif
View
17 win32.mak
@@ -149,7 +149,7 @@ MANIFEST= \
src\rt\compiler.d \
src\rt\complex.c \
src\rt\cover.d \
- src\rt\critical.c \
+ src\rt\critical_.d \
src\rt\deh.d \
src\rt\deh2.d \
src\rt\dmain2.d \
@@ -159,12 +159,11 @@ MANIFEST= \
src\rt\invariant_.d \
src\rt\lifetime.d \
src\rt\llmath.d \
- src\rt\mars.h \
src\rt\memory.d \
src\rt\memory_osx.c \
src\rt\memset.d \
src\rt\minit.asm \
- src\rt\monitor.c \
+ src\rt\monitor_.d \
src\rt\obj.d \
src\rt\qsort.d \
src\rt\qsort2.d \
@@ -275,6 +274,7 @@ SRCS= \
src\rt\arrayshort.d \
src\rt\cast_.d \
src\rt\cover.d \
+ src\rt\critical_.d \
src\rt\deh.d \
src\rt\dmain2.d \
src\rt\invariant.d \
@@ -283,6 +283,7 @@ SRCS= \
src\rt\llmath.d \
src\rt\memory.d \
src\rt\memset.d \
+ src\rt\monitor_.d \
src\rt\obj.d \
src\rt\qsort.d \
src\rt\switch_.d \
@@ -335,8 +336,8 @@ SRCS= \
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux
-OBJS= errno_c.obj complex.obj critical.obj monitor.obj src\rt\minit.obj
-OBJS_TO_DELETE= errno_c.obj complex.obj critical.obj monitor.obj
+OBJS= errno_c.obj complex.obj src\rt\minit.obj
+OBJS_TO_DELETE= errno_c.obj complex.obj
DOCS=\
$(DOCDIR)\object.html \
@@ -751,15 +752,9 @@ errno_c.obj : src\core\stdc\errno.c
complex.obj : src\rt\complex.c
$(CC) -c $(CFLAGS) src\rt\complex.c
-critical.obj : src\rt\critical.c
- $(CC) -c $(CFLAGS) src\rt\critical.c
-
src\rt\minit.obj : src\rt\minit.asm
$(CC) -c $(CFLAGS) src\rt\minit.asm
-monitor.obj : src\rt\monitor.c
- $(CC) -c $(CFLAGS) src\rt\monitor.c
-
################### gcstub generation #########################
$(GCSTUB) : src\gcstub\gc.d win32.mak
Please sign in to comment.
Something went wrong with that request. Please try again.