freebsd_network: Lots of additions and modifications for iflib.

This commit is contained in:
Augustin Cavalier 2018-12-29 20:39:50 -05:00
parent 88c3c4fa49
commit 8267c19341
26 changed files with 262 additions and 49 deletions

View File

@ -79,3 +79,10 @@ publishedConditionNotifyAll(const void* waitChannel)
{ {
ConditionVariable::NotifyAll(waitChannel, B_OK); ConditionVariable::NotifyAll(waitChannel, B_OK);
} }
void
publishedConditionNotifyOne(const void* waitChannel)
{
ConditionVariable::NotifyOne(waitChannel, B_OK);
}

View File

@ -18,6 +18,7 @@ void conditionWait(struct cv*);
void conditionNotifyOne(struct cv*); void conditionNotifyOne(struct cv*);
int publishedConditionTimedWait(const void*, const int); int publishedConditionTimedWait(const void*, const int);
void publishedConditionNotifyAll(const void*); void publishedConditionNotifyAll(const void*);
void publishedConditionNotifyOne(const void*);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -48,7 +48,7 @@ extern "C" {
struct internal_intr { struct internal_intr {
device_t dev; device_t dev;
driver_filter_t filter; driver_filter_t* filter;
driver_intr_t *handler; driver_intr_t *handler;
void *arg; void *arg;
int irq; int irq;
@ -325,7 +325,7 @@ free_internal_intr(struct internal_intr *intr)
int int
bus_setup_intr(device_t dev, struct resource *res, int flags, bus_setup_intr(device_t dev, struct resource *res, int flags,
driver_filter_t filter, driver_intr_t handler, void *arg, void **_cookie) driver_filter_t* filter, driver_intr_t handler, void *arg, void **_cookie)
{ {
/* TODO check MPSAFE etc */ /* TODO check MPSAFE etc */

View File

@ -265,6 +265,13 @@ device_get_softc(device_t dev)
} }
void
device_set_softc(device_t dev, void *softc)
{
dev->softc = softc;
}
u_int32_t u_int32_t
device_get_flags(device_t dev) device_get_flags(device_t dev)
{ {
@ -277,11 +284,11 @@ device_set_driver(device_t dev, driver_t *driver)
{ {
int i; int i;
dev->softc = malloc(driver->softc_size); dev->softc = malloc(driver->size);
if (dev->softc == NULL) if (dev->softc == NULL)
return -1; return -1;
memset(dev->softc, 0, driver->softc_size); memset(dev->softc, 0, driver->size);
dev->driver = driver; dev->driver = driver;
for (i = 0; driver->methods[i].name != NULL; i++) { for (i = 0; driver->methods[i].name != NULL; i++) {

View File

@ -9,27 +9,27 @@
typedef void led_t(void*, int); typedef void led_t(void*, int);
static struct cdev* static inline struct cdev*
led_create_state(led_t* func, void* priv, char const* name, int state) led_create_state(led_t* func, void* priv, char const* name, int state)
{ {
return NULL; return NULL;
} }
static struct cdev* static inline struct cdev*
led_create(led_t* func, void* priv, char const* name) led_create(led_t* func, void* priv, char const* name)
{ {
return NULL; return NULL;
} }
static void static inline void
led_destroy(struct cdev* dev) led_destroy(struct cdev* dev)
{ {
} }
static int static inline int
led_set(char const* name, char const* cmd) led_set(char const* name, char const* cmd)
{ {
return -1; return -1;

View File

@ -13,7 +13,7 @@
#include <sys/time.h> #include <sys/time.h>
#define IF_Kbps(x) ((x) * 1000) #define IF_Kbps(x) ((uintmax_t)(x) * 1000)
#define IF_Mbps(x) (IF_Kbps((x) * 1000)) #define IF_Mbps(x) (IF_Kbps((x) * 1000))
#define IF_Gbps(x) (IF_Mbps((x) * 1000)) #define IF_Gbps(x) (IF_Mbps((x) * 1000))
@ -52,7 +52,7 @@
#define IFCAP_CANTCHANGE (IFCAP_NETMAP) #define IFCAP_CANTCHANGE (IFCAP_NETMAP)
/* Interface flags */ /* interface flags -- these extend the Haiku-native ones from posix/net/if.h */
#define IFF_DRV_RUNNING 0x00010000 #define IFF_DRV_RUNNING 0x00010000
#define IFF_DRV_OACTIVE 0x00020000 #define IFF_DRV_OACTIVE 0x00020000
#define IFF_LINK0 0x00040000 /* per link layer defined bit */ #define IFF_LINK0 0x00040000 /* per link layer defined bit */
@ -60,6 +60,7 @@
#define IFF_LINK2 0x00100000 /* per link layer defined bit */ #define IFF_LINK2 0x00100000 /* per link layer defined bit */
#define IFF_DEBUG 0x00200000 #define IFF_DEBUG 0x00200000
#define IFF_MONITOR 0x00400000 /* (n) user-requested monitor mode */ #define IFF_MONITOR 0x00400000 /* (n) user-requested monitor mode */
#define IFF_NOGROUP 0x00800000 /* (n) interface is not part of any groups */
#define LINK_STATE_UNKNOWN 0 #define LINK_STATE_UNKNOWN 0
#define LINK_STATE_DOWN 1 #define LINK_STATE_DOWN 1
@ -113,6 +114,19 @@ struct ifdrv {
void* ifd_data; void* ifd_data;
}; };
/*
* Structure used to request i2c data
* from interface transceivers.
*/
struct ifi2creq {
uint8_t dev_addr; /* i2c address (0xA0, 0xA2) */
uint8_t offset; /* read offset */
uint8_t len; /* read length */
uint8_t spare0;
uint32_t spare1;
uint8_t data[8]; /* read buffer */
};
#ifdef _KERNEL #ifdef _KERNEL
/* TODO: this should go away soon. */ /* TODO: this should go away soon. */
# include <net/if_var.h> # include <net/if_var.h>

View File

@ -8,6 +8,7 @@
#include <lock.h> #include <lock.h>
#include <KernelExport.h>
struct mtx { struct mtx {
@ -18,6 +19,10 @@ struct mtx {
thread_id owner; thread_id owner;
} mutex; } mutex;
recursive_lock recursive; recursive_lock recursive;
struct {
spinlock lock;
cpu_status state;
} spinlock;
} u; } u;
}; };

View File

@ -78,7 +78,7 @@ int bus_generic_suspend(device_t dev);
int bus_generic_resume(device_t dev); int bus_generic_resume(device_t dev);
void bus_generic_shutdown(device_t dev); void bus_generic_shutdown(device_t dev);
typedef int (*driver_filter_t)(void *); typedef int (driver_filter_t)(void *arg);
typedef void driver_intr_t(void *); typedef void driver_intr_t(void *);
@ -113,7 +113,7 @@ bus_alloc_resource_anywhere(device_t dev, int type, int *rid,
bus_dma_tag_t bus_get_dma_tag(device_t dev); bus_dma_tag_t bus_get_dma_tag(device_t dev);
int bus_setup_intr(device_t dev, struct resource *r, int flags, int bus_setup_intr(device_t dev, struct resource *r, int flags,
driver_filter_t filter, driver_intr_t handler, void *arg, void **_cookie); driver_filter_t* filter, driver_intr_t handler, void *arg, void **_cookie);
int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); int bus_teardown_intr(device_t dev, struct resource *r, void *cookie);
int bus_bind_intr(device_t dev, struct resource *r, int cpu); int bus_bind_intr(device_t dev, struct resource *r, int cpu);
int bus_describe_intr(device_t dev, struct resource *irq, void *cookie, int bus_describe_intr(device_t dev, struct resource *irq, void *cookie,
@ -123,6 +123,7 @@ const char *device_get_name(device_t dev);
const char *device_get_nameunit(device_t dev); const char *device_get_nameunit(device_t dev);
int device_get_unit(device_t dev); int device_get_unit(device_t dev);
void *device_get_softc(device_t dev); void *device_get_softc(device_t dev);
void device_set_softc(device_t dev, void *softc);
int device_printf(device_t dev, const char *, ...) __printflike(2, 3); int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
void device_set_desc(device_t dev, const char *desc); void device_set_desc(device_t dev, const char *desc);
void device_set_desc_copy(device_t dev, const char *desc); void device_set_desc_copy(device_t dev, const char *desc);

View File

@ -18,12 +18,14 @@
void callout_init(struct callout *c, int mpsafe); void callout_init(struct callout *c, int mpsafe);
void callout_init_mtx(struct callout *c, struct mtx *mutex, int flags); void callout_init_mtx(struct callout *c, struct mtx *mutex, int flags);
/* Time values are in ticks, see compat/sys/kernel.h for its definition */
int callout_schedule(struct callout *c, int _ticks); int callout_schedule(struct callout *c, int _ticks);
int callout_reset(struct callout *c, int _ticks, void (*func)(void *), void *arg); int callout_reset(struct callout *c, int _ticks, void (*func)(void *), void *arg);
int callout_pending(struct callout *c); int callout_pending(struct callout *c);
int callout_active(struct callout *c); int callout_active(struct callout *c);
#define callout_reset_on(c, to_ticks, fn, arg, cpu) \
callout_reset(c, to_ticks, fn, arg)
#define callout_drain(c) _callout_stop_safe(c, 1) #define callout_drain(c) _callout_stop_safe(c, 1)
#define callout_stop(c) _callout_stop_safe(c, 0) #define callout_stop(c) _callout_stop_safe(c, 0)
int _callout_stop_safe(struct callout *c, int safe); int _callout_stop_safe(struct callout *c, int safe);

View File

@ -264,6 +264,21 @@
#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg)))
#endif #endif
/*
* C99 Static array indices in function parameter declarations. Syntax such as:
* void bar(int myArray[static 10]);
* is allowed in C99 but not in C++. Define __min_size appropriately so
* headers using it can be compiled in either language. Use like this:
* void bar(int myArray[__min_size(10)]);
*/
#if !defined(__cplusplus) && \
(defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \
(!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901))
#define __min_size(x) static (x)
#else
#define __min_size(x) (x)
#endif
#if __GNUC_PREREQ__(3, 1) #if __GNUC_PREREQ__(3, 1)
#define __noinline __attribute__ ((__noinline__)) #define __noinline __attribute__ ((__noinline__))
#else #else

View File

@ -58,7 +58,7 @@ typedef struct device_method device_method_t;
typedef struct { typedef struct {
const char *name; const char *name;
device_method_t *methods; device_method_t *methods;
size_t softc_size; size_t size;
} driver_t; } driver_t;
#define DRIVER_MODULE_NAME(name, busname) \ #define DRIVER_MODULE_NAME(name, busname) \

View File

@ -0,0 +1,16 @@
/*
* Copyright 2018, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _FBSD_COMPAT_SYS_LOCK_H_
#define _FBSD_COMPAT_SYS_LOCK_H_
#define MPASS(ex) MPASS4(ex, #ex, __FILE__, __LINE__)
#define MPASS2(ex, what) MPASS4(ex, what, __FILE__, __LINE__)
#define MPASS3(ex, file, line) MPASS4(ex, #ex, file, line)
#define MPASS4(ex, what, file, line) \
KASSERT((ex), ("assert %s failed at %s:%d", what, file, line))
#endif /* _FBSD_COMPAT_SYS_LOCK_H_ */

View File

@ -153,6 +153,65 @@ m_extrefcnt(struct mbuf *m)
*m->m_ext.ext_cnt); *m->m_ext.ext_cnt);
} }
static __inline int
m_gettype(int size)
{
int type;
switch (size) {
case MCLBYTES:
type = EXT_CLUSTER;
break;
#if MJUMPAGESIZE != MCLBYTES
case MJUMPAGESIZE:
type = EXT_JUMBOP;
break;
#endif
case MJUM9BYTES:
type = EXT_JUMBO9;
break;
default:
panic("%s: invalid cluster size %d", __func__, size);
}
return (type);
}
/*
* XXX: m_cljset() is a dangerous API. One must attach only a new,
* unreferenced cluster to an mbuf(9). It is not possible to assert
* that, so care can be taken only by users of the API.
*/
static __inline void
m_cljset(struct mbuf *m, void *cl, int type)
{
int size;
switch (type) {
case EXT_CLUSTER:
size = MCLBYTES;
break;
#if MJUMPAGESIZE != MCLBYTES
case EXT_JUMBOP:
size = MJUMPAGESIZE;
break;
#endif
case EXT_JUMBO9:
size = MJUM9BYTES;
break;
default:
panic("%s: unknown cluster type %d", __func__, type);
break;
}
m->m_data = m->m_ext.ext_buf = cl;
m->m_ext.ext_size = size;
m->m_ext.ext_type = type;
m->m_ext.ext_flags = EXT_FLAG_EMBREF;
m->m_ext.ext_count = 1;
m->m_flags |= M_EXT;
}
/* mbufq */ /* mbufq */
struct mbufq { struct mbufq {

View File

@ -24,7 +24,9 @@
#define M_TRYWAIT M_WAITOK #define M_TRYWAIT M_WAITOK
#define M_WAIT M_WAITOK #define M_WAIT M_WAITOK
/* mbuf types describing the content of the mbuf (including external storage). */
#define MT_DATA 1 #define MT_DATA 1
#define MT_NOINIT 255 /* not a type, a flag to allocate a non-initialized mbuf */
/* /*
* mbuf flags of global significance and layer crossing. * mbuf flags of global significance and layer crossing.
@ -273,6 +275,9 @@ struct mbuf {
#define m_pktdat M_dat.MH.MH_dat.MH_databuf #define m_pktdat M_dat.MH.MH_dat.MH_databuf
#define m_dat M_dat.M_databuf #define m_dat M_dat.M_databuf
int m_init(struct mbuf *m, int how, short type, int flags);
int m_pkthdr_init(struct mbuf *m, int how);
void m_catpkt(struct mbuf *m, struct mbuf *n); void m_catpkt(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf*, int); void m_adj(struct mbuf*, int);
int m_append(struct mbuf*, int, c_caddr_t); int m_append(struct mbuf*, int, c_caddr_t);

View File

@ -8,6 +8,7 @@
#include <sys/haiku-module.h> #include <sys/haiku-module.h>
#include <kernel/int.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/_mutex.h> #include <sys/_mutex.h>
@ -23,16 +24,19 @@
#define mtx_assert(mtx, what) #define mtx_assert(mtx, what)
#define MTX_DEF 0x0000 #define MTX_DEF 0x00000000
#define MTX_RECURSE 0x0004 #define MTX_SPIN 0x00000001
#define MTX_QUIET 0x40000 #define MTX_RECURSE 0x00000004
#define MTX_DUPOK 0x400000 #define MTX_QUIET 0x00040000
#define MTX_DUPOK 0x00400000
#define MTX_NETWORK_LOCK "network driver" #define MTX_NETWORK_LOCK "network driver"
#define NET_LOCK_GIANT()
#define NET_UNLOCK_GIANT() /* on FreeBSD these are different functions */
#define mtx_lock_spin(x) mtx_lock(x)
#define mtx_unlock_spin(x) mtx_unlock(x)
extern struct mtx Giant; extern struct mtx Giant;
@ -49,8 +53,13 @@ mtx_lock(struct mtx* mutex)
if (mutex->type == MTX_DEF) { if (mutex->type == MTX_DEF) {
mutex_lock(&mutex->u.mutex.lock); mutex_lock(&mutex->u.mutex.lock);
mutex->u.mutex.owner = find_thread(NULL); mutex->u.mutex.owner = find_thread(NULL);
} else if (mutex->type == MTX_RECURSE) } else if (mutex->type == MTX_RECURSE) {
recursive_lock_lock(&mutex->u.recursive); recursive_lock_lock(&mutex->u.recursive);
} else if (mutex->type == MTX_SPIN) {
cpu_status status = disable_interrupts();
acquire_spinlock(&mutex->u.spinlock.lock);
mutex->u.spinlock.state = status;
}
} }
@ -66,6 +75,8 @@ mtx_trylock(struct mtx* mutex)
if (recursive_lock_trylock(&mutex->u.recursive) != B_OK) if (recursive_lock_trylock(&mutex->u.recursive) != B_OK)
return 0; return 0;
return 1; return 1;
} else if (mutex->type == MTX_SPIN) {
return 0;
} }
return 0; return 0;
} }
@ -77,8 +88,13 @@ mtx_unlock(struct mtx* mutex)
if (mutex->type == MTX_DEF) { if (mutex->type == MTX_DEF) {
mutex->u.mutex.owner = -1; mutex->u.mutex.owner = -1;
mutex_unlock(&mutex->u.mutex.lock); mutex_unlock(&mutex->u.mutex.lock);
} else if (mutex->type == MTX_RECURSE) } else if (mutex->type == MTX_RECURSE) {
recursive_lock_unlock(&mutex->u.recursive); recursive_lock_unlock(&mutex->u.recursive);
} else if (mutex->type == MTX_SPIN) {
cpu_status status = mutex->u.spinlock.state;
release_spinlock(&mutex->u.spinlock.lock);
restore_interrupts(status);
}
} }

