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

Commit

Permalink
Merge pull request #1060 from MartinNowak/pthread_np
Browse files Browse the repository at this point in the history
add core.sys.freebsd.pthread_np
  • Loading branch information
DmitryOlshansky committed Jun 4, 2016
2 parents 6e16494 + 44eb52f commit c58585a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mak/COPY
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 \
$(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
@@ -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
@@ -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;
}

// 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
@@ -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
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
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

0 comments on commit c58585a

Please sign in to comment.