1 /*
2 This file is part of UFFS, the Ultra-low-cost Flash File System.
3
4 Copyright (C) 2005-2009 Ricky Zheng <[email protected]>
5
6 UFFS is free software; you can redistribute it and/or modify it under
7 the GNU Library General Public License as published by the Free Software
8 Foundation; either version 2 of the License, or (at your option) any
9 later version.
10
11 UFFS is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 or GNU Library General Public License, as applicable, for more details.
15
16 You should have received a copy of the GNU General Public License
17 and GNU Library General Public License along with UFFS; if not, write
18 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 As a special exception, if other files instantiate templates or use
22 macros or inline functions from this file, or you compile this file
23 and link it with other works to produce a work based on this file,
24 this file does not by itself cause the resulting work to be covered
25 by the GNU General Public License. However the source code for this
26 file must still be made available in accordance with section (3) of
27 the GNU General Public License v2.
28
29 This exception does not invalidate any other reasons why a work based
30 on this file might be covered by the GNU General Public License.
31 */
32
33 /**
34 * \file uffs_device.c
35 * \brief uffs device operation
36 * \author Ricky Zheng, created 10th May, 2005
37 */
38 #include "uffs_config.h"
39 #include "uffs/uffs_device.h"
40 #include "uffs/uffs_os.h"
41 #include "uffs/uffs_public.h"
42 #include "uffs/uffs_mtb.h"
43 #include <string.h>
44
45 #define PFX "dev : "
46
47
48 #ifdef CONFIG_USE_PER_DEVICE_LOCK
uffs_DeviceInitLock(uffs_Device * dev)49 void uffs_DeviceInitLock(uffs_Device *dev)
50 {
51 uffs_SemCreate(&dev->lock.sem);
52 dev->lock.task_id = UFFS_TASK_ID_NOT_EXIST;
53 dev->lock.counter = 0;
54 }
55
uffs_DeviceReleaseLock(uffs_Device * dev)56 void uffs_DeviceReleaseLock(uffs_Device *dev)
57 {
58 uffs_SemDelete(&dev->lock.sem);
59 }
60
uffs_DeviceLock(uffs_Device * dev)61 void uffs_DeviceLock(uffs_Device *dev)
62 {
63 uffs_SemWait(dev->lock.sem);
64
65 if (dev->lock.counter != 0) {
66 uffs_Perror(UFFS_MSG_NORMAL,
67 "Lock device, counter %d NOT zero?!", dev->lock.counter);
68 }
69
70 dev->lock.counter++;
71 }
72
uffs_DeviceUnLock(uffs_Device * dev)73 void uffs_DeviceUnLock(uffs_Device *dev)
74 {
75 dev->lock.counter--;
76
77 if (dev->lock.counter != 0) {
78 uffs_Perror(UFFS_MSG_NORMAL,
79 "Unlock device, counter %d NOT zero?!", dev->lock.counter);
80 }
81
82 uffs_SemSignal(dev->lock.sem);
83 }
84
85 #else
86
87 /* dummy stubs */
uffs_DeviceInitLock(uffs_Device * dev)88 void uffs_DeviceInitLock(uffs_Device *dev) {}
uffs_DeviceReleaseLock(uffs_Device * dev)89 void uffs_DeviceReleaseLock(uffs_Device *dev) {}
uffs_DeviceLock(uffs_Device * dev)90 void uffs_DeviceLock(uffs_Device *dev) {}
uffs_DeviceUnLock(uffs_Device * dev)91 void uffs_DeviceUnLock(uffs_Device *dev) {}
92
93 #endif
94