From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/10] remote: Make readahead_cache a C++ class
Date: Wed, 16 May 2018 14:25:00 -0000 [thread overview]
Message-ID: <20180516141830.16859-4-palves@redhat.com> (raw)
In-Reply-To: <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 <palves@redhat.com>
* remote.c (struct readahead_cache) <invalidate, invalidate_fd,
pread>: 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:");
--
2.14.3
next prev parent reply other threads:[~2018-05-16 14:18 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-16 14:18 [PATCH 00/10] remote: More multi-target preparation Pedro Alves
2018-05-16 14:18 ` [PATCH 10/10] remote: one struct remote_state per struct remote_target Pedro Alves
2018-05-22 5:07 ` Simon Marchi
2018-05-22 21:06 ` Pedro Alves
2018-05-24 17:00 ` [PATCH 11/10] remote_target::m_remote_state, pointer -> object (Re: [PATCH 10/10] remote: one struct remote_state per struct remote_target) Pedro Alves
2018-05-25 5:23 ` Simon Marchi
2018-05-16 14:18 ` [PATCH 02/10] remote: Eliminate remote_hostio_close_cleanup Pedro Alves
2018-05-16 17:43 ` Tom Tromey
2018-05-16 18:53 ` Pedro Alves
2018-05-16 19:46 ` Tom Tromey
2018-05-18 21:04 ` Simon Marchi
2018-05-16 14:18 ` [PATCH 01/10] remote: struct remote_state, use op new Pedro Alves
2018-05-18 20:57 ` Simon Marchi
2018-05-21 15:36 ` [PATCH 1.2 01/10] remote: struct remote_state, use op new, fix leaks Pedro Alves
2018-05-16 14:18 ` [PATCH 09/10] remote: Make vcont_builder a class Pedro Alves
2018-05-22 5:07 ` Simon Marchi
2018-05-22 21:33 ` Pedro Alves
2018-05-16 14:25 ` Pedro Alves [this message]
2018-05-18 21:06 ` [PATCH 03/10] remote: Make readahead_cache a C++ class Simon Marchi
2018-05-16 14:25 ` [PATCH 05/10] remote: remote_arch_state pointers -> remote_arch_state objects Pedro Alves
2018-05-18 21:17 ` Simon Marchi
2018-05-18 21:18 ` Simon Marchi
2018-05-21 16:12 ` Pedro Alves
2018-05-16 14:27 ` [PATCH 04/10] remote: multiple remote_arch_state instances per arch Pedro Alves
2018-05-18 21:09 ` Simon Marchi
2018-05-16 14:28 ` [PATCH 08/10] Handle "show remote memory-write-packet-size" when not connected Pedro Alves
2018-05-18 21:42 ` Simon Marchi
2018-05-21 20:41 ` Pedro Alves
2018-05-22 3:37 ` Simon Marchi
2018-05-22 21:55 ` Sergio Durigan Junior
2018-05-22 23:26 ` [pushed] Fix gdb.base/remote.exp with native-extended-gdbserver board (Re: [PATCH 08/10] Handle "show remote memory-write-packet-size" when not connected) Pedro Alves
2018-05-16 15:46 ` [PATCH 07/10] remote: Move discard_pending_stop_replies call Pedro Alves
2018-05-18 21:29 ` Simon Marchi
2018-05-16 15:50 ` [PATCH 06/10] remote: Small cleanup in compare_section_command Pedro Alves
2018-05-18 21:26 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180516141830.16859-4-palves@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).