1*051cd856Spooka /* $NetBSD: lockme.c,v 1.1 2011/01/06 13:12:52 pooka Exp $ */
2*051cd856Spooka
3*051cd856Spooka /*-
4*051cd856Spooka * Copyright (c) 2011 The NetBSD Foundation, Inc.
5*051cd856Spooka * All rights reserved.
6*051cd856Spooka *
7*051cd856Spooka * Redistribution and use in source and binary forms, with or without
8*051cd856Spooka * modification, are permitted provided that the following conditions
9*051cd856Spooka * are met:
10*051cd856Spooka * 1. Redistributions of source code must retain the above copyright
11*051cd856Spooka * notice, this list of conditions and the following disclaimer.
12*051cd856Spooka * 2. Redistributions in binary form must reproduce the above copyright
13*051cd856Spooka * notice, this list of conditions and the following disclaimer in the
14*051cd856Spooka * documentation and/or other materials provided with the distribution.
15*051cd856Spooka *
16*051cd856Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*051cd856Spooka * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*051cd856Spooka * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*051cd856Spooka * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*051cd856Spooka * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*051cd856Spooka * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*051cd856Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*051cd856Spooka * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*051cd856Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*051cd856Spooka * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*051cd856Spooka * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*051cd856Spooka * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*051cd856Spooka */
29*051cd856Spooka
30*051cd856Spooka #include <sys/cdefs.h>
31*051cd856Spooka #if !defined(lint)
32*051cd856Spooka __RCSID("$NetBSD: lockme.c,v 1.1 2011/01/06 13:12:52 pooka Exp $");
33*051cd856Spooka #endif /* !lint */
34*051cd856Spooka
35*051cd856Spooka #include <sys/param.h>
36*051cd856Spooka #include <sys/kmem.h>
37*051cd856Spooka #include <sys/mutex.h>
38*051cd856Spooka #include <sys/rwlock.h>
39*051cd856Spooka
40*051cd856Spooka #include "kernspace.h"
41*051cd856Spooka
42*051cd856Spooka struct somemem {
43*051cd856Spooka char foo;
44*051cd856Spooka kmutex_t mutexetum;
45*051cd856Spooka char oof;
46*051cd856Spooka };
47*051cd856Spooka
48*051cd856Spooka void
rumptest_lockme(enum locktest what)49*051cd856Spooka rumptest_lockme(enum locktest what)
50*051cd856Spooka {
51*051cd856Spooka struct somemem *some;
52*051cd856Spooka kmutex_t mtx;
53*051cd856Spooka krwlock_t rw;
54*051cd856Spooka
55*051cd856Spooka rw_init(&rw);
56*051cd856Spooka mutex_init(&mtx, MUTEX_DEFAULT, IPL_NONE);
57*051cd856Spooka
58*051cd856Spooka switch (what) {
59*051cd856Spooka case LOCKME_MTX:
60*051cd856Spooka mutex_enter(&mtx);
61*051cd856Spooka mutex_enter(&mtx);
62*051cd856Spooka break;
63*051cd856Spooka case LOCKME_RWDOUBLEX:
64*051cd856Spooka rw_enter(&rw, RW_WRITER);
65*051cd856Spooka rw_enter(&rw, RW_WRITER);
66*051cd856Spooka break;
67*051cd856Spooka case LOCKME_RWRX:
68*051cd856Spooka rw_enter(&rw, RW_READER);
69*051cd856Spooka rw_enter(&rw, RW_WRITER);
70*051cd856Spooka break;
71*051cd856Spooka case LOCKME_RWXR:
72*051cd856Spooka rw_enter(&rw, RW_WRITER);
73*051cd856Spooka rw_enter(&rw, RW_READER);
74*051cd856Spooka break;
75*051cd856Spooka case LOCKME_DOUBLEINIT:
76*051cd856Spooka mutex_init(&mtx, MUTEX_DEFAULT, IPL_NONE);
77*051cd856Spooka break;
78*051cd856Spooka case LOCKME_DOUBLEFREE:
79*051cd856Spooka mutex_destroy(&mtx);
80*051cd856Spooka mutex_destroy(&mtx);
81*051cd856Spooka break;
82*051cd856Spooka case LOCKME_DESTROYHELD:
83*051cd856Spooka mutex_enter(&mtx);
84*051cd856Spooka mutex_destroy(&mtx);
85*051cd856Spooka break;
86*051cd856Spooka case LOCKME_MEMFREE:
87*051cd856Spooka some = kmem_alloc(sizeof(*some), KM_SLEEP);
88*051cd856Spooka mutex_init(&some->mutexetum, MUTEX_DEFAULT, IPL_NONE);
89*051cd856Spooka kmem_free(some, sizeof(*some));
90*051cd856Spooka break;
91*051cd856Spooka }
92*051cd856Spooka }
93