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