+2018-05-22 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.
+
2018-05-22 Pedro Alves <palves@redhat.com>
* remote.c (remote_hostio_close_cleanup): Delete.
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);
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;
rs->use_threadinfo_query = 1;
rs->use_threadextra_query = 1;
- readahead_cache_invalidate ();
+ rs->readahead_cache.invalidate ();
if (target_async_permitted)
{
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
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:");
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;
}
{
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++;
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
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:");