summaryrefslogtreecommitdiff
path: root/libthreads/cthread_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'libthreads/cthread_data.c')
-rw-r--r--libthreads/cthread_data.c90
1 files changed, 47 insertions, 43 deletions
diff --git a/libthreads/cthread_data.c b/libthreads/cthread_data.c
index 12d10610..02e6fa82 100644
--- a/libthreads/cthread_data.c
+++ b/libthreads/cthread_data.c
@@ -1,20 +1,26 @@
-/*
+/*
* Mach Operating System
- * Copyright (c) 1991 Carnegie-Mellon University
+ * Copyright (c) 1992,1991 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* HISTORY
- * $Log: cthread_data.c,v $
- * Revision 1.1 1992/10/06 18:31:04 mib
- * entered into RCS
- *
+ * $Log: cthread_data.c,v $
+ * Revision 2.4 93/05/10 17:51:20 rvb
+ * Make cthread_set_data and cthread_data macros.
+ * [93/05/06 rvb]
+ *
+ * Revision 2.3 93/01/14 18:04:52 danner
+ * Converted file to ANSI C.
+ * Removed usage of obsolete type any_t.
+ * [92/12/18 pds]
+ *
* Revision 2.2 92/05/23 11:35:17 jfriedl
* Snarfed from multi-server sources at CMU.
* No stdio (for use with single-server).
- *
- *
+ *
+ *
* Revision 2.2 91/03/25 14:14:45 jjc
* For compatibility with cthread_data:
* 1) Added routines, cthread_data and cthread_set_data,
@@ -27,25 +33,25 @@
* Made simple implementation from POSIX threads specification for
* thread specific data.
* [91/03/07 jjc]
- *
+ *
*/
-#include <cthreads.h>
+#include <stdio.h>
+#include <cthreads.h>
-#ifdef CTHREAD_DATA
-#define CTHREAD_KEY_FIRST (cthread_key_t)1 /* first free key */
-#else /* CTHREAD_DATA */
-#define CTHREAD_KEY_FIRST CTHREAD_KEY_NULL /* first free key */
-#endif /* CTHREAD_DATA */
#define CTHREAD_KEY_MAX (cthread_key_t)8 /* max. no. of keys */
#define CTHREAD_KEY_NULL (cthread_key_t)0
-#ifdef CTHREAD_DATA
+#if defined(CTHREAD_DATA)
/*
* Key reserved for cthread_data
*/
#define CTHREAD_KEY_RESERVED CTHREAD_KEY_NULL
-#endif /* CTHREAD_DATA */
+
+#define CTHREAD_KEY_FIRST (cthread_key_t)1 /* first free key */
+#else /* not defined(CTHREAD_DATA) */
+#define CTHREAD_KEY_FIRST CTHREAD_KEY_NULL /* first free key */
+#endif /* defined(CTHREAD_DATA) */
/* lock protecting key creation */
@@ -61,8 +67,8 @@ cthread_key_t cthread_key = CTHREAD_KEY_FIRST;
* maintained on a thread specific basis.
* Returns 0 if successful and returns -1 otherwise.
*/
-cthread_keycreate(key)
-cthread_key_t *key;
+int
+cthread_keycreate(cthread_key_t *key)
{
if (cthread_key >= CTHREAD_KEY_FIRST && cthread_key < CTHREAD_KEY_MAX) {
mutex_lock((mutex_t)&cthread_data_lock);
@@ -83,20 +89,19 @@ cthread_key_t *key;
* If the calling thread doesn't have a value for the given key,
* the value returned is CTHREAD_DATA_VALUE_NULL.
*/
-cthread_getspecific(key, value)
-cthread_key_t key;
-any_t *value;
+int
+cthread_getspecific(cthread_key_t key, void **value)
{
register cthread_t self;
- register any_t *thread_data;
+ register void **thread_data;
*value = CTHREAD_DATA_VALUE_NULL;
if (key < CTHREAD_KEY_NULL || key >= cthread_key)
return(-1);
self = cthread_self();
- thread_data = (any_t *)(self->private_data);
- if (thread_data != (any_t *)0)
+ thread_data = (void **)(self->private_data);
+ if (thread_data != NULL)
*value = thread_data[key];
return(0);
@@ -107,20 +112,19 @@ any_t *value;
* Set private data associated with given key
* Returns 0 if successful and returns -1 otherwise.
*/
-cthread_setspecific(key, value)
-cthread_key_t key;
-any_t value;
+int
+cthread_setspecific(cthread_key_t key, void *value)
{
register int i;
register cthread_t self;
- register any_t *thread_data;
+ register void **thread_data;
if (key < CTHREAD_KEY_NULL || key >= cthread_key)
return(-1);
self = cthread_self();
- thread_data = (any_t *)(self->private_data);
- if (thread_data != (any_t *)0)
+ thread_data = (void **)(self->private_data);
+ if (thread_data != NULL)
thread_data[key] = value;
else {
/*
@@ -128,12 +132,12 @@ any_t value;
* point cthread_data at it, and then set the
* data for the given key with the given value.
*/
- thread_data = (any_t *)malloc(CTHREAD_KEY_MAX * sizeof(any_t));
- if (thread_data == (any_t *)0) {
+ thread_data = malloc(CTHREAD_KEY_MAX * sizeof(void *));
+ if (thread_data == NULL) {
printf("cthread_setspecific: malloc failed\n");
return(-1);
}
- self->private_data = (any_t)thread_data;
+ self->private_data = thread_data;
for (i = 0; i < CTHREAD_KEY_MAX; i++)
thread_data[i] = CTHREAD_DATA_VALUE_NULL;
@@ -144,16 +148,15 @@ any_t value;
}
-#ifdef CTHREAD_DATA
+#if defined(CTHREAD_DATA_XX)
/*
* Set thread specific "global" variable,
* using new POSIX routines.
* Crash and burn if the thread given isn't the calling thread.
* XXX For compatibility with old cthread_set_data() XXX
*/
-cthread_set_data(t, x)
-cthread_t t;
-any_t x;
+int
+cthread_set_data(cthread_t t, void *x)
{
register cthread_t self;
@@ -162,6 +165,7 @@ any_t x;
return(cthread_setspecific(CTHREAD_KEY_RESERVED, x));
else {
ASSERT(t == self);
+ return(-1);
}
}
@@ -172,12 +176,11 @@ any_t x;
* Crash and burn if the thread given isn't the calling thread.
* XXX For compatibility with old cthread_data() XXX
*/
-any_t
-cthread_data(t)
-cthread_t t;
+void *
+cthread_data(cthread_t t)
{
register cthread_t self;
- any_t value;
+ void *value;
self = cthread_self();
if (t == self) {
@@ -186,6 +189,7 @@ cthread_t t;
}
else {
ASSERT(t == self);
+ return(NULL);
}
}
-#endif /* CTHREAD_DATA */
+#endif /* defined(CTHREAD_DATA_XX) */