Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mak/COPY
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ COPY=\
$(IMPDIR)\core\sys\freebsd\execinfo.d \
\
$(IMPDIR)\core\sys\freebsd\sys\cdefs.d \
$(IMPDIR)\core\sys\freebsd\pthread_np.d \
$(IMPDIR)\core\sys\freebsd\sys\_bitset.d \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these modules have an underscore prepended? Just to match what the C files do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

$(IMPDIR)\core\sys\freebsd\sys\_cpuset.d \
$(IMPDIR)\core\sys\freebsd\sys\elf.d \
$(IMPDIR)\core\sys\freebsd\sys\elf_common.d \
$(IMPDIR)\core\sys\freebsd\sys\elf32.d \
$(IMPDIR)\core\sys\freebsd\sys\elf64.d \
$(IMPDIR)\core\sys\freebsd\sys\elf_common.d \
$(IMPDIR)\core\sys\freebsd\sys\event.d \
$(IMPDIR)\core\sys\freebsd\sys\link_elf.d \
$(IMPDIR)\core\sys\freebsd\sys\mman.d \
Expand Down
44 changes: 44 additions & 0 deletions src/core/sys/freebsd/pthread_np.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* D header file for FreeBSD.
*
* Authors: Martin Nowak
*/
module core.sys.freebsd.pthread;

version (FreeBSD):
extern (C) nothrow @nogc:

public import core.sys.posix.sys.types;
// TODO: add full core.sys.freebsd.sys.cpuset;
public import core.sys.freebsd.sys._cpuset;
public import core.sys.posix.time;

enum __BSD_VISIBLE = true;

alias pthread_switch_routine_t = void function(pthread_t, pthread_t);

int pthread_attr_setcreatesuspend_np(pthread_attr_t *);
int pthread_attr_get_np(pthread_t, pthread_attr_t *);
int pthread_attr_getaffinity_np(const(pthread_attr_t)*, size_t, cpuset_t *);
int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const(cpuset_t)*);
int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *);
int pthread_getthreadid_np();
int pthread_main_np();
int pthread_multi_np();
int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
void pthread_resume_all_np();
int pthread_resume_np(pthread_t);
void pthread_set_name_np(pthread_t, const(char)*);
int pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count);
int pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count);
int pthread_mutex_getyieldloops_np(pthread_mutex_t *mutex, int *count);
int pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count);
int pthread_mutex_isowned_np(pthread_mutex_t *mutex);
int pthread_setaffinity_np(pthread_t, size_t, const(cpuset_t)*);
int pthread_single_np();
void pthread_suspend_all_np();
int pthread_suspend_np(pthread_t);
int pthread_switch_add_np(pthread_switch_routine_t);
int pthread_switch_delete_np(pthread_switch_routine_t);
int pthread_timedjoin_np(pthread_t, void **, const(timespec)*);
45 changes: 45 additions & 0 deletions src/core/sys/freebsd/sys/_bitset.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* D header file for FreeBSD.
*
* Authors: Martin Nowak
*/
module core.sys.freebsd.sys._bitset;

version (FreeBSD):
extern (C) pure nothrow @nogc:

import core.stdc.config : c_long;

enum NBBY = 8; // number of bits per byte

enum _BITSET_BITS = c_long.sizeof * NBBY;

enum __bitset_words(size_t s) = (s + _BITSET_BITS - 1) / _BITSET_BITS;

c_long __bitset_mask(size_t s)(size_t n)
{
static if (__bitset_words!s == 1)
return (cast(c_long)1) << n;
else
return (cast(c_long)1) << n % _BITSET_BITS;
}

size_t __bitset_word(size_t s)(size_t n)
{
static if (__bitset_words!s == 1)
return 0;
else
return n / _BITSET_BITS;
}

struct BITSET_DEFINE(size_t s)
{
c_long[__bitset_words!s] __bits;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are double-underscore symbols supposed to be reserved only for the compiler or also druntime?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just matches the C header.

}

// no idea how to translate those
//#define BITSET_T_INITIALIZER(x) \
// { .__bits = { x } }
//
//#define BITSET_FSET(n) \
// [ 0 ... ((n) - 1) ] = (-1L)
29 changes: 29 additions & 0 deletions src/core/sys/freebsd/sys/_cpuset.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* D header file for FreeBSD.
*
* Authors: Martin Nowak
*/
module core.sys.freebsd.sys._cpuset;

version (FreeBSD):
extern (C) pure nothrow @nogc:

public import core.sys.freebsd.sys._bitset;

static if (is(typeof(_KERNEL)))
alias CPU_SETSIZE = MAXCPU;

enum CPU_MAXSIZE = 256;

static if (!is(typeof(CPU_SETSIZE)))
alias CPU_SETSIZE = CPU_MAXSIZE;

enum _NCPUBITS = _BITSET_BITS;
enum _NCPUWORDS = __bitset_words!CPU_SETSIZE;

alias _cpuset = BITSET_DEFINE!(CPU_SETSIZE);
alias cpuset_t = _cpuset;

// no idea how to translate those
//#define CPUSET_FSET BITSET_FSET(_NCPUWORDS)
//#define CPUSET_T_INITIALIZER BITSET_T_INITIALIZER
9 changes: 9 additions & 0 deletions win32.mak
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,21 @@ $(IMPDIR)\core\sys\freebsd\dlfcn.d : src\core\sys\freebsd\dlfcn.d
$(IMPDIR)\core\sys\freebsd\execinfo.d : src\core\sys\freebsd\execinfo.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\pthread_np.d : src\core\sys\freebsd\pthread_np.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\time.d : src\core\sys\freebsd\time.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\cdefs.d : src\core\sys\freebsd\sys\cdefs.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\_bitset.d : src\core\sys\freebsd\sys\_bitset.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\_cpuset.d : src\core\sys\freebsd\sys\_cpuset.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\elf.d : src\core\sys\freebsd\sys\elf.d
copy $** $@

Expand Down
9 changes: 9 additions & 0 deletions win64.mak
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,21 @@ $(IMPDIR)\core\sys\freebsd\dlfcn.d : src\core\sys\freebsd\dlfcn.d
$(IMPDIR)\core\sys\freebsd\execinfo.d : src\core\sys\freebsd\execinfo.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\pthread_np.d : src\core\sys\freebsd\pthread_np.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\time.d : src\core\sys\freebsd\time.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\cdefs.d : src\core\sys\freebsd\sys\cdefs.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\_bitset.d : src\core\sys\freebsd\sys\_bitset.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\_cpuset.d : src\core\sys\freebsd\sys\_cpuset.d
copy $** $@

$(IMPDIR)\core\sys\freebsd\sys\elf.d : src\core\sys\freebsd\sys\elf.d
copy $** $@

Expand Down