Question about OpenSSL id_function() and pthreads
David Xu
davidxu at viatech.com.cn
Wed May 28 18:51:31 PDT 2003
----- Original Message -----
From: "Craig Rodrigues" <rodrigc at attbi.com>
To: <freebsd-threads at freebsd.org>
Sent: Thursday, May 29, 2003 7:51 AM
Subject: Question about OpenSSL id_function() and pthreads
> Hi,
>
> I previously asked this question on freebsd-security@ and
> freebsd-current@ :
>
> http://docs.freebsd.org/cgi/getmsg.cgi?fetch=63674+0+archive/2003/freebsd-security/20030302.freebsd-security
>
>
> Let me try again, now that there is a freebsd-threads mailing list.
>
>
> On the following OpenSSL web page:
> http://www.openssl.org/docs/crypto/threads.html
>
> "void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
>
> id_function(void) is a function that returns a thread ID.
> It is not needed on Windows nor on platforms where getpid() returns
> a different ID for each thread (most notably Linux)."
>
>
> I have some third party C++ code which tries to implements this function:
>
> tatic unsigned long
> idFunction()
> {
> #ifdef _WIN32
> return static_cast<unsigned long>(GetCurrentThreadId());
> #else
> return static_cast<unsigned long>(pthread_self());
> #endif
> }
>
>
> This code does not compile on FreeBSD-CURRENT:
>
> OpenSSLPluginI.cpp: In function `long unsigned int idFunction()':
> OpenSSLPluginI.cpp:151: invalid static_cast from type `pthread*' to type `long
> unsigned int'
>
>
> How can I implement this function properly on FreeBSD?
>
Why don't you change an abused static_cast to use C convertion
directly like this:
static unsigned long
idFunction()
{
#ifdef _WIN32
return static_cast<unsigned long>(GetCurrentThreadId());
#else
return (unsigned long)pthread_self();
#endif
}
Don't be confused by mincing C++.
David Xu
More information about the freebsd-threads
mailing list