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