[ 
https://issues.apache.org/jira/browse/HADOOP-11638?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14357133#comment-14357133
 ] 

Kiran Kumar M R commented on HADOOP-11638:
------------------------------------------

I have added new patch-004 to include Mac OS specific code.
Mac has {{int pthread_threadid_np(pthread_t thread, uint64_t *thread_id)}} 
method to get thread id 
- Its declared in {{pthread.h}} Refer 
https://opensource.apple.com/source/libpthread/libpthread-105.1.4/pthread/pthread.h
- Its implementation can be seen at 
https://opensource.apple.com/source/libpthread/libpthread-105.1.4/src/pthread.c
- Its usage can be seen at 
https://opensource.apple.com/source/libpthread/libpthread-105.1.4/src/pthread_rwlock.c
 as below
{code}
  uint64_t myid;
  (void)pthread_threadid_np(pthread_self(), &myid);
{code}

Now my patch code is:
{code}
static unsigned long pthreads_thread_id(void)
{
  unsigned long thread_id = 0;
#if defined(__linux__)
  thread_id = (unsigned long)syscall(SYS_gettid);
#elif defined(__FreeBSD__)
  thread_id = (unsigned long)pthread_getthreadid_np();
#elif defined(__sun)
  thread_id = (unsigned long)pthread_self();
#elif defined(__APPLE__ )
  (void)pthread_threadid_np(pthread_self(), &thread_id);
#else
#error "Platform not supported"
#endif
  return thread_id;
}
{code}

[~cnauroth], please check if patch-004 works on Mac


> OpensslSecureRandom.c pthreads_thread_id should support FreeBSD and Solaris 
> in addition to Linux
> ------------------------------------------------------------------------------------------------
>
>                 Key: HADOOP-11638
>                 URL: https://issues.apache.org/jira/browse/HADOOP-11638
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: native
>    Affects Versions: 2.6.0
>            Reporter: Dmitry Sivachenko
>            Assignee: Kiran Kumar M R
>              Labels: freebsd
>         Attachments: HADOOP-11638-001.patch, HADOOP-11638-002.patch, 
> HADOOP-11638-003.patch, HADOOP-11638-004.patch
>
>
> In OpensslSecureRandom.c you use Linux-specific syscall gettid():
> static unsigned long pthreads_thread_id(void)
> {
> return (unsigned long)syscall(SYS_gettid);
> }
> Man page says:
> gettid()  is Linux-specific and should not be used in programs that are
> intended to be portable.
> This breaks hadoop-2.6.0 compilation on FreeBSD (may be on other OSes too).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to