comparison src/lib-index/mail-cache-fields.c @ 2929:ba9062032877 HEAD

Locking fixes and cleanups
author Timo Sirainen <tss@iki.fi>
date Sat, 04 Dec 2004 23:55:41 +0200
parents d416b6d0a7ee
children 2ab037df6cf3
comparison
equal deleted inserted replaced
2928:3470bb04fb57 2929:ba9062032877
273 byte = (uint8_t)*data; 273 byte = (uint8_t)*data;
274 buffer_append(dest, &byte, 1); 274 buffer_append(dest, &byte, 1);
275 } 275 }
276 } 276 }
277 277
278 int mail_cache_header_fields_update(struct mail_cache *cache) 278 static int mail_cache_header_fields_update_locked(struct mail_cache *cache)
279 { 279 {
280 int locked = cache->locked;
281 buffer_t *buffer; 280 buffer_t *buffer;
282 uint32_t i, offset; 281 uint32_t i, offset;
283 int ret = 0; 282 int ret = 0;
284 283
285 if (!locked) {
286 if (mail_cache_lock(cache) <= 0)
287 return -1;
288 }
289
290 if (mail_cache_header_fields_read(cache) < 0 || 284 if (mail_cache_header_fields_read(cache) < 0 ||
291 mail_cache_header_fields_get_offset(cache, &offset) < 0) { 285 mail_cache_header_fields_get_offset(cache, &offset) < 0)
292 mail_cache_unlock(cache); 286 return -1;
293 return -1;
294 }
295 287
296 t_push(); 288 t_push();
297 buffer = buffer_create_dynamic(pool_datastack_create(), 256); 289 buffer = buffer_create_dynamic(pool_datastack_create(), 256);
298 290
299 copy_to_buf(cache, buffer, 291 copy_to_buf(cache, buffer,
319 t_pop(); 311 t_pop();
320 312
321 if (ret == 0) 313 if (ret == 0)
322 cache->field_header_write_pending = FALSE; 314 cache->field_header_write_pending = FALSE;
323 315
324 if (!locked) 316 return ret;
325 mail_cache_unlock(cache); 317 }
318
319 int mail_cache_header_fields_update(struct mail_cache *cache)
320 {
321 int ret;
322
323 if (cache->locked)
324 return mail_cache_header_fields_update_locked(cache);
325
326 if (mail_cache_lock(cache) <= 0)
327 return -1;
328
329 ret = mail_cache_header_fields_update_locked(cache);
330 mail_cache_unlock(cache);
326 return ret; 331 return ret;
327 } 332 }
328 333
329 void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest) 334 void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest)
330 { 335 {