source: trunk/sys/libpthread/pthread_rwlock.c @ 186

Last change on this file since 186 was 1, checked in by alain, 8 years ago

First import

File size: 2.0 KB
Line 
1/*
2 * pthread_mutex.c - pthread rwlock related functions
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS.
8 *
9 * ALMOS is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <errno.h>
24#include <sys/types.h>
25#include <semaphore.h>
26#include <pthread.h>
27#include <sys/syscall.h>
28#include <cpu-syscall.h>
29
30typedef enum
31{
32        RWLOCK_INIT,
33        RWLOCK_WRLOCK,
34        RWLOCK_RDLOCK,
35        RWLOCK_TRYWRLOCK,
36        RWLOCK_TRYRDLOCK,
37        RWLOCK_UNLOCK,
38        RWLOCK_DESTROY
39} rwlock_operation_t;
40
41static int __sys_rwlock(pthread_rwlock_t *rwlock, uint_t operation)
42{
43        register int retval;
44        retval = (int)cpu_syscall((void*)rwlock,(void*)operation,NULL,NULL,SYS_RWLOCK);
45        return retval;
46}
47
48int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
49{
50        return __sys_rwlock(rwlock, RWLOCK_INIT);
51}
52
53int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
54{
55        return __sys_rwlock(rwlock, RWLOCK_TRYWRLOCK);
56}
57
58int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
59{
60        return __sys_rwlock(rwlock, RWLOCK_WRLOCK);
61}
62
63int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
64{
65        return __sys_rwlock(rwlock, RWLOCK_RDLOCK);
66}
67
68int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
69{
70        return __sys_rwlock(rwlock, RWLOCK_TRYRDLOCK);
71}
72
73int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
74{
75        return __sys_rwlock(rwlock, RWLOCK_UNLOCK);
76}
77
78int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
79{
80        return __sys_rwlock(rwlock, RWLOCK_DESTROY);
81}
Note: See TracBrowser for help on using the repository browser.