4 * @brief Implements the subdevice lock class.
5 * @note Copyright (C) 2006 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
10 * Copyright (C) 2006 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/spinlock.h>
29 #include "medefines.h"
35 int me_slock_enter(struct me_slock
*slock
, struct file
*filep
)
37 PDEBUG_LOCKS("executed.\n");
39 spin_lock(&slock
->spin_lock
);
41 if ((slock
->filep
) != NULL
&& (slock
->filep
!= filep
)) {
42 PERROR("Subdevice is locked by another process.\n");
43 spin_unlock(&slock
->spin_lock
);
44 return ME_ERRNO_LOCKED
;
49 spin_unlock(&slock
->spin_lock
);
51 return ME_ERRNO_SUCCESS
;
54 int me_slock_exit(struct me_slock
*slock
, struct file
*filep
)
56 PDEBUG_LOCKS("executed.\n");
58 spin_lock(&slock
->spin_lock
);
60 spin_unlock(&slock
->spin_lock
);
62 return ME_ERRNO_SUCCESS
;
65 int me_slock_lock(struct me_slock
*slock
, struct file
*filep
, int lock
)
67 PDEBUG_LOCKS("executed.\n");
72 spin_lock(&slock
->spin_lock
);
74 if (slock
->filep
== filep
)
77 spin_unlock(&slock
->spin_lock
);
82 spin_lock(&slock
->spin_lock
);
85 spin_unlock(&slock
->spin_lock
);
86 PERROR("Subdevice is used by another process.\n");
88 } else if (slock
->filep
== NULL
)
90 else if (slock
->filep
!= filep
) {
91 spin_unlock(&slock
->spin_lock
);
92 PERROR("Subdevice is locked by another process.\n");
93 return ME_ERRNO_LOCKED
;
96 spin_unlock(&slock
->spin_lock
);
101 spin_lock(&slock
->spin_lock
);
104 spin_unlock(&slock
->spin_lock
);
105 return ME_ERRNO_USED
;
106 } else if ((slock
->filep
!= NULL
) && (slock
->filep
!= filep
)) {
107 spin_unlock(&slock
->spin_lock
);
108 return ME_ERRNO_LOCKED
;
111 spin_unlock(&slock
->spin_lock
);
119 return ME_ERRNO_SUCCESS
;
122 void me_slock_deinit(struct me_slock
*slock
)
124 PDEBUG_LOCKS("executed.\n");
127 int me_slock_init(me_slock_t
*slock
)
129 PDEBUG_LOCKS("executed.\n");
133 spin_lock_init(&slock
->spin_lock
);