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.)
This commit is contained in:
Augustin Cavalier
2018-11-03 14:30:37 -04:00
parent 6f3f2e141c
commit 94064605f5
5 changed files with 37 additions and 1 deletions
@@ -41,6 +41,7 @@ KernelStaticLibrary libfreebsd11_network.a :
mbuf.c mbuf.c
mii.c mii.c
mutex.c mutex.c
pcpu.cpp
priv.cpp priv.cpp
smp.c smp.c
subr_autoconf.cpp subr_autoconf.cpp
@@ -17,7 +17,6 @@ struct mtx {
mutex lock; mutex lock;
thread_id owner; thread_id owner;
} mutex; } mutex;
int32 spinlock;
recursive_lock recursive; recursive_lock recursive;
} u; } u;
}; };
@@ -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 static inline void
mtx_unlock(struct mtx* mutex) mtx_unlock(struct mtx* mutex)
{ {
@@ -10,7 +10,9 @@
struct thread; struct thread;
int get_curcpu();
#define curcpu (get_curcpu())
#define curthread ((struct thread*)NULL) #define curthread ((struct thread*)NULL)
/* NOTE: Dereferencing curthread will crash, which is intentional. There is /* NOTE: Dereferencing curthread will crash, which is intentional. There is
no FreeBSD compatible struct thread and Haiku's should not be used as it no FreeBSD compatible struct thread and Haiku's should not be used as it
@@ -0,0 +1,18 @@
/*
* Copyright 2018, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <OS.h>
#include <smp.h>
extern "C" {
#include <compat/sys/pcpu.h>
};
int32_t
get_curcpu()
{
return smp_get_current_cpu();
}