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 isAFSGlocked = ISAFS_GLOCK();
77 #ifdef DECLARE_WAITQUEUE
78 DECLARE_WAITQUEUE(wait, current);
80 struct wait_queue wait = { current, NULL };
83 add_wait_queue(cv, &wait);
84 set_current_state(TASK_INTERRUPTIBLE);
92 saved_set = current->blocked;
93 sigfillset(¤t->blocked);
94 RECALC_SIGPENDING(current);
99 remove_wait_queue(cv, &wait);
103 current->blocked = saved_set;
104 RECALC_SIGPENDING(current);
112 return (sigok && signal_pending(current)) ? EINTR : 0;
116 afs_cv_timedwait(afs_kcondvar_t * cv, afs_kmutex_t * l, int waittime)
118 int isAFSGlocked = ISAFS_GLOCK();
119 long t = waittime * HZ / 1000;
120 #ifdef DECLARE_WAITQUEUE
121 DECLARE_WAITQUEUE(wait, current);
123 struct wait_queue wait = { current, NULL };
126 add_wait_queue(cv, &wait);
127 set_current_state(TASK_INTERRUPTIBLE);
133 t = schedule_timeout(t);
134 remove_wait_queue(cv, &wait);