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"
22 #include "rx/rx_kcommon.h"
23 #include "rx_kmutex.h"
24 #include "rx/rx_kernel.h"
27 afs_mutex_init(afs_kmutex_t * l)
29 #if defined(AFS_LINUX24_ENV)
38 afs_mutex_enter(afs_kmutex_t * l)
42 osi_Panic("mutex_enter: 0x%x held by %d", l, l->owner);
43 l->owner = current->pid;
47 afs_mutex_tryenter(afs_kmutex_t * l)
49 if (down_trylock(&l->sem))
51 l->owner = current->pid;
56 afs_mutex_exit(afs_kmutex_t * l)
58 if (l->owner != current->pid)
59 osi_Panic("mutex_exit: 0x%x held by %d", l, l->owner);
64 /* CV_WAIT and CV_TIMEDWAIT sleep until the specified event occurs, or, in the
65 * case of CV_TIMEDWAIT, until the specified timeout occurs.
66 * - NOTE: that on Linux, there are circumstances in which TASK_INTERRUPTIBLE
67 * can wake up, even if all signals are blocked
68 * - TODO: handle signals correctly by passing an indication back to the
69 * caller that the wait has been interrupted and the stack should be cleaned
70 * up preparatory to signal delivery
73 afs_cv_wait(afs_kcondvar_t * cv, afs_kmutex_t * l, int sigok)
75 int seq, isAFSGlocked = ISAFS_GLOCK();
77 #ifdef DECLARE_WAITQUEUE
78 DECLARE_WAITQUEUE(wait, current);
80 struct wait_queue wait = { current, NULL };
85 set_current_state(TASK_INTERRUPTIBLE);
86 add_wait_queue(&cv->waitq, &wait);
94 saved_set = current->blocked;
95 sigfillset(¤t->blocked);
96 RECALC_SIGPENDING(current);
100 while(seq == cv->seq) {
102 #ifdef AFS_LINUX26_ENV
106 current->flags & PF_FREEZE
111 #ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
112 refrigerator(PF_FREEZE);
116 set_current_state(TASK_INTERRUPTIBLE);
121 remove_wait_queue(&cv->waitq, &wait);
122 set_current_state(TASK_RUNNING);
126 current->blocked = saved_set;
127 RECALC_SIGPENDING(current);
135 return (sigok && signal_pending(current)) ? EINTR : 0;
139 afs_cv_timedwait(afs_kcondvar_t * cv, afs_kmutex_t * l, int waittime)
141 int seq, isAFSGlocked = ISAFS_GLOCK();
142 long t = waittime * HZ / 1000;
143 #ifdef DECLARE_WAITQUEUE
144 DECLARE_WAITQUEUE(wait, current);
146 struct wait_queue wait = { current, NULL };
150 set_current_state(TASK_INTERRUPTIBLE);
151 add_wait_queue(&cv->waitq, &wait);
157 while(seq == cv->seq) {
158 t = schedule_timeout(t);
159 if (!t) /* timeout */
163 remove_wait_queue(&cv->waitq, &wait);
164 set_current_state(TASK_RUNNING);