View File

@ -17,7 +17,7 @@
/* The version this compatibility layer is based on */ /* The version this compatibility layer is based on */
#define __FreeBSD_version 1101000 #define __FreeBSD_version 1200000
#define MAXBSIZE 0x10000 #define MAXBSIZE 0x10000
@ -61,6 +61,16 @@
#error Need definition of ALIGNED_POINTER for this arch! #error Need definition of ALIGNED_POINTER for this arch!
#endif #endif
/* defined in arch_cpu.h which we can't include here as it's C++ */
#if defined(__x86_64__) || defined(__i386__)
#define CACHE_LINE_SIZE 64
#else
#error Need definition of CACHE_LINE_SIZE for this arch!
#endif
/* defined in platform_kernel_args.h as SMP_MAX_CPUS */
#define MAXCPU 64 /* SMP_MAX_CPUS */
/* Macros for counting and rounding. */ /* Macros for counting and rounding. */
#ifndef howmany #ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y)) #define howmany(x, y) (((x)+((y)-1))/(y))

View File

@ -1,12 +1,19 @@
/* /*
* Copyright 2009 Haiku Inc. All rights reserved. * Copyright 2009-2018, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _FBSD_COMPAT_SYS_PRIORITY_H_ #ifndef _FBSD_COMPAT_SYS_PRIORITY_H_
#define _FBSD_COMPAT_SYS_PRIORITY_H_ #define _FBSD_COMPAT_SYS_PRIORITY_H_
#include <OS.h>
#define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 9)
#define PI_SOFT (B_REAL_TIME_DISPLAY_PRIORITY - 1)
#define PRI_MIN_KERN (64) #define PRI_MIN_KERN (64)
#define PZERO (PRI_MIN_KERN + 20) #define PZERO (PRI_MIN_KERN + 20)
#define PWAIT (PRI_MIN_KERN + 28)
#endif /* _FBSD_COMPAT_SYS_PRIORITY_H_ */ #endif /* _FBSD_COMPAT_SYS_PRIORITY_H_ */

