2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * rx_kmutex.c - mutex and condition variable macros for kernel environment.
13 * Linux implementation.
16 #include <afsconfig.h>
17 #include "../afs/param.h"
21 #include "../rx/rx_kcommon.h"
22 #include "../rx/rx_kmutex.h"
23 #include "../rx/rx_kernel.h"
27 void afs_mutex_init(afs_kmutex_t *l)
29 #if defined(AFS_LINUX24_ENV)
37 void afs_mutex_enter(afs_kmutex_t *l)
41 osi_Panic("mutex_enter: 0x%x held by %d", l, l->owner);
42 l->owner = current->pid;
45 int afs_mutex_tryenter(afs_kmutex_t *l)
47 if (down_trylock(&l->sem))
49 l->owner = current->pid;
53 void afs_mutex_exit(afs_kmutex_t *l)
55 if (l->owner != current->pid)
56 osi_Panic("mutex_exit: 0x%x held by %d",
63 * CV_WAIT and CV_TIMEDWAIT rely on the fact that the Linux kernel has
64 * a global lock. Thus we can safely drop our locks before calling the
65 * kernel sleep services.
67 int afs_cv_wait(afs_kcondvar_t *cv, afs_kmutex_t *l, int sigok)
69 int isAFSGlocked = ISAFS_GLOCK();
72 if (isAFSGlocked) AFS_GUNLOCK();
76 spin_lock_irq(¤t->sigmask_lock);
77 saved_set = current->blocked;
78 sigfillset(¤t->blocked);
79 recalc_sigpending(current);
80 spin_unlock_irq(¤t->sigmask_lock);
83 #if defined(AFS_LINUX24_ENV)
84 interruptible_sleep_on((wait_queue_head_t *)cv);
86 interruptible_sleep_on((struct wait_queue**)cv);
90 spin_lock_irq(¤t->sigmask_lock);
91 current->blocked = saved_set;
92 recalc_sigpending(current);
93 spin_unlock_irq(¤t->sigmask_lock);
97 if (isAFSGlocked) AFS_GLOCK();
99 return (sigok && signal_pending(current)) ? EINTR : 0;
102 void afs_cv_timedwait(afs_kcondvar_t *cv, afs_kmutex_t *l, int waittime)
104 int isAFSGlocked = ISAFS_GLOCK();
105 long t = waittime * HZ / 1000;
107 if (isAFSGlocked) AFS_GUNLOCK();
110 #if defined(AFS_LINUX24_ENV)
111 t = interruptible_sleep_on_timeout((wait_queue_head_t *)cv, t);
113 t = interruptible_sleep_on_timeout((struct wait_queue**)cv, t);
117 if (isAFSGlocked) AFS_GLOCK();