Xenomai  3.1
synch.h
1 /*
2  * Copyright (C) 2001-2013 Philippe Gerum <rpm@xenomai.org>.
3  * Copyright (C) 2008, 2009 Jan Kiszka <jan.kiszka@siemens.com>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18  */
19 #ifndef _COBALT_UAPI_KERNEL_SYNCH_H
20 #define _COBALT_UAPI_KERNEL_SYNCH_H
21 
22 #include <cobalt/uapi/kernel/types.h>
23 
24 /* Creation flags */
25 #define XNSYNCH_FIFO 0x0
26 #define XNSYNCH_PRIO 0x1
27 #define XNSYNCH_PI 0x2
28 #define XNSYNCH_DREORD 0x4
29 #define XNSYNCH_OWNER 0x8
30 #define XNSYNCH_PP 0x10
31 
32 /* Fast lock API */
33 static inline int xnsynch_fast_is_claimed(xnhandle_t handle)
34 {
35  return (handle & XNSYNCH_FLCLAIM) != 0;
36 }
37 
38 static inline xnhandle_t xnsynch_fast_claimed(xnhandle_t handle)
39 {
40  return handle | XNSYNCH_FLCLAIM;
41 }
42 
43 static inline xnhandle_t xnsynch_fast_ceiling(xnhandle_t handle)
44 {
45  return handle | XNSYNCH_FLCEIL;
46 }
47 
48 static inline int
49 xnsynch_fast_owner_check(atomic_t *fastlock, xnhandle_t ownerh)
50 {
51  return (xnhandle_get_id(atomic_read(fastlock)) == ownerh) ?
52  0 : -EPERM;
53 }
54 
55 static inline
56 int xnsynch_fast_acquire(atomic_t *fastlock, xnhandle_t new_ownerh)
57 {
58  xnhandle_t h;
59 
60  h = atomic_cmpxchg(fastlock, XN_NO_HANDLE, new_ownerh);
61  if (h != XN_NO_HANDLE) {
62  if (xnhandle_get_id(h) == new_ownerh)
63  return -EBUSY;
64 
65  return -EAGAIN;
66  }
67 
68  return 0;
69 }
70 
71 static inline
72 int xnsynch_fast_release(atomic_t *fastlock, xnhandle_t cur_ownerh)
73 {
74  return atomic_cmpxchg(fastlock, cur_ownerh, XN_NO_HANDLE)
75  == cur_ownerh;
76 }
77 
78 /* Local/shared property */
79 static inline int xnsynch_is_shared(xnhandle_t handle)
80 {
81  return (handle & XNSYNCH_PSHARED) != 0;
82 }
83 
84 #endif /* !_COBALT_UAPI_KERNEL_SYNCH_H */
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition: atomic.h:24