|
From: Carlo W. <li...@us...> - 2002-01-24 05:48:41
|
CVSROOT : /cvsroot/libcw
Module : src
Commit time: 2002-00-24 05:48:39 UTC
Modified files:
libcwd/Makefile.am libcwd/bfd.cc libcwd/include/libcw/Makefile.am
libcwd/include/libcw/private_threading.h
Added files:
libcwd/semwrapper.cc libcwd/include/libcw/semwrapper.h
Log message:
Work in progress
---------------------- diff included ----------------------
Index: src/libcwd/Makefile.am
diff -u src/libcwd/Makefile.am:1.41 src/libcwd/Makefile.am:1.42
--- src/libcwd/Makefile.am:1.41 Tue Jan 8 17:42:21 2002
+++ src/libcwd/Makefile.am Wed Jan 23 21:48:29 2002
@@ -26,6 +26,7 @@
debugmalloc.cc \
demangle.cc \
demangle3.cc \
+ semwrapper.cc \
strerrno.cc \
type_info.cc
Index: src/libcwd/bfd.cc
diff -u src/libcwd/bfd.cc:1.93 src/libcwd/bfd.cc:1.94
--- src/libcwd/bfd.cc:1.93 Fri Jan 18 21:08:54 2002
+++ src/libcwd/bfd.cc Wed Jan 23 21:48:29 2002
@@ -1,4 +1,4 @@
-// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.93 2002/01/19 05:08:54 libcw Exp $
+// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.94 2002/01/24 05:48:29 libcw Exp $
//
// Copyright (C) 2000 - 2001, by
//
@@ -68,6 +68,7 @@
using libcw::debug::_private_::mutex_tct;
using libcw::debug::_private_::object_files_instance;
using libcw::debug::_private_::dlopen_map_instance;
+#define BFD_INITIALIZE_LOCK rwlock_tct<object_files_instance>::initialize();
#define BFD_ACQUIRE_WRITE_LOCK rwlock_tct<object_files_instance>::wrlock();
#define BFD_RELEASE_WRITE_LOCK rwlock_tct<object_files_instance>::wrunlock();
#define BFD_ACQUIRE_READ_LOCK rwlock_tct<object_files_instance>::rdlock();
@@ -77,6 +78,7 @@
#define DLOPEN_MAP_ACQUIRE_LOCK mutex_tct<dlopen_map_instance>::lock();
#define DLOPEN_MAP_RELEASE_LOCK mutex_tct<dlopen_map_instance>::unlock();
#else // !LIBCWD_THREAD_SAFE
+#define BFD_INITIALIZE_LOCK
#define BFD_ACQUIRE_WRITE_LOCK
#define BFD_RELEASE_WRITE_LOCK
#define BFD_ACQUIRE_READ_LOCK
@@ -1010,6 +1012,7 @@
// but the sanity checks inside the allocators used in load_object_file()
// require the lock to be set. Fortunately is therefore also doesn't hurt
// that we keep the lock a long time (during the execution of ldd_prog).
+ BFD_INITIALIZE_LOCK
BFD_ACQUIRE_WRITE_LOCK
load_object_file(fullpath.value->data(), 0);
Index: src/libcwd/include/libcw/Makefile.am
diff -u src/libcwd/include/libcw/Makefile.am:1.20 src/libcwd/include/libcw/Makefile.am:1.21
--- src/libcwd/include/libcw/Makefile.am:1.20 Tue Jan 22 20:03:44 2002
+++ src/libcwd/include/libcw/Makefile.am Wed Jan 23 21:48:29 2002
@@ -45,6 +45,7 @@
private_set_alloc_checking.h \
private_struct_TSD.h \
private_threading.h \
+ semwrapper.h \
strerrno.h \
struct_debug_tsd.h \
type_info.h
Index: src/libcwd/include/libcw/private_threading.h
diff -u src/libcwd/include/libcw/private_threading.h:1.10 src/libcwd/include/libcw/private_threading.h:1.11
--- src/libcwd/include/libcw/private_threading.h:1.10 Tue Jan 22 20:03:45 2002
+++ src/libcwd/include/libcw/private_threading.h Wed Jan 23 21:48:29 2002
@@ -1,4 +1,4 @@
-// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.10 2002/01/23 04:03:45 libcw Exp $
+// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.11 2002/01/24 05:48:29 libcw Exp $
//
// Copyright (C) 2001, by
//
@@ -39,7 +39,7 @@
#ifdef LIBCWD_HAVE_PTHREAD
#include <pthread.h>
-#include <semaphore.h>
+#include <libcw/semwrapper.h>
#if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
#define LIBCWD_USE_LINUXTHREADS
#else
@@ -60,6 +60,30 @@
#endif
#endif
+#ifdef LIBCWD_THREAD_SAFE
+#define LIBCWD_TSD_INSTANCE ::libcw::debug::_private_::\
+ thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance()
+ // For directly passing the `__libcwd_tsd' instance to a function (foo(TSD::instance())).
+#define LIBCWD_COMMA_TSD_INSTANCE , LIBCWD_TSD_INSTANCE
+ // Idem, but as second or higher parameter.
+#define LIBCWD_TSD_DECLARATION ::libcw::debug::_private_::\
+ TSD_st& __libcwd_tsd(::libcw::debug::_private_::\
+ thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance());
+ // Declaration of local `__libcwd_tsd' structure reference.
+#define LIBCWD_DO_TSD(debug_object) (__libcwd_tsd.do_array[(debug_object).WNS_index])
+ // For use inside class debug_ct to access member `m'.
+#else // !LIBCWD_THREAD_SAFE
+#define LIBCWD_TSD_INSTANCE
+#define LIBCWD_COMMA_TSD_INSTANCE
+#define LIBCWD_TSD_DECLARATION
+#define LIBCWD_DO_TSD(debug_object) ((debug_object).tsd)
+#endif // !LIBCWD_THREAD_SAFE
+
+#define LIBCWD_DO_TSD_MEMBER(debug_object, m) (LIBCWD_DO_TSD(debug_object).m)
+#define LIBCWD_TSD_MEMBER(m) LIBCWD_DO_TSD_MEMBER(*this, m)
+
+#ifdef LIBCWD_THREAD_SAFE
+
namespace libcw {
namespace debug {
namespace _private_ {
@@ -68,9 +92,6 @@
extern bool WST_multi_threaded;
#endif
-//===================================================================================================
-// Thread Specific Data.
-
#if defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS)
template<class TSD>
class thread_specific_data_tct {
@@ -95,42 +116,7 @@
};
#endif // defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS)
- } // namespace _private_
- } // namespace debug
-} // namespace libcw
-
-#ifdef LIBCWD_THREAD_SAFE
-#define LIBCWD_TSD_INSTANCE ::libcw::debug::_private_::\
- thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance()
- // For directly passing the `__libcwd_tsd' instance to a function (foo(TSD::instance())).
-#define LIBCWD_COMMA_TSD_INSTANCE , LIBCWD_TSD_INSTANCE
- // Idem, but as second or higher parameter.
-#define LIBCWD_TSD_DECLARATION ::libcw::debug::_private_::\
- TSD_st& __libcwd_tsd(::libcw::debug::_private_::\
- thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance());
- // Declaration of local `__libcwd_tsd' structure reference.
-#define LIBCWD_DO_TSD(debug_object) (__libcwd_tsd.do_array[(debug_object).WNS_index])
- // For use inside class debug_ct to access member `m'.
-#else // !LIBCWD_THREAD_SAFE
-#define LIBCWD_TSD_INSTANCE
-#define LIBCWD_COMMA_TSD_INSTANCE
-#define LIBCWD_TSD_DECLARATION
-#define LIBCWD_DO_TSD(debug_object) ((debug_object).tsd)
-#endif // !LIBCWD_THREAD_SAFE
-
-#define LIBCWD_DO_TSD_MEMBER(debug_object, m) (LIBCWD_DO_TSD(debug_object).m)
-#define LIBCWD_TSD_MEMBER(m) LIBCWD_DO_TSD_MEMBER(*this, m)
-
-// End of Thread Specific Data
//===================================================================================================
-
-#ifdef LIBCWD_THREAD_SAFE
-
-namespace libcw {
- namespace debug {
- namespace _private_ {
-
-//===================================================================================================
//
// Mutex locking.
//
@@ -349,10 +335,10 @@
#if LIBCWD_DEBUGTHREADS
int res =
#endif
- sem_init(&S_no_readers_left, 0, 1);
+ LIBCWD_SEM(init)(&S_no_readers_left, 0, 1);
FATALDEBUGDEBUG_CERR("res == " << res << "; &S_no_readers_left = " << (void*)&S_no_readers_left);
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
#if LIBCWD_DEBUGTHREADS
@@ -379,7 +365,7 @@
FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()");
return false;
}
- bool success = (++S_readers_count != 1) || (sem_trywait(&S_no_readers_left) == 0);
+ bool success = (++S_readers_count != 1) || (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0);
if (!success)
S_readers_count = 0;
mutex_tct<readers_count_instance>::unlock();
@@ -394,9 +380,9 @@
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::trywrlock()");
#ifndef DEBUGDEBUG
FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()");
- return sem_trywait(&S_no_readers_left) == 0;
+ return LIBCWD_SEM(trywait)(&S_no_readers_left) == 0;
#else
- bool res = (sem_trywait(&S_no_readers_left) == 0);
+ bool res = (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0);
if (res)
instance_locked[instance] += 1;
FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()");
@@ -424,12 +410,12 @@
if (++S_readers_count == 1)
{
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait...");
- sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val);
}
mutex_tct<readers_count_instance>::unlock();
@@ -448,12 +434,12 @@
if (--S_readers_count == 0)
{
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post...");
- sem_post(&S_no_readers_left);
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(post)(&S_no_readers_left);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val);
}
mutex_tct<readers_count_instance>::unlock();
@@ -470,12 +456,12 @@
if (1)
{
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait...");
- sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val);
}
if (instance < end_recursive_types)
@@ -498,12 +484,12 @@
if(1)
{
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post...");
- sem_post(&S_no_readers_left);
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(post)(&S_no_readers_left);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val);
}
FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrunlock()");
@@ -521,12 +507,12 @@
if (1)
{
int val;
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')');
FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting);
FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait...");
- sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
- sem_getvalue(&S_no_readers_left, &val);
+ LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked!
+ LIBCWD_SEM(getvalue)(&S_no_readers_left, &val);
FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val);
}
if (instance < end_recursive_types)
@@ -650,6 +636,8 @@
} // namespace _private_
} // namespace debug
} // namespace libcw
+
+#undef LIBCWD_SEM
#endif // LIBCWD_THREAD_SAFE
#endif // LIBCW_PRIVATE_THREADING_H
Index: src/libcwd/include/libcw/semwrapper.h
diff -u /dev/null src/libcwd/include/libcw/semwrapper.h:1.1
--- /dev/null Wed Jan 23 21:48:39 2002
+++ src/libcwd/include/libcw/semwrapper.h Wed Jan 23 21:48:29 2002
@@ -0,0 +1,53 @@
+// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/semwrapper.h,v 1.1 2002/01/24 05:48:29 libcw Exp $
+//
+// Copyright (C) 2002, by
+//
+// Carlo Wood, Run on IRC <ca...@al...>
+// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
+// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
+//
+// This file may be distributed under the terms of the Q Public License
+// version 1.0 as appearing in the file LICENSE.QPL included in the
+// packaging of this file.
+//
+
+//
+// Bug work around.
+// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html
+//
+
+#ifndef LIBCW_SEMWRAPPER_H
+#define LIBCW_SEMWRAPPER_H
+
+#include <semaphore.h>
+
+namespace libcw {
+ namespace debug {
+ namespace _private_ {
+
+// This bug results in __old_sem_* to be used (in libpthread)
+// which can not cause problems as long as we declare enough
+// space.
+//
+// With typedef struct { long int sem_status; int sem_spinlock; } old_sem_t;
+// it is garanteed however that sizeof(old_sem_t) <= sizeof(sem_t) and
+// thus creating a sem_t variable and passing that to __old_sem_*
+// functions can not cause problems.
+//
+// This wrapper is to make sure that __old_sem_* and __new_sem_* calls
+// aren't mixed.
+
+extern int __libcwd_sem_post_wrapper(sem_t* sem);
+extern int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value);
+extern int __libcwd_sem_wait_wrapper(sem_t* sem);
+extern int __libcwd_sem_trywait_wrapper(sem_t* sem);
+extern int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval);
+extern int __libcwd_sem_destroy_wrapper(sem_t* sem);
+
+ } // namespace __private_
+ } // namespace debug
+} // namespace libcw
+
+#define LIBCWD_SEM(x) __libcwd_sem_##x##_wrapper
+
+#endif // LIBCW_SEMWRAPPER_H
Index: src/libcwd/semwrapper.cc
diff -u /dev/null src/libcwd/semwrapper.cc:1.1
--- /dev/null Wed Jan 23 21:48:39 2002
+++ src/libcwd/semwrapper.cc Wed Jan 23 21:48:29 2002
@@ -0,0 +1,59 @@
+// $Header: /cvsroot/l/li/libcw/src/libcwd/semwrapper.cc,v 1.1 2002/01/24 05:48:29 libcw Exp $
+//
+// Copyright (C) 2002, by
+//
+// Carlo Wood, Run on IRC <ca...@al...>
+// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
+// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
+//
+// This file may be distributed under the terms of the Q Public License
+// version 1.0 as appearing in the file LICENSE.QPL included in the
+// packaging of this file.
+//
+
+//
+// Bug work around.
+// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html
+//
+
+#include "sys.h"
+#include <libcw/semwrapper.h>
+
+namespace libcw {
+ namespace debug {
+ namespace _private_ {
+
+int __libcwd_sem_post_wrapper(sem_t* sem)
+{
+ return sem_post(sem);
+}
+
+int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value)
+{
+ return sem_init(sem, pshared, value);
+}
+
+int __libcwd_sem_wait_wrapper(sem_t* sem)
+{
+ return sem_wait(sem);
+}
+
+int __libcwd_sem_trywait_wrapper(sem_t* sem)
+{
+ return sem_trywait(sem);
+}
+
+int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval)
+{
+ return sem_getvalue(sem, sval);
+}
+
+int __libcwd_sem_destroy_wrapper(sem_t* sem)
+{
+ return sem_destroy(sem);
+}
+
+ } // namespace __private_
+ } // namespace debug
+} // namespace libcw
+
----------------------- End of diff -----------------------
|