ASoC: Remove duplicate ADC/DAC widgets from wm_hubs.c
[linux/fpc-iii.git] / drivers / staging / meilhaus / meslock.c
blobabcdb4a2eba68fb748e577f68296932e65e83d97
1 /**
2 * @file meslock.c
4 * @brief Implements the subdevice lock class.
5 * @note Copyright (C) 2006 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 */
9 /*
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"
30 #include "meerror.h"
32 #include "medebug.h"
33 #include "meslock.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;
47 slock->count++;
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);
59 slock->count--;
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");
69 switch (lock) {
71 case ME_LOCK_RELEASE:
72 spin_lock(&slock->spin_lock);
74 if (slock->filep == filep)
75 slock->filep = NULL;
77 spin_unlock(&slock->spin_lock);
79 break;
81 case ME_LOCK_SET:
82 spin_lock(&slock->spin_lock);
84 if (slock->count) {
85 spin_unlock(&slock->spin_lock);
86 PERROR("Subdevice is used by another process.\n");
87 return ME_ERRNO_USED;
88 } else if (slock->filep == NULL)
89 slock->filep = filep;
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);
98 break;
100 case ME_LOCK_CHECK:
101 spin_lock(&slock->spin_lock);
103 if (slock->count) {
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);
113 break;
115 default:
116 break;
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");
131 slock->filep = NULL;
132 slock->count = 0;
133 spin_lock_init(&slock->spin_lock);
135 return 0;