This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Gsoc 2014 project proposal
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andrea Francesco Iuorio <andreafrancesco dot iuorio at gmail dot com>
- Cc: <libc-alpha at sourceware dot org>
- Date: Wed, 26 Feb 2014 21:48:06 +0000
- Subject: Re: Gsoc 2014 project proposal
- Authentication-results: sourceware.org; auth=none
- References: <CAMaJsKjobBfmxjBRB2WP6MMLiAAD=QTV3bhO=hogeZHxmmotPg at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1402261759390 dot 11728 at digraph dot polyomino dot org dot uk> <CAMaJsKg-4WTvX+XPYXMYXHZvRvUotyYeq7O69Xye4WBE7Zw6Wg at mail dot gmail dot com>
On Wed, 26 Feb 2014, Andrea Francesco Iuorio wrote:
> So, i can' t use a simple typedef because the type pthread_*_t is
> something in userland. This make sense as the functions name problem.
> I really didn' t think about it, it is the first time i try to create
> a system library. But i can' t also create a typedef __pthead_*_t
> because C++ don' t allow it ( and this it something that i didn' t
> honestly know ). So you suggest to create a struct or union that
> encapsulate the original type in the type i want. Am i right ? I need
> to know if i understand the problem correctly.
For example, at least some of the bits/pthreadtypes.h headers define
pthread_mutex_t as
typedef union
{
struct __pthread_mutex_s
{
(architecture-specific contents)
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
If that's what all architectures do, one option would be:
* bits/threadtypes.h defines struct __pthread_mutex_s and
__SIZEOF_PTHREAD_MUTEX_T (and lots of other things, all in the reserved
namespace).
* bits/pthreadtypes.h, possibly now architecture-independent, includes
bits/threadtypes.h and does:
typedef union
{
struct __pthread_mutex_s __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
* threads.h includes bits/threadtypes.h and does:
typedef union
{
struct __pthread_mutex_s __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} mtx_t;
Or the common header could do
#define __pthread_mutex_t_contents \
union \
{ \
... \
}
and then the other headers would do
typedef __pthread_mutex_t_contents pthread_mutex_t;
and
typedef __pthread_mutex_t_contents mtx_t;
which would avoid duplication of the list of three union fields.
There are various such options. The basic requirement is that after macro
expansion the pthread_mutex_t definition looks like
typedef union { ... } pthread_mutex_t;
where the union does not have a tag, so that the C++ name mangling is
unchanged. And, so that you can cast pointers appropriately, the two
types need the same contents.
--
Joseph S. Myers
joseph@codesourcery.com