source: mainline/kernel/test/synch/rwlock2.c@ a000878c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a000878c was a000878c, checked in by Martin Decky <martin@…>, 15 years ago

make sure that all statically allocated strings are declared as "const char *"
and are treated as read-only

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[f761f1eb]1/*
[df4ed85]2 * Copyright (c) 2001-2004 Jakub Jermar
[f761f1eb]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <test.h>
30#include <arch.h>
[23684b7]31#include <atomic.h>
[f761f1eb]32#include <print.h>
33#include <proc/thread.h>
34
35#include <synch/rwlock.h>
36
[cb01e1e]37#define READERS 50
38#define WRITERS 50
[f761f1eb]39
40static rwlock_t rwlock;
41
[70b6de1]42static void writer(void *arg)
[f761f1eb]43{
[cb01e1e]44 TPRINTF("Trying to lock rwlock for writing....\n");
[deada67]45
[f761f1eb]46 rwlock_write_lock(&rwlock);
47 rwlock_write_unlock(&rwlock);
48
[cb01e1e]49 TPRINTF("Trying to lock rwlock for reading....\n");
[deada67]50
[f761f1eb]51 rwlock_read_lock(&rwlock);
[cb01e1e]52 rwlock_read_unlock(&rwlock);
[f761f1eb]53}
54
[a000878c]55const char *test_rwlock2(void)
[f761f1eb]56{
57 thread_t *thrd;
58
59 rwlock_initialize(&rwlock);
[cb01e1e]60
61 rwlock_read_lock(&rwlock);
[f761f1eb]62 rwlock_read_lock(&rwlock);
63 rwlock_read_lock(&rwlock);
64 rwlock_read_lock(&rwlock);
65
[62b6d17]66 thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
[f761f1eb]67 if (thrd)
68 thread_ready(thrd);
69 else
[96348adc]70 return "Could not create thread";
[cb01e1e]71
[f761f1eb]72 thread_sleep(1);
73
74 rwlock_read_unlock(&rwlock);
75 rwlock_read_unlock(&rwlock);
76 rwlock_read_unlock(&rwlock);
[96348adc]77 rwlock_read_unlock(&rwlock);
78
[deada67]79 thread_join(thrd);
80 thread_detach(thrd);
81
[96348adc]82 return NULL;
[f761f1eb]83}
Note: See TracBrowser for help on using the repository browser.