PERFORCE change 127792 for review
Kip Macy
kmacy at FreeBSD.org
Fri Oct 19 12:31:50 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=127792
Change 127792 by kmacy at kmacy_home:ethng on 2007/10/19 19:31:20
simple idr compat shim
Affected files ...
.. //depot/projects/ethng/src/sys/sys/linux_compat.h#4 edit
Differences ...
==== //depot/projects/ethng/src/sys/sys/linux_compat.h#4 (text+ko) ====
@@ -82,4 +82,61 @@
} \
} while (0)
+
+/*
+ * idr emulation
+ */
+
+
+
+struct idr {
+ struct idr *next;
+ unsigned int key;
+ void *value;
+};
+
+
+#define DEFINE_IDR(x) struct idr *x;
+
+static inline void *idr_find(struct idr *x, uint32_t key)
+{
+ struct idr *i;
+ for (i=x;i;i=i->next) if (i->key==key) return(i->value);
+ return(0);
+}
+
+static inline int idr_pre_get(struct idr *idp, unsigned int gfp){return(1);}
+static inline int idr_get_new(struct idr **idp, void *ptr, int *id)
+{
+ struct idr *i=malloc(sizeof(struct idr),M_TEMP,M_WAITOK);
+ i->key=*id;
+ i->value=ptr;
+ i->next=*idp;
+ *idp=i;
+ return(0);
+}
+
+static inline int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
+{
+ struct idr *i=malloc(sizeof(struct idr),M_TEMP,M_WAITOK);
+ i->key=*id;
+ i->value=ptr;
+ i->next=idp;
+ idp=i;
+ return(0);
+}
+
+static inline void idr_remove(struct idr *idp, int id)
+{
+ /* leak */
+ struct idr *i;
+ for (i=idp;i;i=((i)->next))
+ if ((i)->key==id) {
+ i=(i)->next;
+ return;
+ }
+}
+static inline void idr_init(struct idr *idp){}
+
+
#endif
More information about the p4-projects
mailing list