[Mono-dev] [PATCH] Android Support [3/4]

Paolo Molaro lupus at ximian.com
Tue Apr 20 05:16:56 EDT 2010


On 04/19/10 Jonathan Pryor wrote:
> Index: mono/io-layer/collection.c
> ===================================================================
> --- mono/io-layer/collection.c	(revision 155735)
> +++ mono/io-layer/collection.c	(working copy)
> @@ -58,7 +58,10 @@
>          ret = pthread_attr_init (&attr);
>          g_assert (ret == 0);
>  
> -#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
> +/* Android implements pthread_attr_setstacksize(), but errors out when using
> + * PTHREAD_STACK_MIN: http://code.google.com/p/android/issues/detail?id=7808
> + */
> +#if defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && !defined(PLATFORM_ANDROID)
>          if (set_stacksize == 0) {
>  #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
>  			ret = pthread_attr_setstacksize (&attr, 65536);

Instead of adding more checks there, just change the code to do:
	ret = pthread_attr_setstacksize (&attr, MAX (65536, PTHREAD_STACK_MIN));

> Index: mono/io-layer/mono-mutex.c
> ===================================================================
> --- mono/io-layer/mono-mutex.c	(revision 155735)
> +++ mono/io-layer/mono-mutex.c	(working copy)
> @@ -22,11 +22,24 @@
>  
>  
>  #ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
> +/* Android does not implement pthread_mutex_timedlock(), but does provide an
> + * unusual declaration: http://code.google.com/p/android/issues/detail?id=7807
> + */
> +#if defined(PLATFORM_ANDROID)
>  int pthread_mutex_timedlock (pthread_mutex_t *mutex,
> +			    struct timespec *timeout);
> +#else
> +int pthread_mutex_timedlock (pthread_mutex_t *mutex,
>  			    const struct timespec *timeout);
> +#endif

Just do this at the start:
#ifdef PLATFORM_ANDROID
#define CONST_NEEDED const
#else
#define CONST_NEEDED const
#endif

And then insert CONST_NEEDED where appropriate instead of the ugly
duplication and ifdef mess.

> Index: mono/mini/exceptions-arm.c
> ===================================================================
> --- mono/mini/exceptions-arm.c	(revision 155735)
> +++ mono/mini/exceptions-arm.c	(working copy)
> @@ -12,7 +12,11 @@
>  #include <glib.h>
>  #include <signal.h>
>  #include <string.h>
> +#if defined(PLATFORM_ANDROID)
> +#include <asm/sigcontext.h>
> +#else
>  #include <ucontext.h>
> +#endif

Please make sure configure has the appropriate header checks and use:

#ifdef HAVE_ASM_SIGCONTEXT_H
#include <asm/sigcontext.h>
#endif
#ifdef HAVE_UCONTEXT_H
#include <ucontext.h>
#endif

We must use feature checks and not platform checks as much as possible.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better


More information about the Mono-devel-list mailing list