From 94064605f5e90504c01ac5abe15dcae37e8e3e40 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 3 Nov 2018 14:30:37 -0400 Subject: [PATCH] freebsd11_network: Add mtx_trylock() and curcpu. These are needed for the "non-legacy" TX path in ipro1000. Also remove the "spinlock" member from struct mtx; struct mtx_spin is different (and not implemented by us presently.) --- src/libs/compat/freebsd11_network/Jamfile | 1 + .../freebsd11_network/compat/sys/_mutex.h | 1 - .../freebsd11_network/compat/sys/mutex.h | 16 ++++++++++++++++ .../compat/freebsd11_network/compat/sys/pcpu.h | 2 ++ src/libs/compat/freebsd11_network/pcpu.cpp | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/libs/compat/freebsd11_network/pcpu.cpp diff --git a/src/libs/compat/freebsd11_network/Jamfile b/src/libs/compat/freebsd11_network/Jamfile index f1a6eafc44..2b1bd70392 100644 --- a/src/libs/compat/freebsd11_network/Jamfile +++ b/src/libs/compat/freebsd11_network/Jamfile @@ -41,6 +41,7 @@ KernelStaticLibrary libfreebsd11_network.a : mbuf.c mii.c mutex.c + pcpu.cpp priv.cpp smp.c subr_autoconf.cpp diff --git a/src/libs/compat/freebsd11_network/compat/sys/_mutex.h b/src/libs/compat/freebsd11_network/compat/sys/_mutex.h index 7d8e757c53..ebddbecaff 100644 --- a/src/libs/compat/freebsd11_network/compat/sys/_mutex.h +++ b/src/libs/compat/freebsd11_network/compat/sys/_mutex.h @@ -17,7 +17,6 @@ struct mtx { mutex lock; thread_id owner; } mutex; - int32 spinlock; recursive_lock recursive; } u; }; diff --git a/src/libs/compat/freebsd11_network/compat/sys/mutex.h b/src/libs/compat/freebsd11_network/compat/sys/mutex.h index 2666030fc8..757496a6a2 100644 --- a/src/libs/compat/freebsd11_network/compat/sys/mutex.h +++ b/src/libs/compat/freebsd11_network/compat/sys/mutex.h @@ -54,6 +54,22 @@ mtx_lock(struct mtx* mutex) } +static inline int +mtx_trylock(struct mtx* mutex) +{ + if (mutex->type == MTX_DEF) { + if (mutex_trylock(&mutex->u.mutex.lock) != B_OK) + return 0; + mutex->u.mutex.owner = find_thread(NULL); + return 1; + } else if (mutex->type == MTX_RECURSE) { + if (recursive_lock_trylock(&mutex->u.recursive) != B_OK) + return 0; + return 1; + } +} + + static inline void mtx_unlock(struct mtx* mutex) { diff --git a/src/libs/compat/freebsd11_network/compat/sys/pcpu.h b/src/libs/compat/freebsd11_network/compat/sys/pcpu.h index 858d57b7f8..9900e8e5f2 100644 --- a/src/libs/compat/freebsd11_network/compat/sys/pcpu.h +++ b/src/libs/compat/freebsd11_network/compat/sys/pcpu.h @@ -10,7 +10,9 @@ struct thread; +int get_curcpu(); +#define curcpu (get_curcpu()) #define curthread ((struct thread*)NULL) /* NOTE: Dereferencing curthread will crash, which is intentional. There is no FreeBSD compatible struct thread and Haiku's should not be used as it diff --git a/src/libs/compat/freebsd11_network/pcpu.cpp b/src/libs/compat/freebsd11_network/pcpu.cpp new file mode 100644 index 0000000000..5a6bf7bd3c --- /dev/null +++ b/src/libs/compat/freebsd11_network/pcpu.cpp @@ -0,0 +1,18 @@ +/* + * Copyright 2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include + +extern "C" { +#include +}; + + +int32_t +get_curcpu() +{ + return smp_get_current_cpu(); +}