[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] threads: add virThreadID for debugging use



2010/12/4 Eric Blake <eblake redhat com>:
> * src/util/threads.h (virThreadID): New prototype.
> * src/util/threads-pthread.c (virThreadID): New function.
> * src/util/threads-win32.c (virThreadID): Likewise.
> * src/libvirt_private.syms (threads.h): Export it.
> * daemon/event.c (virEventInterruptLocked): Use it to avoid
> warning on BSD systems.
> ---


> diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c
> index bff4979..826b9d1 100644
> --- a/src/util/threads-pthread.c
> +++ b/src/util/threads-pthread.c

> @@ -197,6 +198,11 @@ int virThreadSelfID(void)
>  #endif
>  }
>
> +int virThreadID(virThreadPtr thread)
> +{
> +    return (int)(uintptr_t)thread->thread;
> +}
> +
>  void virThreadJoin(virThreadPtr thread)
>  {
>     pthread_join(thread->thread, NULL);
> diff --git a/src/util/threads-win32.c b/src/util/threads-win32.c
> index 436b3bd..2f4bcfc 100644
> --- a/src/util/threads-win32.c
> +++ b/src/util/threads-win32.c
> @@ -304,6 +304,11 @@ int virThreadSelfID(void)
>     return (int)GetCurrentThreadId();
>  }
>
> +int virThreadID(virThreadPtr thread)
> +{
> +    return (int)thread->thread;
> +}
> +
>
>  void virThreadJoin(virThreadPtr thread)
>  {
> diff --git a/src/util/threads.h b/src/util/threads.h
> index fa00a91..de28db6 100644
> --- a/src/util/threads.h
> +++ b/src/util/threads.h
> @@ -51,7 +51,12 @@ int virThreadCreate(virThreadPtr thread,
>  void virThreadSelf(virThreadPtr thread);
>  bool virThreadIsSelf(virThreadPtr thread);
>  void virThreadJoin(virThreadPtr thread);
> +
> +/* These next two functions are for debugging only, since they are not
> + * guaranteed to give unique values for distinct threads on all
> + * architectures. */
>  int virThreadSelfID(void);
> +int virThreadID(virThreadPtr thread);
>

This solve the problem, but it should also be noted that
virThreadSelfID and virThreadID cannot be used for comparison as they
are not taken from the same source.

ACK.

Matthias


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]