shithub: npe

Download patch

ref: 537d4c5c119be15eec734bc443074a8d90b9c202
parent: e4cdde6bf5fd9562d826cc2f5a30e3774c247432
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Aug 18 15:26:58 EDT 2023

pthread: fix const/pointer mess

--- a/include/npe/pthread.h
+++ b/include/npe/pthread.h
@@ -3,40 +3,37 @@
 
 #pragma lib "libnpe_pthread.a"
 
-typedef struct npe_pthread_t npe_pthread_t;
 typedef struct pthread_attr_t pthread_attr_t;
 typedef struct pthread_cond_t pthread_cond_t;
 typedef struct pthread_mutex_t pthread_mutex_t;
 typedef struct pthread_once_t pthread_once_t;
+typedef uintptr pthread_t;
 
-#pragma incomplete npe_pthread_t
 #pragma incomplete pthread_attr_t
 #pragma incomplete pthread_cond_t
 #pragma incomplete pthread_mutex_t
 #pragma incomplete pthread_once_t
 
-typedef npe_pthread_t* pthread_t;
-
 #define PTHREAD_ONCE_INIT {0}
 
-int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*f)(void *), void *arg);
+int pthread_create(pthread_t *pt, pthread_attr_t *attr, void *(*f)(void *), void *arg);
 int pthread_join(pthread_t thread, void **retval);
 
-int pthread_attr_init(pthread_attr_t *const attr);
-int pthread_attr_destroy(pthread_attr_t *const attr);
-int pthread_attr_setstacksize(pthread_attr_t *const attr, int stack_size);
+int pthread_attr_init(pthread_attr_t *attr);
+int pthread_attr_destroy(pthread_attr_t *attr);
+int pthread_attr_setstacksize(pthread_attr_t *attr, int stack_size);
 
 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
 
-int pthread_mutex_init(pthread_mutex_t *const mutex, const void *const attr);
-int pthread_mutex_destroy(pthread_mutex_t *const mutex);
-int pthread_mutex_lock(pthread_mutex_t *const mutex);
-int pthread_mutex_unlock(pthread_mutex_t *const mutex);
+int pthread_mutex_init(pthread_mutex_t *mutex, void *attr);
+int pthread_mutex_destroy(pthread_mutex_t *mutex);
+int pthread_mutex_lock(pthread_mutex_t *mutex);
+int pthread_mutex_unlock(pthread_mutex_t *mutex);
 
-int pthread_cond_init(pthread_cond_t *const cond, const void *const attr);
-int pthread_cond_destroy(pthread_cond_t *const cond);
-int pthread_cond_wait(pthread_cond_t *const cond, pthread_mutex_t *const mutex);
-int pthread_cond_signal(pthread_cond_t *const cond);
-int pthread_cond_broadcast(pthread_cond_t *const cond);
+int pthread_cond_init(pthread_cond_t *cond, void *attr);
+int pthread_cond_destroy(pthread_cond_t *cond);
+int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
+int pthread_cond_signal(pthread_cond_t *cond);
+int pthread_cond_broadcast(pthread_cond_t *cond);
 
 #endif
--- a/libnpe_pthread/_pthread.h
+++ b/libnpe_pthread/_pthread.h
@@ -2,6 +2,8 @@
 #include <pthread.h>
 #include <thread.h>
 
+typedef struct npe_pthread_t npe_pthread_t;
+
 struct pthread_attr_t {
 	unsigned stack_size;
 };
--- a/libnpe_pthread/pthread_create.c
+++ b/libnpe_pthread/pthread_create.c
@@ -3,7 +3,7 @@
 static void
 thread(void *x)
 {
-	pthread_t t;
+	npe_pthread_t *t;
 	void *p;
 
 	t = x;
@@ -16,7 +16,7 @@
 }
 
 int
-pthread_create(pthread_t *pt, const pthread_attr_t *attr, void *(*func)(void*), void *arg)
+pthread_create(pthread_t *pt, pthread_attr_t *attr, void *(*f)(void*), void *arg)
 {
 	npe_pthread_t *t;
 	int stacksz;
@@ -27,10 +27,10 @@
 
 	t = calloc(1, sizeof(npe_pthread_t));
 	t->waitchan = chancreate(sizeof(void*), 0);
-	t->func = func;
+	t->func = f;
 	t->arg = arg;
 	t->pid = proccreate(thread, t, stacksz);
-	*pt = t;
+	*pt = (pthread_t)t;
 
 	return 0;
 }
--- a/libnpe_pthread/pthread_join.c
+++ b/libnpe_pthread/pthread_join.c
@@ -3,8 +3,10 @@
 int
 pthread_join(pthread_t pt, void **res)
 {
-	if(pt->waitchan != nil)
-		recv(pt->waitchan, res);
+	npe_pthread_t *t;
+	t = (npe_pthread_t*)pt;
+	if(t->waitchan != nil)
+		recv(t->waitchan, res);
 
 	return 0;
 }