Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/thread.cc')
-rw-r--r--winsup/cygwin/thread.cc69
1 files changed, 42 insertions, 27 deletions
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 183b9b8d5..2e54b7a50 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -38,7 +38,12 @@ extern "C" void __fp_lock_all ();
extern "C" void __fp_unlock_all ();
extern "C" int valid_sched_parameters(const struct sched_param *);
extern "C" int sched_set_thread_priority(HANDLE thread, int priority);
+#ifdef __x86_64__
+/* FIXME: Temporarily workaround gcc 4.8 bug. */
+static verifyable_object_state
+#else
static inline verifyable_object_state
+#endif
verifyable_object_isvalid (void const * objectptr, thread_magic_t magic,
void *static_ptr1 = NULL,
void *static_ptr2 = NULL,
@@ -117,7 +122,12 @@ __cygwin_lock_unlock (_LOCK_T *lock)
paranoid_printf ("threadcount %d. unlocked", MT_INTERFACE->threadcount);
}
+#ifdef __x86_64__
+/* FIXME: Temporarily workaround gcc 4.8 bug. */
+static verifyable_object_state
+#else
static inline verifyable_object_state
+#endif
verifyable_object_isvalid (void const *objectptr, thread_magic_t magic, void *static_ptr1,
void *static_ptr2, void *static_ptr3)
{
@@ -216,7 +226,7 @@ pthread_mutex::can_be_unlocked ()
* Also check for the ANONYMOUS owner to cover NORMAL mutexes as well. */
bool res = type == PTHREAD_MUTEX_NORMAL || no_owner ()
|| (recursion_counter == 1 && pthread::equal (owner, self));
- pthread_printf ("recursion_counter %d res %d", recursion_counter, res);
+ pthread_printf ("recursion_counter %u res %d", recursion_counter, res);
return res;
}
@@ -579,7 +589,11 @@ pthread::cancel ()
executing Windows code. Rely on deferred cancellation in this case. */
if (!cygtls->inside_kernel (&context))
{
+#ifdef __x86_64__
+ context.Rip = (ULONG_PTR) pthread::static_cancel_self;
+#else
context.Eip = (DWORD) pthread::static_cancel_self;
+#endif
SetThreadContext (win32_obj_id, &context);
}
}
@@ -1143,7 +1157,7 @@ pthread_cond::pthread_cond (pthread_condattr *attr) :
/* Change the mutex type to NORMAL to speed up mutex operations */
mtx_out.set_type (PTHREAD_MUTEX_NORMAL);
- sem_wait = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL);
+ sem_wait = ::CreateSemaphore (&sec_none_nih, 0, INT32_MAX, NULL);
if (!sem_wait)
{
pthread_printf ("CreateSemaphore failed. %E");
@@ -1165,7 +1179,7 @@ pthread_cond::~pthread_cond ()
void
pthread_cond::unblock (const bool all)
{
- unsigned long releaseable;
+ LONG releaseable;
/*
* Block outgoing threads (and avoid simultanous unblocks)
@@ -1175,7 +1189,7 @@ pthread_cond::unblock (const bool all)
releaseable = waiting - pending;
if (releaseable)
{
- unsigned long released;
+ LONG released;
if (!pending)
{
@@ -1212,11 +1226,11 @@ pthread_cond::wait (pthread_mutex_t mutex, PLARGE_INTEGER timeout)
DWORD rv;
mtx_in.lock ();
- if (InterlockedIncrement ((long *)&waiting) == 1)
+ if (InterlockedIncrement (&waiting) == 1)
mtx_cond = mutex;
else if (mtx_cond != mutex)
{
- InterlockedDecrement ((long *)&waiting);
+ InterlockedDecrement (&waiting);
mtx_in.unlock ();
return EINVAL;
}
@@ -1247,7 +1261,7 @@ pthread_cond::wait (pthread_mutex_t mutex, PLARGE_INTEGER timeout)
rv = WAIT_OBJECT_0;
}
- InterlockedDecrement ((long *)&waiting);
+ InterlockedDecrement (&waiting);
if (rv == WAIT_OBJECT_0 && --pending == 0)
/*
@@ -1286,7 +1300,7 @@ pthread_cond::_fixup_after_fork ()
mtx_in.unlock ();
mtx_out.unlock ();
- sem_wait = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL);
+ sem_wait = ::CreateSemaphore (&sec_none_nih, 0, INT32_MAX, NULL);
if (!sem_wait)
api_fatal ("pthread_cond::_fixup_after_fork () failed to recreate win32 semaphore");
}
@@ -1383,7 +1397,7 @@ pthread_rwlock::rdlock ()
reader = lookup_reader ();
if (reader)
{
- if (reader->n < ULONG_MAX)
+ if (reader->n < UINT32_MAX)
++reader->n;
else
errno = EAGAIN;
@@ -1429,7 +1443,7 @@ pthread_rwlock::tryrdlock ()
RWLOCK_READER *reader = lookup_reader ();
if (!reader)
reader = add_reader ();
- if (reader && reader->n < ULONG_MAX)
+ if (reader && reader->n < UINT32_MAX)
++reader->n;
else
result = EAGAIN;
@@ -1448,7 +1462,7 @@ pthread_rwlock::wrlock ()
mtx.lock ();
- if (writer == self || lookup_reader ())
+ if (writer == self || lookup_reader ())
{
result = EDEADLK;
goto DONE;
@@ -1730,7 +1744,7 @@ pthread_mutex::lock ()
pthread_t self = ::pthread_self ();
int result = 0;
- if (InterlockedIncrement ((long *) &lock_counter) == 1)
+ if (InterlockedIncrement (&lock_counter) == 1)
set_owner (self);
else if (type == PTHREAD_MUTEX_NORMAL /* potentially causes deadlock */
|| !pthread::equal (owner, self))
@@ -1741,14 +1755,14 @@ pthread_mutex::lock ()
}
else
{
- InterlockedDecrement ((long *) &lock_counter);
+ InterlockedDecrement (&lock_counter);
if (type == PTHREAD_MUTEX_RECURSIVE)
result = lock_recursive ();
else
result = EDEADLK;
}
- pthread_printf ("mutex %p, self %p, owner %p, lock_counter %d, recursion_counter %d",
+ pthread_printf ("mutex %p, self %p, owner %p, lock_counter %d, recursion_counter %u",
this, self, owner, lock_counter, recursion_counter);
return result;
}
@@ -1772,12 +1786,12 @@ pthread_mutex::unlock ()
#ifdef DEBUGGING
tid = 0; // thread-id
#endif
- if (InterlockedDecrement ((long *) &lock_counter))
+ if (InterlockedDecrement (&lock_counter))
::SetEvent (win32_obj_id); // Another thread is waiting
res = 0;
}
- pthread_printf ("mutex %p, owner %p, self %p, lock_counter %d, recursion_counter %d, type %d, res %d",
+ pthread_printf ("mutex %p, owner %p, self %p, lock_counter %d, recursion_counter %u, type %d, res %d",
this, owner, self, lock_counter, recursion_counter, type, res);
return res;
}
@@ -1788,7 +1802,7 @@ pthread_mutex::trylock ()
pthread_t self = ::pthread_self ();
int result = 0;
- if (InterlockedCompareExchange ((long *) &lock_counter, 1, 0) == 0)
+ if (InterlockedCompareExchange (&lock_counter, 1, 0) == 0)
set_owner (self);
else if (type == PTHREAD_MUTEX_RECURSIVE && pthread::equal (owner, self))
result = lock_recursive ();
@@ -1864,7 +1878,7 @@ pthread_spinlock::lock ()
do
{
- if (InterlockedExchange ((long *) &lock_counter, 1) == 0)
+ if (InterlockedExchange (&lock_counter, 1) == 0)
{
set_owner (self);
result = 0;
@@ -1899,7 +1913,7 @@ pthread_spinlock::unlock ()
#ifdef DEBUGGING
tid = 0; // thread-id
#endif
- InterlockedExchange ((long *) &lock_counter, 0);
+ InterlockedExchange (&lock_counter, 0);
::SetEvent (win32_obj_id);
result = 0;
}
@@ -2248,7 +2262,7 @@ pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size)
if (!pthread_attr::is_good_object (attr))
return EINVAL;
/* uses lowest address of stack on all platforms */
- *addr = (void *)((int)(*attr)->stackaddr - (*attr)->stacksize);
+ *addr = (void *)((ptrdiff_t)(*attr)->stackaddr - (*attr)->stacksize);
*size = (*attr)->stacksize;
return 0;
}
@@ -2481,7 +2495,7 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
else
{
debug_printf ("NtQueryInformationThread(ThreadBasicInformation), "
- "status %p", status);
+ "status %y", status);
(*attr)->stackaddr = thread->attr.stackaddr;
(*attr)->stacksize = thread->attr.stacksize;
}
@@ -3030,7 +3044,8 @@ extern "C" int
pthread_sigmask (int operation, const sigset_t *set, sigset_t *old_set)
{
int res = handle_sigprocmask (operation, set, old_set, _my_tls.sigmask);
- syscall_printf ("%d = pthread_sigmask(%d, %p, %p)", operation, set, old_set);
+ syscall_printf ("%d = pthread_sigmask(%d, %p, %p)",
+ res, operation, set, old_set);
return res;
}
@@ -3368,7 +3383,7 @@ semaphore::semaphore (int pshared, unsigned int value)
{
SECURITY_ATTRIBUTES sa = (pshared != PTHREAD_PROCESS_PRIVATE)
? sec_all : sec_none_nih;
- this->win32_obj_id = ::CreateSemaphore (&sa, value, LONG_MAX, NULL);
+ this->win32_obj_id = ::CreateSemaphore (&sa, value, INT32_MAX, NULL);
if (!this->win32_obj_id)
magic = 0;
@@ -3389,7 +3404,7 @@ semaphore::semaphore (unsigned long long shash, LUID sluid, int sfd,
__small_sprintf (name, "semaphore/%016X%08x%08x",
hash, luid.HighPart, luid.LowPart);
- this->win32_obj_id = ::CreateSemaphore (&sec_all, value, LONG_MAX, name);
+ this->win32_obj_id = ::CreateSemaphore (&sec_all, value, INT32_MAX, name);
if (!this->win32_obj_id)
magic = 0;
if (GetLastError () == ERROR_ALREADY_EXISTS && (oflag & O_EXCL))
@@ -3420,7 +3435,7 @@ semaphore::_post ()
int
semaphore::_getvalue (int *sval)
{
- long val;
+ LONG val;
switch (WaitForSingleObject (win32_obj_id, 0))
{
@@ -3513,10 +3528,10 @@ semaphore::_fixup_after_fork ()
{
if (shared == PTHREAD_PROCESS_PRIVATE)
{
- pthread_printf ("sem %x", this);
+ pthread_printf ("sem %p", this);
/* FIXME: duplicate code here and in the constructor. */
this->win32_obj_id = ::CreateSemaphore (&sec_none_nih, currentvalue,
- LONG_MAX, NULL);
+ INT32_MAX, NULL);
if (!win32_obj_id)
api_fatal ("failed to create new win32 semaphore, %E");
}