From: Yao Qi <qiyaoltc@gmail.com>
To: Weimin Pan <weimin.pan@oracle.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v6] gdb: ADI support
Date: Mon, 07 Aug 2017 11:10:00 -0000 [thread overview]
Message-ID: <86efsn1vne.fsf@gmail.com> (raw)
In-Reply-To: <1501885950-125523-1-git-send-email-weimin.pan@oracle.com> (Weimin Pan's message of "Fri, 4 Aug 2017 17:32:30 -0500")
Weimin Pan <weimin.pan@oracle.com> writes:
> +/* ADI stat settings. */
> +typedef struct
> +{
> + /* The ADI block size. */
> + unsigned long blksize;
> +
> + /* Number of bits used for an ADI version tag which can be
> + * used together with the shift value for an ADI version tag
> + * to encode or extract the ADI version value in a pointer. */
> + unsigned long nbits;
> +
> + /* The maximum ADI version tag value supported. */
> + int max_version;
> +
> + /* ADI version tag file. */
> + int tag_fd;
You can do in-class initialization for these fields,
int tag_fd = 0;
> +
> + /* ADI availability check has been done. */
> + bool checked_avail;
> +
bool checked_avail = false;
> + /* ADI is available. */
> + bool is_avail;
> +
> +} adi_stat_t;
> +
> +/* Per-process ADI stat info. */
> +
> +typedef struct
> +{
and add constructor,
sparc64_adi_info (pid_t pid_)
: pid (pid_)
{}
> + /* The process identifier. */
> + pid_t pid;
> +
> + /* The ADI stat. */
> + adi_stat_t stat;
> +
and in-class initialization,
adi_stat_t state = {};
> +} sparc64_adi_info;
> +
> +static std::forward_list<sparc64_adi_info> adi_proc_list;
> +
> +/* Find ADI info for process PID. */
> +
> +static sparc64_adi_info *
> +find_adi_info (pid_t pid)
> +{
> + for (auto &it : adi_proc_list)
> + if (it.pid == pid)
> + return &(it);
> +
> + return NULL;
> +}
> +
> +/* Add ADI info for process PID. Returns newly allocated info
> + object. */
> +
> +static sparc64_adi_info *
> +add_adi_info (pid_t pid)
> +{
> + sparc64_adi_info proc;
> +
> + proc.pid = pid;
> + proc.stat.is_avail = false;
> + proc.stat.checked_avail = false;
> + proc.stat.tag_fd = 0;
> + adi_proc_list.push_front (proc);
> + auto it = adi_proc_list.begin ();
> + return &(*it);
> +}
> +
> +/* Get ADI info for process PID, creating one if it doesn't exist. */
> +
> +static sparc64_adi_info *
> +get_adi_info_proc (pid_t pid)
> +{
> + sparc64_adi_info *proc;
> +
> + proc = find_adi_info (pid);
> + if (proc == NULL)
> + proc = add_adi_info (pid);
> +
> + return proc;
then, we can rewrite it in a simple way,
auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (),
[&pid] (const sparc64_adi_info &info)
{
return info.pid == pid;
});
if (found == adi_proc_list.end ())
{
adi_proc_list.emplace_front (pid);
return &adi_proc_list.front ();
}
else
{
return &(*found);
}
> +}
> +
> +static adi_stat_t
> +get_adi_info (pid_t pid)
> +{
> + sparc64_adi_info *proc;
> +
> + proc = get_adi_info_proc (pid);
> + return proc->stat;
> +}
> +
--
Yao (齐尧)
next prev parent reply other threads:[~2017-08-07 11:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-04 22:41 Weimin Pan
2017-08-07 11:10 ` Yao Qi [this message]
2017-08-18 0:09 ` Wei-min Pan
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=86efsn1vne.fsf@gmail.com \
--to=qiyaoltc@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=weimin.pan@oracle.com \
/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).