Changeset 65591


Ignore:
Timestamp:
Jul 14, 2015, 8:18:21 PM (9 years ago)
Author:
glynn
Message:

Prevent concurrent raster reads when a mask is present

File:
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/raster/r.mapcalc/map.c

    r63859 r65591  
    7272static int num_maps;
    7373static int max_maps;
     74static int masking;
    7475
    7576static int min_row = INT_MAX;
     
    8283#ifdef HAVE_PTHREAD_H
    8384static pthread_mutex_t cats_mutex;
    84 #endif
    85 
    86 /****************************************************************************/
     85static pthread_mutex_t mask_mutex;
     86#endif
     87
     88/****************************************************************************/
     89
     90static void read_row(int fd, void *buf, int row, int res_type)
     91{
     92#ifdef HAVE_PTHREAD_H
     93    if (masking)
     94        pthread_mutex_lock(&mask_mutex);
     95#endif
     96    Rast_get_row(fd, buf, row, res_type);
     97#ifdef HAVE_PTHREAD_H
     98    if (masking)
     99        pthread_mutex_unlock(&mask_mutex);
     100#endif
     101}
    87102
    88103static void cache_sub_init(struct row_cache *cache, int data_type)
     
    146161    if (i >= 0 && i < cache->nrows) {
    147162        if (!sub->valid[i]) {
    148             Rast_get_row(cache->fd, sub->buf[i], row + i, data_type);
     163            read_row(cache->fd, sub->buf[i], row + i, data_type);
    149164            sub->valid[i] = 1;
    150165        }
     
    155170        memset(sub->valid, 0, cache->nrows);
    156171        sub->row = i;
    157         Rast_get_row(cache->fd, sub->buf[0], row, data_type);
     172        read_row(cache->fd, sub->buf[0], row, data_type);
    158173        sub->valid[0] = 1;
    159174        return sub->buf[0];
     
    183198    G_freea(vtmp);
    184199
    185     Rast_get_row(cache->fd, sub->buf[i], row, data_type);
     200    read_row(cache->fd, sub->buf[i], row, data_type);
    186201    sub->valid[i] = 1;
    187202
     
    366381}
    367382
    368 static void read_row(int fd, void *buf, int row, int res_type)
    369 {
    370     Rast_get_row(fd, buf, row, res_type);
    371 }
    372 
    373383static void setup_map(struct map *m)
    374384{
     
    577587#ifdef HAVE_PTHREAD_H
    578588    pthread_mutex_init(&cats_mutex, NULL);
     589    pthread_mutex_init(&mask_mutex, NULL);
     590    masking = Rast_maskfd() >= 0;
    579591#endif
    580592
     
    636648#ifdef HAVE_PTHREAD_H
    637649    pthread_mutex_destroy(&cats_mutex);
     650    pthread_mutex_destroy(&mask_mutex);
    638651#endif
    639652}
Note: See TracChangeset for help on using the changeset viewer.