Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/ibuclaw/druntime
Browse files Browse the repository at this point in the history
  • Loading branch information
braddr committed Feb 6, 2011
2 parents 5f8db8e + 6bdcb9e commit eddc043
Show file tree
Hide file tree
Showing 12 changed files with 465 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/core/sys/osx/mach/kern_return.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
module core.sys.osx.mach.kern_return;

version (OSX):

extern (C):

alias int kern_return_t;
Expand Down
2 changes: 2 additions & 0 deletions src/core/sys/osx/mach/port.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
module core.sys.osx.mach.port;

version (OSX):

extern (C):

version( X86 )
Expand Down
2 changes: 2 additions & 0 deletions src/core/sys/osx/mach/semaphore.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
module core.sys.osx.mach.semaphore;

version (OSX):

public import core.sys.osx.mach.kern_return;
public import core.sys.osx.mach.port;

Expand Down
2 changes: 2 additions & 0 deletions src/core/sys/osx/mach/thread_act.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
module core.sys.osx.mach.thread_act;

version (OSX):

public import core.sys.osx.mach.kern_return;
public import core.sys.osx.mach.port;

Expand Down
14 changes: 1 addition & 13 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,7 @@ private

void* getStackTop()
{
version( D_InlineAsm_X86 )
{
asm
{
naked;
mov EAX, ESP;
ret;
}
}
else
{
return rt_stackTop();
}
return rt_stackTop();
}


Expand Down
2 changes: 2 additions & 0 deletions src/gc/gcx.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private import gc.gcalloc;
private import cstdlib = core.stdc.stdlib : calloc, free, malloc, realloc;
private import core.stdc.string;

version (GNU) import gcc.builtins;

debug (PRINTF) import core.stdc.stdio : printf;
debug (COLLECT_PRINTF) import core.stdc.stdio : printf;
debug private import core.stdc.stdio;
Expand Down
2 changes: 1 addition & 1 deletion src/rt/critical.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void _STD_critical_term()

/* ================================= linux ============================ */

#if linux || __APPLE__ || __FreeBSD__
#if linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4

#include <stdio.h>
#include <stdlib.h>
Expand Down
199 changes: 199 additions & 0 deletions src/rt/critical_.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/**
* Implementation of support routines for synchronized blocks.
*
* Copyright: Copyright Digital Mars 2000 - 2011.
* 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 - 2011.
* 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)
*/
module rt.critical_;

private
{
debug(PRINTF) import core.stdc.stdio;
import core.stdc.stdlib;

version( linux )
{
version = USE_PTHREADS;
}
else version( FreeBSD )
{
version = USE_PTHREADS;
}
else version( OSX )
{
version = USE_PTHREADS;
}

version( Windows )
{
import core.sys.windows.windows;

/* 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.
*/
struct D_CRITICAL_SECTION
{
D_CRITICAL_SECTION *next;
CRITICAL_SECTION cs;
}
}
else version( USE_PTHREADS )
{
import core.sys.posix.pthread;

/* 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.
*/
struct D_CRITICAL_SECTION
{
D_CRITICAL_SECTION *next;
pthread_mutex_t cs;
}
}
else
{
static assert(0, "Unsupported platform");
}
}


/* ================================= Win32 ============================ */

version( Windows )
{
/******************************************
* Enter/exit critical section.
*/

static __gshared D_CRITICAL_SECTION *dcs_list;
static __gshared D_CRITICAL_SECTION critical_section;
static __gshared int inited;

extern (C) void _d_criticalenter(D_CRITICAL_SECTION *dcs)
{
debug(PRINTF) printf("_d_criticalenter(dcs = x%x)\n", 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);
}

extern (C) void _d_criticalexit(D_CRITICAL_SECTION *dcs)
{
debug(PRINTF) printf("_d_criticalexit(dcs = x%x)\n", dcs);
LeaveCriticalSection(&dcs.cs);
}

extern (C) void _STI_critical_init()
{
if (!inited)
{
debug(PRINTF) printf("_STI_critical_init()\n");
InitializeCriticalSection(&critical_section.cs);
dcs_list = &critical_section;
inited = 1;
}
}

extern (C) void _STD_critical_term()
{
if (inited)
{
debug(PRINTF) printf("_STI_critical_term()\n");
while (dcs_list)
{
debug(PRINTF) printf("\tlooping... %x\n", dcs_list);
DeleteCriticalSection(&dcs_list.cs);
dcs_list = dcs_list.next;
}
inited = 0;
}
}
}

/* ================================= linux ============================ */

version( USE_PTHREADS )
{
/******************************************
* Enter/exit critical section.
*/

static __gshared D_CRITICAL_SECTION *dcs_list;
static __gshared D_CRITICAL_SECTION critical_section;
static __gshared pthread_mutexattr_t _criticals_attr;

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)
{
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);
}

extern (C) void _d_criticalexit(D_CRITICAL_SECTION *dcs)
{
debug(PRINTF) printf("_d_criticalexit(dcs = x%x)\n", dcs);
pthread_mutex_unlock(&dcs.cs);
}

extern (C) void _STI_critical_init()
{
if (!dcs_list)
{
debug(PRINTF) 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, null);
dcs_list = &critical_section;
}
}

extern (C) void _STD_critical_term()
{
if (dcs_list)
{
debug(PRINTF) printf("_STI_critical_term()\n");
while (dcs_list)
{
debug(PRINTF) printf("\tlooping... %x\n", dcs_list);
pthread_mutex_destroy(&dcs_list.cs);
dcs_list = dcs_list.next;
}
}
}
}

3 changes: 2 additions & 1 deletion src/rt/mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* http://www.boost.org/LICENSE_1_0.txt)
*/
#include <stddef.h>
#include <sys/types.h>

#if __cplusplus
extern "C" {
Expand All @@ -30,7 +31,7 @@ typedef struct Interface
{
struct ClassInfo *classinfo;
struct Vtbl vtbl;
int offset;
ptrdiff_t offset;
} Interface;

typedef struct Object
Expand Down
8 changes: 8 additions & 0 deletions src/rt/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module rt.memory;

private
{
version( GNU )
{
import gcc.builtins;
}
version( linux )
{
version = SimpleLibcStackEnd;
Expand Down Expand Up @@ -143,6 +147,10 @@ extern (C) void* rt_stackTop()
ret;
}
}
else version( GNU )
{
return __builtin_frame_address(0);
}
else
{
static assert( false, "Architecture not supported." );
Expand Down
2 changes: 1 addition & 1 deletion src/rt/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <assert.h>

#if _WIN32
#elif linux || __APPLE__ || __FreeBSD__
#elif linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
#define USE_PTHREADS 1
#else
#endif
Expand Down
Loading

0 comments on commit eddc043

Please sign in to comment.