Rev 3573 | Rev 3575 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3573 | Rev 3574 | ||
---|---|---|---|
Line 100... | Line 100... | ||
100 | 100 | ||
101 | b->dirty = true; /* need to sync block */ |
101 | b->dirty = true; /* need to sync block */ |
102 | block_put(b); |
102 | block_put(b); |
103 | } |
103 | } |
104 | 104 | ||
- | 105 | static fat_node_t *fat_node_get_new(void) |
|
- | 106 | { |
|
- | 107 | fat_node_t *nodep; |
|
- | 108 | ||
- | 109 | futex_down(&ffn_futex); |
|
- | 110 | if (!list_empty(&ffn_head)) { |
|
- | 111 | /* Try to use a cached free node structure. */ |
|
- | 112 | fat_idx_t *idxp_tmp; |
|
- | 113 | nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link); |
|
- | 114 | if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK) |
|
- | 115 | goto skip_cache; |
|
- | 116 | idxp_tmp = nodep->idx; |
|
- | 117 | if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) { |
|
- | 118 | futex_up(&nodep->lock); |
|
- | 119 | goto skip_cache; |
|
- | 120 | } |
|
- | 121 | list_remove(&nodep->ffn_link); |
|
- | 122 | futex_up(&ffn_futex); |
|
- | 123 | if (nodep->dirty) |
|
- | 124 | fat_node_sync(nodep); |
|
- | 125 | idxp_tmp->nodep = NULL; |
|
- | 126 | futex_up(&nodep->lock); |
|
- | 127 | futex_up(&idxp_tmp->lock); |
|
- | 128 | } else { |
|
- | 129 | skip_cache: |
|
- | 130 | /* Try to allocate a new node structure. */ |
|
- | 131 | futex_up(&ffn_futex); |
|
- | 132 | nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); |
|
- | 133 | if (!nodep) |
|
- | 134 | return NULL; |
|
- | 135 | } |
|
- | 136 | fat_node_initialize(nodep); |
|
- | 137 | ||
- | 138 | return nodep; |
|
- | 139 | } |
|
- | 140 | ||
105 | /** Internal version of fat_node_get(). |
141 | /** Internal version of fat_node_get(). |
106 | * |
142 | * |
107 | * @param idxp Locked index structure. |
143 | * @param idxp Locked index structure. |
108 | */ |
144 | */ |
109 | static void *fat_node_get_core(fat_idx_t *idxp) |
145 | static void *fat_node_get_core(fat_idx_t *idxp) |
Line 132... | Line 168... | ||
132 | * We must instantiate the node from the file system. |
168 | * We must instantiate the node from the file system. |
133 | */ |
169 | */ |
134 | 170 | ||
135 | assert(idxp->pfc); |
171 | assert(idxp->pfc); |
136 | 172 | ||
137 | futex_down(&ffn_futex); |
- | |
138 | if (!list_empty(&ffn_head)) { |
- | |
139 | /* Try to use a cached free node structure. */ |
- | |
140 | fat_idx_t *idxp_tmp; |
- | |
141 | nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link); |
- | |
142 | if (futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK) |
- | |
143 | goto skip_cache; |
- | |
144 | idxp_tmp = nodep->idx; |
- | |
145 | if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) { |
- | |
146 | futex_up(&nodep->lock); |
- | |
147 | goto skip_cache; |
- | |
148 | } |
- | |
149 | list_remove(&nodep->ffn_link); |
- | |
150 | futex_up(&ffn_futex); |
- | |
151 | if (nodep->dirty) |
- | |
152 | fat_node_sync(nodep); |
173 | nodep = fat_node_get_new(); |
153 | idxp_tmp->nodep = NULL; |
- | |
154 | futex_up(&nodep->lock); |
- | |
155 | futex_up(&idxp_tmp->lock); |
- | |
156 | } else { |
- | |
157 | skip_cache: |
- | |
158 | /* Try to allocate a new node structure. */ |
- | |
159 | futex_up(&ffn_futex); |
- | |
160 | nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); |
- | |
161 | if (!nodep) |
174 | if (!nodep) |
162 | return NULL; |
175 | return NULL; |
163 | } |
- | |
164 | fat_node_initialize(nodep); |
- | |
165 | 176 | ||
166 | bs = block_bb_get(idxp->dev_handle); |
177 | bs = block_bb_get(idxp->dev_handle); |
167 | bps = uint16_t_le2host(bs->bps); |
178 | bps = uint16_t_le2host(bs->bps); |
168 | spc = bs->spc; |
179 | spc = bs->spc; |
169 | dps = bps / sizeof(fat_dentry_t); |
180 | dps = bps / sizeof(fat_dentry_t); |