summaryrefslogtreecommitdiffstats
path: root/Python/thread_sgi.h
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-05 20:56:21 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-05 20:56:21 (GMT)
commita027efa5bfa7911b5c4b522b6a0698749a6f2e4a (patch)
tree7027609cb66223aba0355957599aa7629fce7e53 /Python/thread_sgi.h
parent73237c54b40c345813fa6b7831a32b10fa4671b5 (diff)
downloadcpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.zip
cpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.tar.gz
cpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.tar.bz2
Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated separately.
Diffstat (limited to 'Python/thread_sgi.h')
-rw-r--r--Python/thread_sgi.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/Python/thread_sgi.h b/Python/thread_sgi.h
index 32b94f2..a53c8dc 100644
--- a/Python/thread_sgi.h
+++ b/Python/thread_sgi.h
@@ -451,3 +451,83 @@ void up_sema _P1(sema, type_sema sema)
if (usvsema((usema_t *) sema) < 0)
perror("usvsema");
}
+
+/*
+ * Per-thread data ("key") support.
+ */
+
+struct key {
+ struct key *next;
+ long id;
+ int key;
+ void *value;
+};
+
+static struct key *keyhead = NULL;
+static int nkeys = 0;
+static type_lock keymutex = NULL;
+
+static struct key *find_key _P2(key, int key, value, void *value)
+{
+ struct key *p;
+ long id = get_thread_ident();
+ for (p = keyhead; p != NULL; p = p->next) {
+ if (p->id == id && p->key == key)
+ return p;
+ }
+ if (value == NULL)
+ return NULL;
+ p = (struct key *)malloc(sizeof(struct key));
+ if (p != NULL) {
+ p->id = id;
+ p->key = key;
+ p->value = value;
+ acquire_lock(keymutex, 1);
+ p->next = keyhead;
+ keyhead = p;
+ release_lock(keymutex);
+ }
+ return p;
+}
+
+int create_key _P0()
+{
+ if (keymutex == NULL)
+ keymutex = allocate_lock();
+ return ++nkeys;
+}
+
+void delete_key _P1(key, int key)
+{
+ struct key *p, **q;
+ acquire_lock(keymutex, 1);
+ q = &keyhead;
+ while ((p = *q) != NULL) {
+ if (p->key == key) {
+ *q = p->next;
+ free((void *)p);
+ /* NB This does *not* free p->value! */
+ }
+ else
+ q = &p->next;
+ }
+ release_lock(keymutex);
+}
+
+int set_key_value _P2(key, int key, value, void *value)
+{
+ struct key *p = find_key(key, value);
+ if (p == NULL)
+ return -1;
+ else
+ return 0;
+}
+
+void *get_key_value _P1(key, int key)
+{
+ struct key *p = find_key(key, NULL);
+ if (p == NULL)
+ return NULL;
+ else
+ return p->value;
+}