This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v6] gdb: ADI support


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 (齐尧)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]