-typedef pthread_t ldap_pvt_thread_t;
-typedef pthread_attr_t ldap_pvt_thread_attr_t;
-typedef pthread_mutex_t ldap_pvt_thread_mutex_t;
-typedef pthread_mutexattr_t ldap_pvt_thread_mutexattr_t;
-typedef pthread_cond_t ldap_pvt_thread_cond_t;
-typedef pthread_condattr_t ldap_pvt_thread_condattr_t;
-
-#define LDAP_PVT_THREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
-#define LDAP_PVT_THREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
+#ifndef LDAP_PVT_THREAD_H_DONE
+typedef ldap_int_thread_t ldap_pvt_thread_t;
+#ifdef LDAP_THREAD_DEBUG_WRAP
+typedef ldap_debug_thread_mutex_t ldap_pvt_thread_mutex_t;
+typedef ldap_debug_thread_cond_t ldap_pvt_thread_cond_t;
+typedef ldap_debug_thread_rdwr_t ldap_pvt_thread_rdwr_t;
+#else
+typedef ldap_int_thread_mutex_t ldap_pvt_thread_mutex_t;
+typedef ldap_int_thread_cond_t ldap_pvt_thread_cond_t;
+typedef ldap_int_thread_rdwr_t ldap_pvt_thread_rdwr_t;
+#endif
+typedef ldap_int_thread_rmutex_t ldap_pvt_thread_rmutex_t;
+#endif /* !LDAP_PVT_THREAD_H_DONE */