IgH EtherCAT Master  1.5.2
locks.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #ifndef __EC_LOCKS_H__
38 #define __EC_LOCKS_H__
39 
40 #include "globals.h"
41 
42 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
43 #include <linux/semaphore.h>
44 #else
45 #include <asm/semaphore.h>
46 #endif
47 
48 /*****************************************************************************/
49 
50 #ifdef EC_USE_RTMUTEX
51 
52 #include <linux/rtmutex.h>
53 
54 typedef struct rt_mutex ec_lock_t;
55 
56 static inline void ec_lock_init(ec_lock_t *sem) { rt_mutex_init(sem); }
57 static inline void ec_lock_down(ec_lock_t *sem) { rt_mutex_lock(sem); }
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 34)
59 static inline int ec_lock_down_interruptible(ec_lock_t *sem) { return rt_mutex_lock_interruptible(sem); }
60 #else
61 static inline int ec_lock_down_interruptible(ec_lock_t *sem) { return rt_mutex_lock_interruptible(sem, 1); }
62 #endif
63 static inline void ec_lock_up(ec_lock_t *sem) { rt_mutex_unlock(sem); }
64 
65 #else
66 
67 typedef struct semaphore ec_lock_t;
68 
69 static inline void ec_lock_init(ec_lock_t *sem) { sema_init(sem, 1); }
70 static inline void ec_lock_down(ec_lock_t *sem) { down(sem); }
71 static inline int ec_lock_down_interruptible(ec_lock_t *sem) { return down_interruptible(sem); }
72 static inline void ec_lock_up(ec_lock_t *sem) { up(sem); }
73 
74 #endif
75 
76 /*****************************************************************************/
77 
78 #endif
79 
80 /*****************************************************************************/
Global definitions and macros.