Commit fd312537 by Nicola Pero Committed by Nicola Pero

In libobjc/: Implemented objc_sync_enter() and objc_sync_exit(), which are…

In libobjc/: Implemented objc_sync_enter() and objc_sync_exit(), which are required by @synchronized() to work.

In libobjc/:
       Implemented objc_sync_enter() and objc_sync_exit(), which are
       required by @synchronized() to work.
       * objc-sync.c: New file.
       * objc/objc-sync.h: New file.
       * objc-private/objc-sync.h: New file.
       * init.c (__objc_exec_class): Call __objc_sync_init() during the
       Objective-C runtime startup.
       * Makefile.in: Added objc-sync.c and objc-sync.h.
       * configure.ac: Added GCC_CHECK_TLS.
       * acinclude.m4: Include ../config/enable.m4 and ../config/tls.m4.
       * configure: Regenerated.
       * config.h.in: Regenerated.

From-SVN: r164276
parent 4359dc2a
2010-09-14 Nicola Pero <nicola.pero@meta-innovation.com>
Implemented objc_sync_enter() and objc_sync_exit(), which are
required by @synchronized() to work.
* objc-sync.c: New file.
* objc/objc-sync.h: New file.
* objc-private/objc-sync.h: New file.
* init.c (__objc_exec_class): Call __objc_sync_init() during the
Objective-C runtime startup.
* Makefile.in: Added objc-sync.c and objc-sync.h.
* configure.ac: Added GCC_CHECK_TLS.
* acinclude.m4: Include ../config/enable.m4 and ../config/tls.m4.
* configure: Regenerated.
* config.h.in: Regenerated.
2010-09-12 Nicola Pero <nicola.pero@meta-innovation.com>
* Makefile.in (%_gc.lo): New pattern rules to build the
......
......@@ -111,6 +111,7 @@ INCLUDES = -I$(srcdir)/$(MULTISRCTOP)../gcc \
OBJC_H = \
objc.h \
objc-exception.h \
objc-sync.h \
\
NXConstStr.h \
Object.h \
......@@ -159,6 +160,7 @@ C_SOURCE_FILES = \
init.c \
memory.c \
nil_method.c \
objc-sync.c \
objects.c \
sarray.c \
selector.c \
......
dnl Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2004
dnl Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2010
dnl Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
......@@ -11,6 +11,8 @@ dnl PARTICULAR PURPOSE.
m4_include(../config/acx.m4)
m4_include(../config/no-executables.m4)
m4_include(../config/enable.m4)
m4_include(../config/tls.m4)
m4_include(../libtool.m4)
dnl The lines below arrange for aclocal not to bring an installed
......
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if the target assembler supports thread-local storage. */
#undef HAVE_CC_TLS
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
......@@ -33,6 +36,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if the target supports thread-local storage. */
#undef HAVE_TLS
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
......
......@@ -718,6 +718,7 @@ with_pic
enable_fast_install
with_gnu_ld
enable_libtool_lock
enable_tls
enable_sjlj_exceptions
'
ac_precious_vars='build_alias
......@@ -1351,6 +1352,7 @@ Optional Features:
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--enable-tls Use thread-local storage [default=yes]
--enable-sjlj-exceptions
force use of builtin_setjmp for exceptions
......@@ -10566,7 +10568,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 10569 "configure"
#line 10571 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -10672,7 +10674,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 10675 "configure"
#line 10677 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -11232,6 +11234,215 @@ $as_echo "#define HAVE_GTHR_DEFAULT 1" >>confdefs.h
fi
# Check if we have thread-local storage
# Check whether --enable-tls was given.
if test "${enable_tls+set}" = set; then :
enableval=$enable_tls;
case "$enableval" in
yes|no) ;;
*) as_fn_error "Argument to enable/disable tls must be yes or no" "$LINENO" 5 ;;
esac
else
enable_tls=yes
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports thread-local storage" >&5
$as_echo_n "checking whether the target supports thread-local storage... " >&6; }
if test "${gcc_cv_have_tls+set}" = set; then :
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
if test x$gcc_no_link = xyes; then
as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
__thread int a; int b; int main() { return a = b; }
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
chktls_save_LDFLAGS="$LDFLAGS"
case $host in
*-*-linux*)
LDFLAGS="-shared -Wl,--no-undefined $LDFLAGS"
;;
esac
chktls_save_CFLAGS="$CFLAGS"
CFLAGS="-fPIC $CFLAGS"
if test x$gcc_no_link = xyes; then
as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int f() { return 0; }
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if test x$gcc_no_link = xyes; then
as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
__thread int a; int b; int f() { return a = b; }
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
gcc_cv_have_tls=yes
else
gcc_cv_have_tls=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
else
gcc_cv_have_tls=yes
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
CFLAGS="$chktls_save_CFLAGS"
LDFLAGS="$chktls_save_LDFLAGS"
else
gcc_cv_have_tls=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
__thread int a; int b; int main() { return a = b; }
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
chktls_save_LDFLAGS="$LDFLAGS"
LDFLAGS="-static $LDFLAGS"
if test x$gcc_no_link = xyes; then
as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int main() { return 0; }
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if test "$cross_compiling" = yes; then :
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error "cannot run test program while cross compiling
See \`config.log' for more details." "$LINENO" 5; }
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
__thread int a; int b; int main() { return a = b; }
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
gcc_cv_have_tls=yes
else
gcc_cv_have_tls=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
else
gcc_cv_have_tls=yes
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LDFLAGS="$chktls_save_LDFLAGS"
if test $gcc_cv_have_tls = yes; then
chktls_save_CFLAGS="$CFLAGS"
thread_CFLAGS=failed
for flag in '' '-pthread' '-lpthread'; do
CFLAGS="$flag $chktls_save_CFLAGS"
if test x$gcc_no_link = xyes; then
as_fn_error "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <pthread.h>
void *g(void *d) { return NULL; }
int
main ()
{
pthread_t t; pthread_create(&t,NULL,g,NULL);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
thread_CFLAGS="$flag"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
if test "X$thread_CFLAGS" != Xfailed; then
break
fi
done
CFLAGS="$chktls_save_CFLAGS"
if test "X$thread_CFLAGS" != Xfailed; then
CFLAGS="$thread_CFLAGS $chktls_save_CFLAGS"
if test "$cross_compiling" = yes; then :
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error "cannot run test program while cross compiling
See \`config.log' for more details." "$LINENO" 5; }
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <pthread.h>
__thread int a;
static int *volatile a_in_other_thread;
static void *
thread_func (void *arg)
{
a_in_other_thread = &a;
return (void *)0;
}
int
main ()
{
pthread_t thread;
void *thread_retval;
int *volatile a_in_main_thread;
a_in_main_thread = &a;
if (pthread_create (&thread, (pthread_attr_t *)0,
thread_func, (void *)0))
return 0;
if (pthread_join (thread, &thread_retval))
return 0;
return (a_in_other_thread == a_in_main_thread);
;
return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
gcc_cv_have_tls=yes
else
gcc_cv_have_tls=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
CFLAGS="$chktls_save_CFLAGS"
fi
fi
else
gcc_cv_have_tls=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_have_tls" >&5
$as_echo "$gcc_cv_have_tls" >&6; }
if test "$enable_tls $gcc_cv_have_tls" = "yes yes"; then
$as_echo "#define HAVE_TLS 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for exception model to use" >&5
$as_echo_n "checking for exception model to use... " >&6; }
......@@ -11246,7 +11457,7 @@ if test "${enable_sjlj_exceptions+set}" = set; then :
enableval=$enable_sjlj_exceptions; :
else
cat > conftest.$ac_ext << EOF
#line 11249 "configure"
#line 11460 "configure"
@interface Frob
@end
@implementation Frob
......
......@@ -215,6 +215,8 @@ if test $target_thread_file != single; then
[Define if the compiler has a thread header that is non single.])
fi
# Check if we have thread-local storage
GCC_CHECK_TLS
AC_MSG_CHECKING([for exception model to use])
AC_LANG_PUSH(C)
......
......@@ -32,6 +32,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "objc/hash.h"
#include "objc/objc-list.h"
#include "objc-private/runtime.h"
#include "objc-private/objc-sync.h" /* For __objc_sync_init() */
/* The version number of this runtime. This must match the number
defined in gcc (objc-act.c). */
......@@ -550,6 +551,7 @@ __objc_exec_class (Module_t module)
__objc_load_methods = objc_hash_new (128,
(hash_func_type)objc_hash_ptr,
objc_compare_ptrs);
__objc_sync_init ();
previous_constructors = 1;
}
......
/* GNU Objective C Runtime @synchronized implementation - Private functions
Copyright (C) 2010 Free Software Foundation, Inc.
Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef __objc_private_objc_sync_INCLUDE_GNU
#define __objc_private_objc_sync_INCLUDE_GNU
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* This function needs to be called at startup before @synchronized()
can be used. */
void
__objc_sync_init (void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* not __objc_private_objc_sync_INCLUDE_GNU */
/* GNU Objective C Runtime @synchronized implementation
Copyright (C) 2010 Free Software Foundation, Inc.
Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef __objc_sync_INCLUDE_GNU
#define __objc_sync_INCLUDE_GNU
#include "objc.h"
#ifdef __cplusplus
extern "C" {
#endif
/* These functions are automatically called by @synchronized(). */
/* 'objc_sync_enter' is automatically called when entering a
@synchronized() block. It locks the recursive lock associated with
'object'. If 'object' is nil, it does nothing. It returns
OBJC_SYNC_SUCCESS on success; see the enumeration below for error
values.
Note that you should not rely on the behaviour when 'object' is nil
because it could change.
*/
int objc_sync_enter (id object);
/* 'objc_sync_exit' is automatically called when exiting from a
@synchronized() block. It unlocks the recursive lock associated
with 'object'. If 'object' is nil, it does nothing. It returns
OBJC_SYNC_SUCCESS on success; see the enumeration below for error
values.
*/
int objc_sync_exit (id object);
/* All the possible return values for objc_sync_enter() and
objc_sync_exit().
*/
enum {
OBJC_SYNC_SUCCESS = 0,
OBJC_SYNC_NOT_OWNING_THREAD_ERROR = -1,
OBJC_SYNC_TIMED_OUT = -2,
OBJC_SYNC_NOT_INITIALIZED = -3
};
#ifdef __cplusplus
}
#endif
#endif /* not __objc_sync_INCLUDE_GNU */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment