1 /* $NetBSD: pthread.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
4 * Sven Verdoolaege. All rights reserved.
6 * See the LICENSE file for redistribution information.
11 #include <sys/cdefs.h>
14 static const char sccsid
[] = "Id: pthread.c,v 1.4 2000/07/22 14:52:37 skimo Exp (Berkeley) Date: 2000/07/22 14:52:37 ";
17 __RCSID("$NetBSD: pthread.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #include <sys/types.h>
21 #include <sys/queue.h>
23 #include <bitstring.h>
33 #include "../common/common.h"
35 static int vi_pthread_run
__P((WIN
*wp
, void *(*fun
)(void*), void *data
));
36 static int vi_pthread_lock_init
__P((WIN
*, void **));
37 static int vi_pthread_lock_end
__P((WIN
*, void **));
38 static int vi_pthread_lock_try
__P((WIN
*, void **));
39 static int vi_pthread_lock_unlock
__P((WIN
*, void **));
44 * PUBLIC: void thread_init __P((GS *gp));
49 gp
->run
= vi_pthread_run
;
50 gp
->lock_init
= vi_pthread_lock_init
;
51 gp
->lock_end
= vi_pthread_lock_end
;
52 gp
->lock_try
= vi_pthread_lock_try
;
53 gp
->lock_unlock
= vi_pthread_lock_unlock
;
57 vi_pthread_run(WIN
*wp
, void *(*fun
)(void*), void *data
)
59 pthread_t
*t
= malloc(sizeof(pthread_t
));
60 pthread_create(t
, NULL
, fun
, data
);
65 vi_pthread_lock_init (WIN
* wp
, void **p
)
67 pthread_mutex_t
*mutex
;
70 MALLOC_RET(NULL
, mutex
, pthread_mutex_t
*, sizeof(*mutex
));
72 if (rc
= pthread_mutex_init(mutex
, NULL
)) {
82 vi_pthread_lock_end (WIN
* wp
, void **p
)
85 pthread_mutex_t
*mutex
= (pthread_mutex_t
*)*p
;
87 if (rc
= pthread_mutex_destroy(mutex
))
96 vi_pthread_lock_try (WIN
* wp
, void **p
)
98 printf("try %p\n", *p
);
101 return pthread_mutex_trylock((pthread_mutex_t
*)*p
);
105 vi_pthread_lock_unlock (WIN
* wp
, void **p
)
107 printf("unlock %p\n", *p
);
109 return pthread_mutex_unlock((pthread_mutex_t
*)*p
);