[Mesa-dev] [PATCH 6/7] util/disk_cache: add a write helper

Timothy Arceri tarceri at itsqueeze.com
Thu Mar 16 01:00:19 UTC 2017



On 16/03/17 10:09, Grazvydas Ignotas wrote:
> Simplifies the write code a bit and handles EINTR.
>
> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
> ---
>  src/util/disk_cache.c | 40 ++++++++++++++++++++++++++--------------
>  1 file changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index 904aa66..ad591be 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -650,6 +650,24 @@ disk_cache_remove(struct disk_cache *cache, const cache_key key)
>        p_atomic_add(cache->size, - (uint64_t)sb.st_size);
>  }
>
> +static ssize_t
> +write_all(int fd, const void *buf, size_t count)
> +{
> +   const char *out = buf;
> +   ssize_t written;
> +   size_t done;
> +
> +   for (done = 0; done < count; done += written) {
> +      written = write(fd, out + done, count - done);
> +      if (written == -1) {
> +         if (errno != EINTR)
> +            return -1;
> +         written = 0;

I considered doing this but it didn't seem worth it. Also should you add 
a retry limit? It's probably unlikely but I guess we could get stuck in 
a loop here in theory?



More information about the mesa-dev mailing list