Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / common / pthread.c
blobddb1a6c00530c963195472e3befabc0bbd8fad17
1 /* $NetBSD: pthread.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 /*-
3 * Copyright (c) 2000
4 * Sven Verdoolaege. All rights reserved.
6 * See the LICENSE file for redistribution information.
7 */
9 #include "config.h"
11 #include <sys/cdefs.h>
12 #if 0
13 #ifndef lint
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 ";
15 #endif /* not lint */
16 #else
17 __RCSID("$NetBSD: pthread.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
18 #endif
20 #include <sys/types.h>
21 #include <sys/queue.h>
23 #include <bitstring.h>
24 #include <ctype.h>
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
31 #include <pthread.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 **));
42 * thread_init
44 * PUBLIC: void thread_init __P((GS *gp));
46 void
47 thread_init(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;
56 static int
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);
61 return 0;
64 static int
65 vi_pthread_lock_init (WIN * wp, void **p)
67 pthread_mutex_t *mutex;
68 int rc;
70 MALLOC_RET(NULL, mutex, pthread_mutex_t *, sizeof(*mutex));
72 if (rc = pthread_mutex_init(mutex, NULL)) {
73 free(mutex);
74 *p = NULL;
75 return rc;
77 *p = mutex;
78 return 0;
81 static int
82 vi_pthread_lock_end (WIN * wp, void **p)
84 int rc;
85 pthread_mutex_t *mutex = (pthread_mutex_t *)*p;
87 if (rc = pthread_mutex_destroy(mutex))
88 return rc;
90 free(mutex);
91 *p = NULL;
92 return 0;
95 static int
96 vi_pthread_lock_try (WIN * wp, void **p)
98 printf("try %p\n", *p);
99 fflush(stdout);
100 return 0;
101 return pthread_mutex_trylock((pthread_mutex_t *)*p);
104 static int
105 vi_pthread_lock_unlock (WIN * wp, void **p)
107 printf("unlock %p\n", *p);
108 return 0;
109 return pthread_mutex_unlock((pthread_mutex_t *)*p);