source: rtems/cpukit/libstdthreads/mtx.c @ bdd4eb87

5
Last change on this file since bdd4eb87 was a2a71b5, checked in by Sebastian Huber <sebastian.huber@…>, on 09/14/18 at 14:00:45

build: Merge libstdthreads/Makefile.am

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*-
2 * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
3 * Copyright (c) 2015 embedded brains GmbH <info@embedded-brains.de>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. 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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD r279326 2015-02-26T16:39:57Z$
28 */
29
30#include <threads.h>
31#include <sys/lock.h>
32#include <errno.h>
33
34void
35mtx_destroy(mtx_t *mtx)
36{
37
38        _Mutex_recursive_Destroy(mtx);
39}
40
41int
42mtx_init(mtx_t *mtx, int type)
43{
44
45        (void)type;
46        _Mutex_recursive_Initialize(mtx);
47        return (thrd_success);
48}
49
50int
51mtx_lock(mtx_t *mtx)
52{
53
54        _Mutex_recursive_Acquire(mtx);
55        return (thrd_success);
56}
57
58int
59mtx_timedlock(mtx_t *__restrict mtx, const struct timespec *__restrict ts)
60{
61
62        switch (_Mutex_recursive_Acquire_timed(mtx, ts)) {
63        case 0:
64                return (thrd_success);
65        case ETIMEDOUT:
66                return (thrd_timedout);
67        default:
68                return (thrd_error);
69        }
70}
71
72int
73mtx_trylock(mtx_t *mtx)
74{
75
76        switch (_Mutex_recursive_Try_acquire(mtx)) {
77        case 0:
78                return (thrd_success);
79        default:
80                return (thrd_busy);
81        }
82}
83
84int
85mtx_unlock(mtx_t *mtx)
86{
87
88        _Mutex_recursive_Release(mtx);
89        return (thrd_success);
90}
Note: See TracBrowser for help on using the repository browser.