Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / common / pthread.c
blob66770a155cb3b78e3d629bb2d5c784e9e10c9e3a
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 2000
5 * Sven Verdoolaege. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 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";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <ctype.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 #include <pthread.h>
29 #include "../common/common.h"
31 static int vi_pthread_run __P((WIN *wp, void *(*fun)(void*), void *data));
32 static int vi_pthread_lock_init __P((WIN *, void **));
33 static int vi_pthread_lock_end __P((WIN *, void **));
34 static int vi_pthread_lock_try __P((WIN *, void **));
35 static int vi_pthread_lock_unlock __P((WIN *, void **));
38 * thread_init
40 * PUBLIC: void thread_init __P((GS *gp));
42 void
43 thread_init(GS *gp)
45 gp->run = vi_pthread_run;
46 gp->lock_init = vi_pthread_lock_init;
47 gp->lock_end = vi_pthread_lock_end;
48 gp->lock_try = vi_pthread_lock_try;
49 gp->lock_unlock = vi_pthread_lock_unlock;
52 static int
53 vi_pthread_run(WIN *wp, void *(*fun)(void*), void *data)
55 pthread_t *t = malloc(sizeof(pthread_t));
56 pthread_create(t, NULL, fun, data);
57 return 0;
60 static int
61 vi_pthread_lock_init (WIN * wp, void **p)
63 pthread_mutex_t *mutex;
64 int rc;
66 MALLOC_RET(NULL, mutex, pthread_mutex_t *, sizeof(*mutex));
68 if (rc = pthread_mutex_init(mutex, NULL)) {
69 free(mutex);
70 *p = NULL;
71 return rc;
73 *p = mutex;
74 return 0;
77 static int
78 vi_pthread_lock_end (WIN * wp, void **p)
80 int rc;
81 pthread_mutex_t *mutex = (pthread_mutex_t *)*p;
83 if (rc = pthread_mutex_destroy(mutex))
84 return rc;
86 free(mutex);
87 *p = NULL;
88 return 0;
91 static int
92 vi_pthread_lock_try (WIN * wp, void **p)
94 printf("try %p\n", *p);
95 fflush(stdout);
96 return 0;
97 return pthread_mutex_trylock((pthread_mutex_t *)*p);
100 static int
101 vi_pthread_lock_unlock (WIN * wp, void **p)
103 printf("unlock %p\n", *p);
104 return 0;
105 return pthread_mutex_unlock((pthread_mutex_t *)*p);