Free memory from afs_events
[openafs.git] / src / afs / afs_osi.h
index 5f6588b..153017e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include "h/types.h"
 #include "h/param.h"
 
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
 #include <sys/condvar.h>
 #endif
 
+#ifdef AFS_SGI_ENV
+#include "sys/sema.h"          /* for kcondvar_t */
+#endif
+
+#ifdef AFS_NBSD_ENV
+#include <sys/lock.h>
+#endif
+
 #ifdef AFS_LINUX20_ENV
 #ifndef _LINUX_CODA_FS_I
 #define _LINUX_CODA_FS_I
@@ -33,6 +41,13 @@ struct xfs_inode_info {
 #include "h/mm.h"
 #endif
 
+#if defined(AFS_NBSD50_ENV)
+# if !defined(DEF_CADDR_T)
+typedef char * caddr_t;
+#define DEF_CADDR_T
+# endif
+#endif
+
 
 /* this is just a dummy type decl, we're really using struct sockets here */
 struct osi_socket {
@@ -85,9 +100,9 @@ struct osi_dev {
 };
 
 struct afs_osi_WaitHandle {
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
     struct cv wh_condvar;
-    int wh_inited;             /* XXX */
+    int wh_inited;
 #else
     caddr_t proc;              /* process waiting */
 #endif
@@ -114,11 +129,36 @@ struct afs_osi_WaitHandle {
 #define        osi_NPACKETS    20      /* number of cluster pkts to alloc */
 
 /*
- * Alloc declarations.
+ * Various definitions for osi_sleep and its event hash table
+ * DFBSD and SUNOS have no osi_sleep, and HPUX has its own hack for this stuff
  */
-#if !defined(AFS_OBSD44_ENV)
-#define afs_osi_Alloc_NoSleep afs_osi_Alloc
+#define AFS_EVHASHSIZE 128     /* size of afs_evhasht, must be power of 2 */
+typedef struct afs_event {
+    struct afs_event *next;    /* next in hash chain */
+    char *event;               /* lwp event: an address */
+    int refcount;              /* Is it in use? */
+    int seq;                   /* Sequence number: this is incremented
+                                * by wakeup calls; wait will not return until
+                                * it changes */
+#if defined(AFS_AIX_ENV)
+    tid_t cond;
+#elif defined(AFS_DARWIN_ENV)
+#ifdef AFS_DARWIN80_ENV
+    lck_mtx_t *lck;
+    thread_t owner;
 #endif
+    /* no cond member */
+#elif defined(AFS_FBSD_ENV) || defined(AFS_OBSD_ENV)
+    int cond;                  /* "all this gluck should probably be replaced by CVs" */
+#elif defined(AFS_LINUX_ENV) || defined(AFS_LINUX24_ENV)
+    wait_queue_head_t cond;
+#elif defined(AFS_NBSD_ENV) || defined(AFS_SOLARIS_ENV) || defined(AFS_SGI_ENV)
+    kcondvar_t cond;           /* Currently associated condition variable */
+#endif
+} afs_event_t;
+extern afs_event_t *afs_evhasht[AFS_EVHASHSIZE];       /* Hash table for events */
+extern void shutdown_osisleep(void);
+
 
 /*
  * Default vnode related macros
@@ -134,8 +174,15 @@ extern struct vnodeops *afs_ops;
 # define       SetAfsVnode(v)      (v)->v_op = afs_ops
 #endif
 
+struct vcache;
+extern int osi_TryEvictVCache(struct vcache *, int *, int);
+extern struct vcache *osi_NewVnode(void);
+extern void osi_PrePopulateVCache(struct vcache *);
+extern void osi_PostPopulateVCache(struct vcache *);
+extern void osi_AttachVnode(struct vcache *, int seq);
+
 /*
- * In IRIX 6.5 we cannot have DEBUG turned on since certain
+ * In IRIX 6.5 and NetBSD we cannot have DEBUG turned on since certain
  * system-defined structures are a different size with DEBUG on, the
  * kernel is compiled without DEBUG on, and the resulting differences
  * would break our ability to interact with the rest of the kernel.
@@ -143,13 +190,13 @@ extern struct vnodeops *afs_ops;
  * Is DEBUG only for turning the ASSERT() macro?  If so, we should
  * be able to eliminate DEBUG entirely.
  */
-#if !defined(AFS_SGI65_ENV)
+#if !defined(AFS_SGI65_ENV) && !defined(AFS_NBSD_ENV)
 #ifndef        DEBUG
 #define        DEBUG   1               /* Default is to enable debugging/logging */
 #endif
 #endif
 
-/* 
+/*
  * Time related macros
  */
 #define osi_GetuTime(x) osi_GetTime(x)
@@ -167,10 +214,16 @@ typedef struct {
     afs_int32 tv_sec;
     afs_int32 tv_usec;
 } osi_timeval_t;
-#elif defined(AFS_SUN57_ENV)
+typedef struct {
+    afs_int32 tv_sec;
+    afs_int32 tv_usec;
+} osi_timeval32_t;
+#elif defined(AFS_SUN5_ENV)
 typedef struct timeval32 osi_timeval_t;
+typedef struct timeval32 osi_timeval32_t;
 #else
 typedef struct timeval osi_timeval_t;
+typedef struct timeval osi_timeval32_t;
 #endif /* AFS_SGI61_ENV */
 
 #ifndef UKERNEL
@@ -183,9 +236,9 @@ typedef struct timeval osi_timeval_t;
  * is going on in the system.  So if ps cannot show thread IDs it is
  * likely to be the process ID instead.
  */
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
 /* should use curthread, but 'ps' can't display it */
-#define osi_ThreadUnique()     curproc
+#define osi_ThreadUnique()     (curproc->p_pid)
 #elif defined(AFS_LINUX_ENV)
 #define osi_ThreadUnique()     (current->pid)
 #elif defined(UKERNEL)
@@ -247,14 +300,14 @@ typedef struct timeval osi_timeval_t;
  * (Also, of course, the vnode is assumed to be one of ours.  Can't use this
  * macro for V-file vnodes.)
  */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-/* Bare refcount manipulation would probably work on this platform, but just
-   calling VREF does not */
-#define AFS_FAST_HOLD(vp) osi_vnhold((vp),0)
+/* osi_vnhold is defined in PLATFORM/osi_machdep.h */
+#define AFS_FAST_HOLD(vp) osi_vnhold((vp), 0)
+
+#ifdef AFS_AIX_ENV
+#define AFS_FAST_RELE(vp) VREFCOUNT_DEC(vp)
 #else
-#define AFS_FAST_HOLD(vp) VN_HOLD(AFSTOV(vp))
-#endif
 #define AFS_FAST_RELE(vp) AFS_RELE(AFSTOV(vp))
+#endif
 
 /*
  * MP safe versions of routines to copy memory between user space
@@ -357,7 +410,7 @@ typedef struct timeval osi_timeval_t;
            uio_setrw((UIO),(RW));                              \
            CODE = uiomove((SRC),(LEN),(UIO));                  \
        } while(0)
-#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#elif defined(AFS_DARWIN_ENV) || (defined(AFS_XBSD_ENV) && !defined(AFS_NBSD40_ENV))
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
            (UIO)->uio_rw = (RW);                               \
@@ -410,7 +463,7 @@ typedef struct timeval osi_timeval_t;
 
 
 /*
-** Macro for Solaris 2.6 returns 1 if file is larger than 2GB; else returns 0 
+** Macro for Solaris 2.6 returns 1 if file is larger than 2GB; else returns 0
 */
 #define AfsLargeFileUio(uio)       0
 #define AfsLargeFileSize(pos, off) 0