1 /* include my_lock_init */
2 #include	"unpthread.h"
3 #include	<sys/mman.h>
4 
5 static pthread_mutex_t	*mptr;	/* actual mutex will be in shared memory */
6 
7 void
my_lock_init(char * pathname)8 my_lock_init(char *pathname)
9 {
10 	int		fd;
11 	pthread_mutexattr_t	mattr;
12 
13 	fd = Open("/dev/zero", O_RDWR, 0);
14 
15 	mptr = Mmap(0, sizeof(pthread_mutex_t), PROT_READ | PROT_WRITE,
16 				MAP_SHARED, fd, 0);
17 	Close(fd);
18 
19 	Pthread_mutexattr_init(&mattr);
20 	Pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
21 	Pthread_mutex_init(mptr, &mattr);
22 }
23 /* end my_lock_init */
24 
25 /* include my_lock_wait */
26 void
my_lock_wait()27 my_lock_wait()
28 {
29 	Pthread_mutex_lock(mptr);
30 }
31 
32 void
my_lock_release()33 my_lock_release()
34 {
35 	Pthread_mutex_unlock(mptr);
36 }
37 /* end my_lock_wait */
38