View File

@ -0,0 +1,27 @@
/*
* Copyright 2018, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Augustin Cavalier <waddlesplash>
*/
#ifndef _FBSD_COMPAT_SYS_SX_H_
#define _FBSD_COMPAT_SYS_SX_H_
#include <lock.h>
struct sx {
rw_lock l;
};
#define sx_init(lock, name) rw_lock_init(&(lock)->l, name)
#define sx_xlock(lock) rw_lock_write_lock(&(lock)->l)
#define sx_xunlock(lock) rw_lock_write_unlock(&(lock)->l)
#define sx_destroy(lock) rw_lock_destroy(&(lock)->l)
#define sx_assert(sx, what)
#endif /* _FBSD_COMPAT_SYS_SX_H_ */

View File

@ -56,7 +56,10 @@ int printf(const char *format, ...) __printflike(1, 2);
snooze(n); \ snooze(n); \
} while (0) } while (0)
#define cold 0
void wakeup(void *); void wakeup(void *);
void wakeup_one(void *);
#ifndef CTASSERT /* Allow lint to override */ #ifndef CTASSERT /* Allow lint to override */
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
@ -96,6 +99,8 @@ int _pause(const char *, int);
#define pause(waitMessage, timeout) _pause((waitMessage), (timeout)) #define pause(waitMessage, timeout) _pause((waitMessage), (timeout))
#define tsleep(channel, priority, waitMessage, timeout) \ #define tsleep(channel, priority, waitMessage, timeout) \
msleep((channel), NULL, (priority), (waitMessage), (timeout)) msleep((channel), NULL, (priority), (waitMessage), (timeout))
#define msleep_spin(chan, mtx, wmesg, timo) \
msleep(chan, mtx, PZERO, wmesg, timo)
#define mtx_sleep msleep #define mtx_sleep msleep
void critical_enter(void); void critical_enter(void);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007 Haiku Inc. All rights reserved. * Copyright 2007-2018, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _FBSD_COMPAT_SYS_TASKQUEUE_H_ #ifndef _FBSD_COMPAT_SYS_TASKQUEUE_H_
@ -11,9 +11,6 @@
#include <sys/callout.h> #include <sys/callout.h>
#define PI_NET (B_REAL_TIME_DISPLAY_PRIORITY - 1)
struct timeout_task { struct timeout_task {
struct taskqueue *q; struct taskqueue *q;
struct task t; struct task t;
@ -21,6 +18,7 @@ struct timeout_task {
int f; int f;
}; };
#define TASKQUEUE_NAMELEN 64
typedef void (*taskqueue_enqueue_fn)(void *context); typedef void (*taskqueue_enqueue_fn)(void *context);

View File

@ -42,24 +42,26 @@ m_to_oc_flags(int how)
} }
static int int
construct_mbuf(struct mbuf *memoryBuffer, short type, int flags) m_init(struct mbuf *m, int how, short type, int flags)
{ {
memoryBuffer->m_next = NULL; int error;
memoryBuffer->m_nextpkt = NULL;
memoryBuffer->m_len = 0;
memoryBuffer->m_flags = flags;
memoryBuffer->m_type = type;
if (flags & M_PKTHDR) {
memoryBuffer->m_data = memoryBuffer->m_pktdat;
memset(&memoryBuffer->m_pkthdr, 0, sizeof(memoryBuffer->m_pkthdr));
SLIST_INIT(&memoryBuffer->m_pkthdr.tags);
} else {
memoryBuffer->m_data = memoryBuffer->m_dat;
}
if (type == MT_NOINIT)
return 0; return 0;
m->m_next = NULL;
m->m_nextpkt = NULL;
m->m_data = m->m_dat;
m->m_len = 0;
m->m_flags = flags;
m->m_type = type;
if (flags & M_PKTHDR)
error = m_pkthdr_init(m, how);
else
error = 0;
return (error);
} }
@ -107,7 +109,8 @@ construct_ext_mbuf(struct mbuf *memoryBuffer, int how)
static int static int
construct_pkt_mbuf(int how, struct mbuf *memoryBuffer, short type, int flags) construct_pkt_mbuf(int how, struct mbuf *memoryBuffer, short type, int flags)
{ {
construct_mbuf(memoryBuffer, type, flags); if (m_init(memoryBuffer, how, type, flags) < 0)
return -1;
if (construct_ext_mbuf(memoryBuffer, how) < 0) if (construct_ext_mbuf(memoryBuffer, how) < 0)
return -1; return -1;
memoryBuffer->m_ext.ext_type = EXT_CLUSTER; memoryBuffer->m_ext.ext_type = EXT_CLUSTER;
@ -140,7 +143,7 @@ _m_get(int how, short type, int flags)
if (memoryBuffer == NULL) if (memoryBuffer == NULL)
return NULL; return NULL;
construct_mbuf(memoryBuffer, type, flags); m_init(memoryBuffer, how, type, flags);
return memoryBuffer; return memoryBuffer;
} }
@ -184,7 +187,10 @@ m_getjcl(int how, short type, int flags, int size)
(struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how)); (struct mbuf *)object_cache_alloc(sMBufCache, m_to_oc_flags(how));
if (memoryBuffer == NULL) if (memoryBuffer == NULL)
return NULL; return NULL;
construct_mbuf(memoryBuffer, type, flags); if (m_init(memoryBuffer, how, type, flags) < 0) {
object_cache_free(sMBufCache, memoryBuffer, 0);
return NULL;
}
if (construct_ext_sized_mbuf(memoryBuffer, how, size) < 0) { if (construct_ext_sized_mbuf(memoryBuffer, how, size) < 0) {
object_cache_free(sMBufCache, memoryBuffer, 0); object_cache_free(sMBufCache, memoryBuffer, 0);
return NULL; return NULL;

View File

@ -24,12 +24,15 @@ mtx_init(struct mtx *mutex, const char *name, const char *type,
if ((options & MTX_RECURSE) != 0) { if ((options & MTX_RECURSE) != 0) {
recursive_lock_init_etc(&mutex->u.recursive, name, recursive_lock_init_etc(&mutex->u.recursive, name,
MUTEX_FLAG_CLONE_NAME); MUTEX_FLAG_CLONE_NAME);
mutex->type = MTX_RECURSE;
} else if ((options & MTX_SPIN) != 0) {
B_INITIALIZE_SPINLOCK(&mutex->u.spinlock.lock);
mutex->type = MTX_SPIN;
} else { } else {
mutex_init_etc(&mutex->u.mutex.lock, name, MUTEX_FLAG_CLONE_NAME); mutex_init_etc(&mutex->u.mutex.lock, name, MUTEX_FLAG_CLONE_NAME);
mutex->u.mutex.owner = -1; mutex->u.mutex.owner = -1;
mutex->type = MTX_DEF;
} }
mutex->type = options;
} }

View File

@ -42,3 +42,10 @@ wakeup(void* identifier)
{ {
publishedConditionNotifyAll(identifier); publishedConditionNotifyAll(identifier);
} }
void
wakeup_one(void* identifier)
{
publishedConditionNotifyOne(identifier);
}

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2012, Jérôme Duval, korli@users.berlios.de. * Copyright 2012, Jérôme Duval, korli@users.berlios.de.
* Copyright 2018, Haiku, Inc.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */

View File

@ -25,7 +25,7 @@
#define DT_DRAIN_IN_PROGRESS (1 << 1) #define DT_DRAIN_IN_PROGRESS (1 << 1)
struct taskqueue { struct taskqueue {
char tq_name[64]; char tq_name[TASKQUEUE_NAMELEN];
struct mtx tq_mutex; struct mtx tq_mutex;
struct list tq_list; struct list tq_list;
taskqueue_enqueue_fn tq_enqueue; taskqueue_enqueue_fn tq_enqueue;