Merge branch 'linux-libspl' into refs/top-bases/linux-zfs-branch

This commit is contained in:
Brian Behlendorf 2008-12-12 12:57:18 -08:00
commit ba611ca42d
3 changed files with 25 additions and 23 deletions

View File

@ -18,6 +18,9 @@ typedef pthread_cond_t cond_t;
#define THR_DETACHED 2 #define THR_DETACHED 2
#define THR_DAEMON 4 #define THR_DAEMON 4
#define USYNC_THREAD 0x00 /* private to a process */
#define USYNC_PROCESS 0x01 /* shared by processes */
#define thr_self() pthread_self() #define thr_self() pthread_self()
#define thr_sigsetmask pthread_sigmask #define thr_sigsetmask pthread_sigmask
#define __nthreads() 2 /* XXX: Force multi-thread */ #define __nthreads() 2 /* XXX: Force multi-thread */
@ -41,6 +44,20 @@ thr_create(void *stack_base, size_t stack_size,
return rc; return rc;
} }
static inline int
mutex_held(mutex_t *mp)
{
int rc;
rc = pthread_mutex_trylock(mp);
if (rc)
return rc;
pthread_mutex_unlock(mp);
return rc;
}
#define MUTEX_HELD(mp) mutex_held(mp)
#define mutex_init(mp, type, arg) pthread_mutex_init(mp, NULL) #define mutex_init(mp, type, arg) pthread_mutex_init(mp, NULL)
#define mutex_lock(mp) pthread_mutex_lock(mp) #define mutex_lock(mp) pthread_mutex_lock(mp)
#define mutex_unlock(mp) pthread_mutex_unlock(mp) #define mutex_unlock(mp) pthread_mutex_unlock(mp)
@ -48,7 +65,6 @@ thr_create(void *stack_base, size_t stack_size,
#define mutex_trylock(mp) pthread_mutex_trylock(mp) #define mutex_trylock(mp) pthread_mutex_trylock(mp)
#define DEFAULTMUTEX PTHREAD_MUTEX_INITIALIZER #define DEFAULTMUTEX PTHREAD_MUTEX_INITIALIZER
#define DEFAULTCV PTHREAD_COND_INITIALIZER #define DEFAULTCV PTHREAD_COND_INITIALIZER
#define MUTEX_HELD(mp) 1 /* XXX: Use mutex_trylock() */
#define cond_init(c, type, arg) pthread_cond_init(c, NULL) #define cond_init(c, type, arg) pthread_cond_init(c, NULL)
#define cond_wait(c, m) pthread_cond_wait(c, m) #define cond_wait(c, m) pthread_cond_wait(c, m)

View File

@ -58,7 +58,7 @@ typedef struct umem_cache {
size_t cache_align; size_t cache_align;
umem_constructor_t *cache_constructor; umem_constructor_t *cache_constructor;
umem_destructor_t *cache_destructor; umem_destructor_t *cache_destructor;
umem_reclaim_t *cache_reclaim umem_reclaim_t *cache_reclaim;
void *cache_private; void *cache_private;
void *cache_arena; void *cache_arena;
int cache_cflags; int cache_cflags;

View File

@ -203,32 +203,18 @@ extern kthread_t *zk_thread_create(void (*func)(void), void *arg);
/* /*
* Mutexes * Mutexes
*/ */
typedef struct kmutex { typedef mutex_t kmutex_t;
void *m_owner;
boolean_t initialized;
mutex_t m_lock;
} kmutex_t;
#define MUTEX_DEFAULT USYNC_THREAD #define MUTEX_DEFAULT USYNC_THREAD
#undef MUTEX_HELD
#define MUTEX_HELD(m) _mutex_held(&(m)->m_lock)
/* /*
* Argh -- we have to get cheesy here because the kernel and userland * Conflicts with lib/libspl/include/thread.h. The kernel and user
* have different signatures for the same routine. * space prototypes differ forcing us to do some special handling.
*/ */
extern int _mutex_init(mutex_t *mp, int type, void *arg); #ifdef mutex_init
extern int _mutex_destroy(mutex_t *mp); #undef mutex_init
#define mutex_init(mp, b, c, d) pthread_mutex_init(mp, NULL)
#define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp)) #endif
#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_exit(kmutex_t *mp);
extern int mutex_tryenter(kmutex_t *mp);
extern void *mutex_owner(kmutex_t *mp);
/* /*
* RW locks * RW locks