From patchwork Wed May 16 14:18:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 27285 Received: (qmail 9115 invoked by alias); 16 May 2018 14:18:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9041 invoked by uid 89); 16 May 2018 14:18:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 May 2018 14:18:35 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE46640201A1 for ; Wed, 16 May 2018 14:18:33 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FA7210EE961 for ; Wed, 16 May 2018 14:18:33 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 03/10] remote: Make readahead_cache a C++ class Date: Wed, 16 May 2018 15:18:23 +0100 Message-Id: <20180516141830.16859-4-palves@redhat.com> In-Reply-To: <20180516141830.16859-1-palves@redhat.com> References: <20180516141830.16859-1-palves@redhat.com> The idea here is eliminate the get_remote_state calls from within readahead_cache_invalidate, readahead_cache_invalidate_fd, remote_hostio_pread_from_cache by making those functions be class methods instead. Later on we'll have one readahead_cache instance per remote connection, and this change makes that easier. gdb/ChangeLog: 2018-05-07 Pedro Alves * remote.c (struct readahead_cache) : New method declarations. (remote_target::open_1): Adjust. (readahead_cache_invalidate): Rename to ... (readahead_cache::invalidate): ... this, and adjust to be a class method. (readahead_cache_invalidate_fd): Rename to ... (readahead_cache::invalidate_fd): ... this, and adjust to be a class method. (remote_hostio_pwrite): Adjust. (remote_hostio_pread_from_cache): Rename to ... (readahead_cache::pread): ... this, and adjust to be a class method. (remote_hostio_close): Adjust. --- gdb/remote.c | 70 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index bc4815c67e..a416d9285b 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -518,8 +518,6 @@ static void remote_btrace_maybe_reopen (void); static int stop_reply_queue_length (void); -static void readahead_cache_invalidate (void); - static void remote_unpush_and_throw (void); static struct remote_state *get_remote_state (void); @@ -575,6 +573,16 @@ typedef unsigned char threadref[OPAQUETHREADBYTES]; struct readahead_cache { + /* Invalidate the readahead cache. */ + void invalidate (); + + /* Invalidate the readahead cache if it is holding data for FD. */ + void invalidate_fd (int fd); + + /* Serve pread from the readahead cache. Returns number of bytes + read, or 0 if the request can't be served from the cache. */ + int pread (int fd, gdb_byte *read_buf, size_t len, ULONGEST offset); + /* The file descriptor for the file that is being cached. -1 if the cache is invalid. */ int fd = -1; @@ -5299,7 +5307,7 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p) rs->use_threadinfo_query = 1; rs->use_threadextra_query = 1; - readahead_cache_invalidate (); + rs->readahead_cache.invalidate (); if (target_async_permitted) { @@ -11668,25 +11676,21 @@ remote_hostio_send_command (int command_bytes, int which_packet, return ret; } -/* Invalidate the readahead cache. */ +/* See declaration.h. */ -static void -readahead_cache_invalidate (void) +void +readahead_cache::invalidate () { - struct remote_state *rs = get_remote_state (); - - rs->readahead_cache.fd = -1; + this->fd = -1; } -/* Invalidate the readahead cache if it is holding data for FD. */ +/* See declaration.h. */ -static void -readahead_cache_invalidate_fd (int fd) +void +readahead_cache::invalidate_fd (int fd) { - struct remote_state *rs = get_remote_state (); - - if (rs->readahead_cache.fd == fd) - rs->readahead_cache.fd = -1; + if (this->fd == fd) + this->fd = -1; } /* Set the filesystem remote_hostio functions that take FILENAME @@ -11793,7 +11797,7 @@ remote_hostio_pwrite (struct target_ops *self, int left = get_remote_packet_size (); int out_len; - readahead_cache_invalidate_fd (fd); + rs->readahead_cache.invalidate_fd (fd); remote_buffer_add_string (&p, &left, "vFile:pwrite:"); @@ -11857,26 +11861,22 @@ remote_hostio_pread_vFile (struct target_ops *self, return ret; } -/* Serve pread from the readahead cache. Returns number of bytes - read, or 0 if the request can't be served from the cache. */ +/* See declaration.h. */ -static int -remote_hostio_pread_from_cache (struct remote_state *rs, - int fd, gdb_byte *read_buf, size_t len, - ULONGEST offset) +int +readahead_cache::pread (int fd, gdb_byte *read_buf, size_t len, + ULONGEST offset) { - struct readahead_cache *cache = &rs->readahead_cache; - - if (cache->fd == fd - && cache->offset <= offset - && offset < cache->offset + cache->bufsize) + if (this->fd == fd + && this->offset <= offset + && offset < this->offset + this->bufsize) { - ULONGEST max = cache->offset + cache->bufsize; + ULONGEST max = this->offset + this->bufsize; if (offset + len > max) len = max - offset; - memcpy (read_buf, cache->buf + offset - cache->offset, len); + memcpy (read_buf, this->buf + offset - this->offset, len); return len; } @@ -11892,9 +11892,9 @@ remote_hostio_pread (struct target_ops *self, { int ret; struct remote_state *rs = get_remote_state (); - struct readahead_cache *cache = &rs->readahead_cache; + readahead_cache *cache = &rs->readahead_cache; - ret = remote_hostio_pread_from_cache (rs, fd, read_buf, len, offset); + ret = cache->pread (fd, read_buf, len, offset); if (ret > 0) { cache->hit_count++; @@ -11919,12 +11919,12 @@ remote_hostio_pread (struct target_ops *self, cache->offset, remote_errno); if (ret <= 0) { - readahead_cache_invalidate_fd (fd); + cache->invalidate_fd (fd); return ret; } cache->bufsize = ret; - return remote_hostio_pread_from_cache (rs, fd, read_buf, len, offset); + return cache->pread (fd, read_buf, len, offset); } int @@ -11943,7 +11943,7 @@ remote_hostio_close (struct target_ops *self, int fd, int *remote_errno) char *p = rs->buf; int left = get_remote_packet_size () - 1; - readahead_cache_invalidate_fd (fd); + rs->readahead_cache.invalidate_fd (fd); remote_buffer_add_string (&p, &left, "vFile:close:");