summaryrefslogtreecommitdiff
path: root/private.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-07-19 16:49:42 +0000
committerrpj <rpj>1998-07-19 16:49:42 +0000
commit2bc58279a6e8baf8b4001042a4eb07d29e36b9a7 (patch)
tree7e020dc0f3325a1ac27704a85d33e2102019adc6 /private.c
parent40cf527fe65e12a745ca7b981676da1fb691eee6 (diff)
Mon Jul 20 02:31:05 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* private.c (_pthread_getthreadindex): Implement.
Diffstat (limited to 'private.c')
-rw-r--r--private.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/private.c b/private.c
new file mode 100644
index 0000000..a880042
--- /dev/null
+++ b/private.c
@@ -0,0 +1,39 @@
+/*
+ * private.c
+ *
+ * Description:
+ * This translation unit implements routines which are private to
+ * the implementation and may be used throughout it.
+ */
+
+#include <windows.h>
+#include <process.h>
+#include "pthread.h"
+#include "implement.h"
+
+int
+_pthread_getthreadindex(pthread_t thread)
+{
+ /* The hash table works as follows:
+ hash into the table,
+ if the thread in this slot doesn't match then start single
+ stepping from there until we find it.
+
+ The scheme should have these characteristics:
+ - if the thread handle is a sequence number then the hash will
+ succeed first time every time,
+ - if the thread handle is a pseudo randomish value (eg. a pointer)
+ then the hash should succeed first time most times.
+ */
+ int t = _PTHREAD_HASH_INDEX(*thread);
+ int it = t; /* The initial thread index */
+
+ while ((_pthread_threads_table[t])->thread != thread) {
+ t++;
+ if (t == PTHREAD_THREADS_MAX)
+ t = 0; /* Wrap around to the first slot */
+ if (t == it)
+ return -1; /* Failed to find the thread */
+ }
+ return t;
+}