freebsd_network: Remove the need for <kernel_c++_structs.h>.
Use sizeof()+roundup() to build a char[] of the correct size, and add a static_assert to ensure it stays so. The <kernel_c++_structs.h> header needs to have its dependency manually declared, and not all consumers of this file properly declared it as such. This then fixes a concurrent build problem. Fixes #17965 as this was the only consumer of this header.
This commit is contained in:
parent
8b61424d3b
commit
869de36dcd
@ -6,10 +6,6 @@ UsePrivateHeaders net ;
|
||||
UsePrivateKernelHeaders ;
|
||||
UseHeaders $(HAIKU_PRIVATE_KERNEL_HEADERS) : true ;
|
||||
|
||||
# Enabling C++ structures in C only code
|
||||
Includes [ FGristFiles kernel_c++_structs.h ]
|
||||
: <src!system!kernel>kernel_c++_struct_sizes.h ;
|
||||
|
||||
SubDirCcFlags [ FDefines _KERNEL=1 ] ;
|
||||
SubDirC++Flags [ FDefines _KERNEL=1 ] ;
|
||||
|
||||
|
@ -1,20 +1,28 @@
|
||||
/*
|
||||
* Copyright 2009, Colin Günther, coling@gmx.de.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
* Copyright 2023, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _FBSD_COMPAT_SYS_CONDVAR_H_
|
||||
#define _FBSD_COMPAT_SYS_CONDVAR_H_
|
||||
|
||||
|
||||
#include <kernel_c++_structs.h>
|
||||
#include <sys/param.h>
|
||||
#include <KernelExport.h>
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
|
||||
struct cv {
|
||||
struct ConditionVariable condition;
|
||||
// We cannot include <condition_variable.h> here as it is C++-only.
|
||||
char condition[roundup((sizeof(void*) * 5) + sizeof(spinlock) + sizeof(int32), sizeof(void*))];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define __cv_ConditionVariable(CV) reinterpret_cast<ConditionVariable*>(&(CV)->condition)
|
||||
#endif
|
||||
|
||||
|
||||
void cv_init(struct cv*, const char*);
|
||||
void cv_destroy(struct cv*);
|
||||
void cv_wait(struct cv*, struct mtx*);
|
||||
@ -24,4 +32,5 @@ void cv_signal(struct cv*);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
#endif /* _FBSD_COMPAT_SYS_CONDVAR_H_ */
|
||||
|
@ -1,27 +1,32 @@
|
||||
/*
|
||||
* Copyright 2022, Haiku, Inc. All rights reserved.
|
||||
* Copyright 2022-2023, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <compat/sys/mutex.h>
|
||||
#include <compat/sys/kernel.h>
|
||||
#include <compat/sys/condvar.h>
|
||||
}
|
||||
|
||||
#include <compat/sys/condvar.h>
|
||||
#include <condition_variable.h>
|
||||
|
||||
|
||||
static_assert(sizeof(cv::condition) == sizeof(ConditionVariable));
|
||||
|
||||
|
||||
void
|
||||
cv_init(struct cv* variable, const char* description)
|
||||
{
|
||||
variable->condition.Init(NULL, description);
|
||||
__cv_ConditionVariable(variable)->Init(NULL, description);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
cv_destroy(struct cv* variable)
|
||||
{
|
||||
variable->condition.NotifyAll();
|
||||
__cv_ConditionVariable(variable)->NotifyAll();
|
||||
|
||||
// Nothing else to do.
|
||||
}
|
||||
|
||||
@ -29,27 +34,28 @@ cv_destroy(struct cv* variable)
|
||||
void
|
||||
cv_signal(struct cv* variable)
|
||||
{
|
||||
variable->condition.NotifyOne();
|
||||
__cv_ConditionVariable(variable)->NotifyOne();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
cv_timedwait(struct cv* variable, struct mtx* mutex, int timeout)
|
||||
{
|
||||
int status;
|
||||
ConditionVariable* condition = __cv_ConditionVariable(variable);
|
||||
|
||||
const uint32 flags = timeout ? B_RELATIVE_TIMEOUT : 0;
|
||||
const bigtime_t bigtimeout = TICKS_2_USEC(timeout);
|
||||
int status;
|
||||
|
||||
if (mutex->type == MTX_RECURSE) {
|
||||
// Special case: let the ConditionVariable handle switching recursive locks.
|
||||
status = variable->condition.Wait(&mutex->u.recursive,
|
||||
status = condition->Wait(&mutex->u.recursive,
|
||||
flags, bigtimeout);
|
||||
return status;
|
||||
}
|
||||
|
||||
ConditionVariableEntry entry;
|
||||
variable->condition.Add(&entry);
|
||||
condition->Add(&entry);
|
||||
|
||||
mtx_unlock(mutex);
|
||||
|
||||
|
@ -3,10 +3,14 @@
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <compat/sys/systm.h>
|
||||
#include <compat/sys/kernel.h>
|
||||
#include <compat/sys/mutex.h>
|
||||
#include <compat/sys/condvar.h>
|
||||
}
|
||||
|
||||
#include <condition_variable.h>
|
||||
|
||||
|
||||
int
|
||||
@ -14,11 +18,11 @@ msleep(void* identifier, struct mtx* mutex, int priority,
|
||||
const char* description, int timeout)
|
||||
{
|
||||
struct cv channel;
|
||||
channel.condition.Publish(identifier, description);
|
||||
__cv_ConditionVariable(&channel)->Publish(identifier, description);
|
||||
|
||||
int status = cv_timedwait(&channel, mutex, timeout);
|
||||
|
||||
channel.condition.Unpublish();
|
||||
__cv_ConditionVariable(&channel)->Unpublish();
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user