Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 May 2003 09:53:54 +0800
From:      "David Xu" <davidxu@viatech.com.cn>
To:        "Craig Rodrigues" <rodrigc@attbi.com>, <freebsd-threads@freebsd.org>
Subject:   Re: Question about OpenSSL id_function() and pthreads
Message-ID:  <006b01c32585$28ca4ad0$f001a8c0@davidw2k>
References:  <20030528235120.GA3481@attbi.com>

next in thread | previous in thread | raw e-mail | index | archive | help

----- Original Message -----=20
From: "Craig Rodrigues" <rodrigc@attbi.com>
To: <freebsd-threads@freebsd.org>
Sent: Thursday, May 29, 2003 7:51 AM
Subject: Question about OpenSSL id_function() and pthreads


> Hi,
>=20
> I previously asked this question on freebsd-security@ and
> freebsd-current@ :
>=20
> =
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=3D63674+0+archive/2003/freeb=
sd-security/20030302.freebsd-security
>=20
>=20
> Let me try again, now that there is a freebsd-threads mailing list.
>=20
>=20
> On the following OpenSSL web page:
> http://www.openssl.org/docs/crypto/threads.html
>=20
> "void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
>=20
> id_function(void) is a function that returns a thread ID.=20
> It is not needed on Windows nor on platforms where getpid() returns=20
> a different ID for each thread (most notably Linux)."
>=20
>=20
> I have some third party C++ code which tries to implements this =
function:
>=20
> tatic unsigned long
> idFunction()
> {
> #ifdef _WIN32
>     return static_cast<unsigned long>(GetCurrentThreadId());
> #else
>     return static_cast<unsigned long>(pthread_self());
> #endif
> }
>=20
>=20
> This code does not compile on FreeBSD-CURRENT:
>=20
> OpenSSLPluginI.cpp: In function `long unsigned int idFunction()':
> OpenSSLPluginI.cpp:151: invalid static_cast from type `pthread*' to =
type `long=20
>    unsigned int'
>=20
>=20
> How can I implement this function properly on FreeBSD?
>=20

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?006b01c32585$28ca4ad0$f001a8c0>