winpthreads: remove WINPTHREAD_DBG macro
The `WINPTHREAD_DBG` macro guards internal functions which are
no longer used. Code guarded by this macro has been removed.
This commit also removed private definition of `assert` macro
from misc.h. assert.h has been included from affected source files.
Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-libraries/winpthreads/Makefile.am b/mingw-w64-libraries/winpthreads/Makefile.am
index c3f0c8d..cf78f4c 100644
--- a/mingw-w64-libraries/winpthreads/Makefile.am
+++ b/mingw-w64-libraries/winpthreads/Makefile.am
@@ -32,7 +32,7 @@
src/wpth_ver.h \
src/version.rc
-libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD -DWINPTHREAD_DBG=1
+libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD
libwinpthread_la_LDFLAGS = -no-undefined -version-info 1:0:0
if MSVC
diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h b/mingw-w64-libraries/winpthreads/include/pthread.h
index 4a58224..7f0be9e 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -86,8 +86,6 @@
/* MSB 8-bit major version, 8-bit minor version, 16-bit patch level. */
#define __WINPTHREADS_VERSION 0x00050000
-/* #define WINPTHREAD_DBG 1 */
-
/* Compatibility stuff: */
#define RWLS_PER_THREAD 8
diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c b/mingw-w64-libraries/winpthreads/src/barrier.c
index e973aaa..f3b5c46 100644
--- a/mingw-w64-libraries/winpthreads/src/barrier.c
+++ b/mingw-w64-libraries/winpthreads/src/barrier.c
@@ -20,12 +20,13 @@
DEALINGS IN THE SOFTWARE.
*/
+#include <assert.h>
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include "pthread.h"
#include "barrier.h"
-#include "ref.h"
+#include "ref.h"
#include "misc.h"
static pthread_spinlock_t barrier_global = PTHREAD_SPINLOCK_INITIALIZER;
@@ -34,9 +35,7 @@
barrier_unref(volatile pthread_barrier_t *barrier, int res)
{
pthread_spin_lock(&barrier_global);
-#ifdef WINPTHREAD_DBG
assert((((barrier_t *)*barrier)->valid == LIFE_BARRIER) && (((barrier_t *)*barrier)->busy > 0));
-#endif
((barrier_t *)*barrier)->busy -= 1;
pthread_spin_unlock(&barrier_global);
return res;
@@ -64,7 +63,7 @@
*bDestroy = NULL;
pthread_spin_lock(&barrier_global);
-
+
if (!barrier || !*barrier || ((barrier_t *)*barrier)->valid != LIFE_BARRIER) r = EINVAL;
else {
barrier_t *b_ = (barrier_t *)*barrier;
@@ -92,15 +91,15 @@
pthread_barrier_t bDestroy;
barrier_t *b;
int r;
-
+
while ((r = barrier_ref_destroy(b_,&bDestroy)) == EBUSY)
Sleep(0);
-
+
if (r)
return r;
b = (barrier_t *)bDestroy;
-
+
pthread_mutex_lock(&b->m);
if (sem_destroy(&b->sems[0]) != 0)
diff --git a/mingw-w64-libraries/winpthreads/src/cond.c b/mingw-w64-libraries/winpthreads/src/cond.c
index 813648f..cad966e 100644
--- a/mingw-w64-libraries/winpthreads/src/cond.c
+++ b/mingw-w64-libraries/winpthreads/src/cond.c
@@ -52,41 +52,13 @@
int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout);
-#ifdef WINPTHREAD_DBG
-static int print_state = 0;
-static FILE *fo;
-void cond_print_set(int state, FILE *f)
-{
- if (f) fo = f;
- if (!fo) fo = stdout;
- print_state = state;
-}
-
-void cond_print(volatile pthread_cond_t *c, char *txt)
-{
- if (!print_state) return;
- cond_t *c_ = (cond_t *)*c;
- if (c_ == NULL) {
- fprintf(fo,"C%p %lu %s\n",(void *)*c,GetCurrentThreadId(),txt);
- } else {
- fprintf(fo,"C%p %lu V=%0X w=%ld %s\n",
- (void *)*c,
- GetCurrentThreadId(),
- (int)c_->valid,
- c_->waiters_count_,
- txt
- );
- }
-}
-#endif
-
static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER;
static int
cond_static_init (pthread_cond_t *c)
{
int r = 0;
-
+
pthread_spin_lock (&cond_locked);
if (c == NULL)
r = EINVAL;
@@ -218,7 +190,7 @@
_c->sema_b = CreateSemaphore (NULL, /* no security */
0, /* initially 0 */
0x7fffffff, /* max count */
- NULL);
+ NULL);
if (_c->sema_q == NULL || _c->sema_b == NULL) {
if (_c->sema_q != NULL)
CloseHandle (_c->sema_q);
@@ -356,7 +328,7 @@
{
cond_t *_c;
int r;
- int relCnt = 0;
+ int relCnt = 0;
if (!c || !*c)
return EINVAL;
@@ -751,5 +723,5 @@
}
InterlockedExchangeAdd(val, -count);
LeaveCriticalSection(cs);
- return EINVAL;
+ return EINVAL;
}
diff --git a/mingw-w64-libraries/winpthreads/src/cond.h b/mingw-w64-libraries/winpthreads/src/cond.h
index 5e869e9..9eda223 100644
--- a/mingw-w64-libraries/winpthreads/src/cond.h
+++ b/mingw-w64-libraries/winpthreads/src/cond.h
@@ -40,7 +40,7 @@
typedef struct cond_t cond_t;
struct cond_t
{
- unsigned int valid;
+ unsigned int valid;
int busy;
LONG waiters_count_; /* Number of waiting threads. */
LONG waiters_count_unblock_; /* Number of waiting threads whitch can be unblocked. */
@@ -56,8 +56,4 @@
became signaled. */
};
-void cond_print_set(int state, FILE *f);
-
-void cond_print(volatile pthread_cond_t *c, char *txt);
-
#endif
diff --git a/mingw-w64-libraries/winpthreads/src/misc.h b/mingw-w64-libraries/winpthreads/src/misc.h
index a853dd0..f01f1fb 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.h
+++ b/mingw-w64-libraries/winpthreads/src/misc.h
@@ -25,35 +25,6 @@
#include "pthread_compat.h"
-#ifndef assert
-
-#ifndef ASSERT_TRACE
-# define ASSERT_TRACE 0
-#else
-# undef ASSERT_TRACE
-# define ASSERT_TRACE 0
-#endif
-
-# define assert(e) \
- ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
- "Assertion succeeded: (%s), file %s, line %d\n", \
- #e, __FILE__, (int) __LINE__), \
- fflush(stderr) : \
- 0) : \
- (fprintf(stderr, "Assertion failed: (%s), file %s, line %d\n", \
- #e, __FILE__, (int) __LINE__), exit(1), 0))
-
-# define fixme(e) \
- ((e) ? ((ASSERT_TRACE) ? fprintf(stderr, \
- "Assertion succeeded: (%s), file %s, line %d\n", \
- #e, __FILE__, (int) __LINE__), \
- fflush(stderr) : \
- 0) : \
- (fprintf(stderr, "FIXME: (%s), file %s, line %d\n", \
- #e, __FILE__, (int) __LINE__), 0, 0))
-
-#endif
-
#define PTR2INT(x) ((int)(uintptr_t)(x))
#if SIZE_MAX>UINT_MAX
diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c b/mingw-w64-libraries/winpthreads/src/rwlock.c
index 76669df..7a4e583 100644
--- a/mingw-w64-libraries/winpthreads/src/rwlock.c
+++ b/mingw-w64-libraries/winpthreads/src/rwlock.c
@@ -20,6 +20,7 @@
DEALINGS IN THE SOFTWARE.
*/
+#include <assert.h>
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
@@ -36,9 +37,7 @@
static WINPTHREADS_ATTRIBUTE((noinline)) int rwl_unref(volatile pthread_rwlock_t *rwl, int res)
{
pthread_spin_lock(&rwl_global);
-#ifdef WINPTHREAD_DBG
assert((((rwlock_t *)*rwl)->valid == LIFE_RWLOCK) && (((rwlock_t *)*rwl)->busy > 0));
-#endif
((rwlock_t *)*rwl)->busy--;
pthread_spin_unlock(&rwl_global);
return res;
@@ -87,7 +86,7 @@
*rDestroy = (pthread_rwlock_t)NULL;
pthread_spin_lock(&rwl_global);
-
+
if (!rwl || !*rwl) r = EINVAL;
else {
rwlock_t *r_ = (rwlock_t *)*rwl;
@@ -128,30 +127,6 @@
return ret;
}
-#ifdef WINPTHREAD_DBG
-static int print_state = 0;
-void rwl_print_set(int state)
-{
- print_state = state;
-}
-
-void rwl_print(volatile pthread_rwlock_t *rwl, char *txt)
-{
- if (!print_state) return;
- rwlock_t *r = (rwlock_t *)*rwl;
- if (r == NULL) {
- printf("RWL%p %lu %s\n",(void *)*rwl,GetCurrentThreadId(),txt);
- } else {
- printf("RWL%p %lu V=%0X B=%d r=%ld w=%ld L=%p %s\n",
- (void *)*rwl,
- GetCurrentThreadId(),
- (int)r->valid,
- (int)r->busy,
- 0L,0L,NULL,txt);
- }
-}
-#endif
-
static pthread_spinlock_t cond_locked = PTHREAD_SPINLOCK_INITIALIZER;
static WINPTHREADS_ATTRIBUTE((noinline)) int rwlock_static_init(pthread_rwlock_t *rw)
@@ -165,7 +140,7 @@
}
r = pthread_rwlock_init (rw, NULL);
pthread_spin_unlock(&cond_locked);
-
+
return r;
}
@@ -178,7 +153,7 @@
return EINVAL;
*rwlock_ = (pthread_rwlock_t)NULL;
if ((rwlock = calloc(1, sizeof(*rwlock))) == NULL)
- return ENOMEM;
+ return ENOMEM;
rwlock->valid = DEAD_RWLOCK;
rwlock->nex_count = rwlock->nsh_count = rwlock->ncomplete = 0;
@@ -203,18 +178,18 @@
rwlock->valid = LIFE_RWLOCK;
*rwlock_ = (pthread_rwlock_t)rwlock;
return r;
-}
+}
int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_)
{
rwlock_t *rwlock;
pthread_rwlock_t rDestroy;
int r, r2;
-
+
pthread_spin_lock(&cond_locked);
r = rwl_ref_destroy(rwlock_,&rDestroy);
pthread_spin_unlock(&cond_locked);
-
+
if(r) return r;
if(!rDestroy) return 0; /* destroyed a (still) static initialized rwl */
@@ -245,7 +220,7 @@
rwlock->valid = DEAD_RWLOCK;
free((void *)rDestroy);
return 0;
-}
+}
int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_)
{
@@ -340,7 +315,7 @@
}
ret = pthread_mutex_unlock(&rwlock->mex);
return rwl_unref(rwlock_,ret);
-}
+}
int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_)
{
@@ -378,7 +353,7 @@
}
rwlock->nex_count = 1;
return rwl_unref(rwlock_, 0);
-}
+}
int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_)
{
@@ -409,7 +384,7 @@
ret = rwlock_free_both_locks(rwlock, 0);
}
return rwl_unref(rwlock_, ret);
-}
+}
static void st_cancelwrite (void *arg)
{
diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.h b/mingw-w64-libraries/winpthreads/src/rwlock.h
index 2d640fa..8faf12b 100644
--- a/mingw-w64-libraries/winpthreads/src/rwlock.h
+++ b/mingw-w64-libraries/winpthreads/src/rwlock.h
@@ -43,7 +43,4 @@
#define RWL_SET 0x01
#define RWL_TRY 0x02
-void rwl_print(volatile pthread_rwlock_t *rwl, char *txt);
-void rwl_print_set(int state);
-
#endif
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c
index 2ebf1ad..6e897f0 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -537,34 +537,6 @@
extern const PIMAGE_TLS_CALLBACK __xl_f;
const PIMAGE_TLS_CALLBACK __xl_f = __dyn_tls_pthread;
-
-#ifdef WINPTHREAD_DBG
-static int print_state = 0;
-void thread_print_set (int state)
-{
- print_state = state;
-}
-
-void
-thread_print (volatile pthread_t t, char *txt)
-{
- if (!print_state)
- return;
- if (!t)
- printf("T%p %lu %s\n",NULL,GetCurrentThreadId(),txt);
- else
- {
- printf("T%p %lu V=%0X H=%p %s\n",
- (void *) __pth_gpointer_locked (t),
- GetCurrentThreadId(),
- (__pth_gpointer_locked (t))->valid,
- (__pth_gpointer_locked (t))->h,
- txt
- );
- }
-}
-#endif
-
/* Internal collect-once structure. */
typedef struct collect_once_t {
pthread_once_t *o;
@@ -725,7 +697,7 @@
/* Compatibility routine for pthread-win32. It returns the
amount of available CPUs on system. */
int
-pthread_num_processors_np(void)
+pthread_num_processors_np(void)
{
int r = 0;
DWORD_PTR ProcessAffinityMask, SystemAffinityMask;
@@ -742,10 +714,10 @@
/* Compatiblity routine for pthread-win32. Allows to set amount of used
CPUs for process. */
int
-pthread_set_num_processors_np(int n)
+pthread_set_num_processors_np(int n)
{
DWORD_PTR ProcessAffinityMask, ProcessNewAffinityMask = 0, SystemAffinityMask;
- int r = 0;
+ int r = 0;
/* need at least 1 */
n = n ? n : 1;
if (GetProcessAffinityMask (GetCurrentProcess (), &ProcessAffinityMask, &SystemAffinityMask))
@@ -878,7 +850,7 @@
return EINVAL;
pthread_rwlock_wrlock (&_pthread_key_lock);
-
+
_pthread_key_dest[key] = NULL;
/* Start next search from our location */
@@ -910,7 +882,7 @@
{
DWORD lasterr = GetLastError ();
_pthread_v *t = __pthread_self_lite ();
-
+
pthread_spin_lock (&t->spin_keys);
if (key >= t->keymax)
diff --git a/mingw-w64-libraries/winpthreads/src/thread.h b/mingw-w64-libraries/winpthreads/src/thread.h
index 1603bae..97bfda7 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.h
+++ b/mingw-w64-libraries/winpthreads/src/thread.h
@@ -69,10 +69,6 @@
int _pthread_tryjoin(pthread_t t, void **res);
void _pthread_setnobreak(int);
-#ifdef WINPTHREAD_DBG
-void thread_print_set(int state);
-void thread_print(volatile pthread_t t, char *txt);
-#endif
int __pthread_shallcancel(void);
WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id);