Merge commit 'refs/top-bases/linux-libspl' into linux-libspl

This commit is contained in:
Brian Behlendorf 2008-12-12 16:29:31 -08:00
commit b35bef8df2
1 changed files with 34 additions and 44 deletions

View File

@ -50,8 +50,7 @@ extern "C" {
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <synch.h> #include <pthread.h>
#include <thread.h>
#include <assert.h> #include <assert.h>
#include <alloca.h> #include <alloca.h>
#include <umem.h> #include <umem.h>
@ -104,6 +103,7 @@ extern void vpanic(const char *, __va_list);
#define fm_panic panic #define fm_panic panic
/* This definition is copied from assert.h. */ /* This definition is copied from assert.h. */
#ifndef verify
#if defined(__STDC__) #if defined(__STDC__)
#if __STDC_VERSION__ - 0 >= 199901L #if __STDC_VERSION__ - 0 >= 199901L
#define verify(EX) (void)((EX) || \ #define verify(EX) (void)((EX) || \
@ -114,7 +114,10 @@ extern void vpanic(const char *, __va_list);
#else #else
#define verify(EX) (void)((EX) || (_assert("EX", __FILE__, __LINE__), 0)) #define verify(EX) (void)((EX) || (_assert("EX", __FILE__, __LINE__), 0))
#endif /* __STDC__ */ #endif /* __STDC__ */
#endif
#undef VERIFY
#undef ASSERT
#define VERIFY verify #define VERIFY verify
#define ASSERT assert #define ASSERT assert
@ -159,11 +162,6 @@ _NOTE(CONSTCOND) } while (0)
* existence for their counterparts in libzpool. * existence for their counterparts in libzpool.
*/ */
#ifdef DTRACE_PROBE
#undef DTRACE_PROBE
#define DTRACE_PROBE(a) ((void)0)
#endif /* DTRACE_PROBE */
#ifdef DTRACE_PROBE1 #ifdef DTRACE_PROBE1
#undef DTRACE_PROBE1 #undef DTRACE_PROBE1
#define DTRACE_PROBE1(a, b, c) ((void)0) #define DTRACE_PROBE1(a, b, c) ((void)0)
@ -187,13 +185,15 @@ _NOTE(CONSTCOND) } while (0)
/* /*
* Threads * Threads
*/ */
#define curthread ((void *)(uintptr_t)thr_self())
/* XXX: not portable */
#define curthread ((void *)(uintptr_t)pthread_self())
typedef struct kthread kthread_t; typedef struct kthread kthread_t;
#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ #define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
zk_thread_create(func, arg) zk_thread_create(func, arg)
#define thread_exit() thr_exit(NULL) #define thread_exit() pthread_exit(NULL)
extern kthread_t *zk_thread_create(void (*func)(void), void *arg); extern kthread_t *zk_thread_create(void (*func)(void), void *arg);
@ -203,28 +203,18 @@ extern kthread_t *zk_thread_create(void (*func)(void), void *arg);
/* /*
* Mutexes * Mutexes
*/ */
#define MTX_MAGIC 0x9522f51362a6e326ull
typedef struct kmutex { typedef struct kmutex {
void *m_owner; void *m_owner;
boolean_t initialized; uint64_t m_magic;
mutex_t m_lock; pthread_mutex_t m_lock;
} kmutex_t; } kmutex_t;
#define MUTEX_DEFAULT USYNC_THREAD #define MUTEX_DEFAULT 0
#undef MUTEX_HELD #define MUTEX_HELD(m) ((m)->m_owner == curthread)
#define MUTEX_HELD(m) _mutex_held(&(m)->m_lock)
/* extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie);
* Argh -- we have to get cheesy here because the kernel and userland extern void mutex_destroy(kmutex_t *mp);
* have different signatures for the same routine.
*/
extern int _mutex_init(mutex_t *mp, int type, void *arg);
extern int _mutex_destroy(mutex_t *mp);
#define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp))
#define mutex_destroy(mp) zmutex_destroy((kmutex_t *)(mp))
extern void zmutex_init(kmutex_t *mp);
extern void zmutex_destroy(kmutex_t *mp);
extern void mutex_enter(kmutex_t *mp); extern void mutex_enter(kmutex_t *mp);
extern void mutex_exit(kmutex_t *mp); extern void mutex_exit(kmutex_t *mp);
extern int mutex_tryenter(kmutex_t *mp); extern int mutex_tryenter(kmutex_t *mp);
@ -233,23 +223,24 @@ extern void *mutex_owner(kmutex_t *mp);
/* /*
* RW locks * RW locks
*/ */
#define RW_MAGIC 0x4d31fb123648e78aull
typedef struct krwlock { typedef struct krwlock {
void *rw_owner; void *rw_owner;
boolean_t initialized; void *rw_wr_owner;
rwlock_t rw_lock; uint64_t rw_magic;
pthread_rwlock_t rw_lock;
uint_t rw_readers;
} krwlock_t; } krwlock_t;
typedef int krw_t; typedef int krw_t;
#define RW_READER 0 #define RW_READER 0
#define RW_WRITER 1 #define RW_WRITER 1
#define RW_DEFAULT USYNC_THREAD #define RW_DEFAULT 0
#undef RW_READ_HELD #define RW_READ_HELD(x) ((x)->rw_readers > 0)
#define RW_READ_HELD(x) _rw_read_held(&(x)->rw_lock) #define RW_WRITE_HELD(x) ((x)->rw_wr_owner == curthread)
#define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x))
#undef RW_WRITE_HELD
#define RW_WRITE_HELD(x) _rw_write_held(&(x)->rw_lock)
extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg); extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
extern void rw_destroy(krwlock_t *rwlp); extern void rw_destroy(krwlock_t *rwlp);
@ -267,9 +258,13 @@ extern gid_t *crgetgroups(cred_t *cr);
/* /*
* Condition variables * Condition variables
*/ */
typedef cond_t kcondvar_t; #define CV_MAGIC 0xd31ea9a83b1b30c4ull
typedef struct kcondvar {
uint64_t cv_magic;
pthread_cond_t cv;
} kcondvar_t;
#define CV_DEFAULT USYNC_THREAD #define CV_DEFAULT 0
extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
extern void cv_destroy(kcondvar_t *cv); extern void cv_destroy(kcondvar_t *cv);
@ -290,7 +285,6 @@ extern void kstat_delete(kstat_t *);
* Kernel memory * Kernel memory
*/ */
#define KM_SLEEP UMEM_NOFAIL #define KM_SLEEP UMEM_NOFAIL
#define KM_PUSHPAGE KM_SLEEP
#define KM_NOSLEEP UMEM_DEFAULT #define KM_NOSLEEP UMEM_DEFAULT
#define KMC_NODEBUG UMC_NODEBUG #define KMC_NODEBUG UMC_NODEBUG
#define kmem_alloc(_s, _f) umem_alloc(_s, _f) #define kmem_alloc(_s, _f) umem_alloc(_s, _f)
@ -321,14 +315,11 @@ typedef void (task_func_t)(void *);
#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */
#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */
extern taskq_t *system_taskq;
extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
extern void taskq_destroy(taskq_t *); extern void taskq_destroy(taskq_t *);
extern void taskq_wait(taskq_t *); extern void taskq_wait(taskq_t *);
extern int taskq_member(taskq_t *, void *); extern int taskq_member(taskq_t *, void *);
extern void system_taskq_init(void);
#define XVA_MAPSIZE 3 #define XVA_MAPSIZE 3
#define XVA_MAGIC 0x78766174 #define XVA_MAGIC 0x78766174
@ -443,13 +434,12 @@ extern void delay(clock_t ticks);
#define minclsyspri 60 #define minclsyspri 60
#define maxclsyspri 99 #define maxclsyspri 99
#define CPU_SEQID (thr_self() & (max_ncpus - 1)) /* XXX: not portable */
#define CPU_SEQID (pthread_self() & (max_ncpus - 1))
#define kcred NULL #define kcred NULL
#define CRED() NULL #define CRED() NULL
#define ptob(x) ((x) * PAGESIZE)
extern uint64_t physmem; extern uint64_t physmem;
extern int highbit(ulong_t i); extern int highbit(ulong_t i);