KSD is being added to support the magazine layer of the object cache.
It will soon gain support for destructors, to be called on each
val at kproc exit.
http://code.google.com/p/inferno-npe/source/detail?r=56a450c8f4
Added:
/emu/port/ksd.c
/man/10/ksd
Modified:
/emu/Linux/os.c
/emu/port/dat.h
/emu/port/fns.h
/emu/port/proc.c
=======================================
--- /dev/null
+++ /emu/port/ksd.c Tue Feb 9 09:34:34 2010
@@ -0,0 +1,45 @@
+/* kproc-specific-data
+ * provides a mechanism to create keys, associated with different data in
each
+ * running kproc.
+ */
+
+#include "dat.h"
+#include "fns.h"
+#include "interp.h"
+#include "error.h"
+
+static Ref high_ksd;
+
+int
+ksd_key_create(void)
+{
+ int i;
+ i = incref(&high_ksd) - 1;
+
+ if (i >= NKEYS) {
+ decref(&high_ksd);
+ return -1;
+ }
+
+ return i;
+}
+
+void *
+ksd_getspecific(int key)
+{
+ if (key < high_ksd.ref && key >= 0)
+ return up->ksd[key];
+ return nil;
+}
+
+void *
+ksd_setspecific(int key, void *val)
+{
+ if (!(key < high_ksd.ref && key >= 0))
+ return nil;
+
+ void *tmp = up->ksd[key];
+ up->ksd[key] = val;
+ return tmp;
+}
+
=======================================
--- /dev/null
+++ /man/10/ksd Tue Feb 9 09:34:34 2010
@@ -0,0 +1,31 @@
+.TH KSD 10.2
+.SH NAME
+ksd_key_create, ksd_getspecific, ksd_setspecific \- kproc-specific data
+.SH SYNOPSIS
+.ta \w'\fLvoid 'u
+.B
+int ksd_key_create(void)
+.PP
+.B
+void *ksd_getspecific(int key);
+.PP
+.B
+void *ksd_setspecific(int key, void *val);
+.B
+.SH DESCRIPTION
+.I ksd_key_create
+returns a key, an integer used to reference different data in each kproc.
+.PP
+.I ksd_getspecific
+returns the pointer associated with
+.I key,
+or nil if the key was never set in the current kproc.
+.PP
+.I ksd_setspecific
+maps
+.I key
+in the current kproc to
+.I val
+and returns the old value at key.
+.SH SEE ALSO
+.IR kproc (10.2)
=======================================
--- /emu/Linux/os.c Sun Feb 7 07:49:54 2010
+++ /emu/Linux/os.c Tue Feb 9 09:34:34 2010
@@ -68,6 +68,7 @@
closesigs(e->sigs);
}
kstack = up->kstack;
+ free(up->ksd);
free(up->prog);
free(up);
if(kstack != nil)
=======================================
--- /emu/port/dat.h Sun Feb 7 05:24:59 2010
+++ /emu/port/dat.h Tue Feb 9 09:34:34 2010
@@ -57,6 +57,10 @@
READSTR = 1000 /* temporary buffer size for device reads */
};
+enum {
+ NKEYS = 32
+};
+
struct Ref
{
Lock lk;
@@ -404,6 +408,7 @@
int nerr; /* error stack SP */
osjmpbuf estack[NERR]; /* vector of error jump labels */
char* kstack;
+ void** ksd; /* Kproc-specific data area */
void (*func)(void*); /* saved trampoline pointer for kproc */
void* arg; /* arg for invoked kproc function */
void* iprog; /* work for Prog after release */
=======================================
--- /emu/port/fns.h Sun Feb 7 05:24:59 2010
+++ /emu/port/fns.h Tue Feb 9 09:34:34 2010
@@ -253,4 +253,9 @@
void cleancname(Cname*);
void cnameclose(Cname*);
+/* ksd.c */
+int ksd_key_create(void);
+void *ksd_getspecific(int key);
+void *ksd_setspecific(int key, void *val);
+
#pragma varargck argpos iprint 1
=======================================
--- /emu/port/proc.c Fri Dec 22 09:07:39 2006
+++ /emu/port/proc.c Tue Feb 9 09:34:34 2010
@@ -21,6 +21,8 @@
p->env->syserrstr = p->env->errbuf1;
addprog(p);
+ p->ksd = mallocz(sizeof(void*) * NKEYS, 1);
+
return p;
}