/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/external/tinycthread.c

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-07 22:32:25 UTC
  • mfrom: (151.1.2 simpletypesystem_meson)
  • Revision ID: gustav.hartvigsson@gmail.com-20210107223225-4i46581v09jkt7tr
* Merged lp:~gustav-hartvigsson/simpletypesystem/meson

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; -*-
2
2
Copyright (c) 2012 Marcus Geelnard
3
 
Copyright (c) 2013-2014 Evan Nemerson
 
3
Copyright (c) 2013-2016 Evan Nemerson
4
4
 
5
5
This software is provided 'as-is', without any express or implied
6
6
warranty. In no event will the authors be held liable for any damages
384
384
#if defined(_TTHREAD_WIN32_)
385
385
static int _cnd_timedwait_win32(cnd_t *cond, mtx_t *mtx, DWORD timeout)
386
386
{
387
 
  int result, lastWaiter;
 
387
  DWORD result;
 
388
  int lastWaiter;
388
389
 
389
390
  /* Increment number of waiters */
390
391
  EnterCriticalSection(&cond->mWaitersCountLock);
404
405
    mtx_lock(mtx);
405
406
    return thrd_timedout;
406
407
  }
407
 
  else if (result == (int)WAIT_FAILED)
 
408
  else if (result == WAIT_FAILED)
408
409
  {
409
410
    /* The mutex is locked again before the function returns, even if an error occurred */
410
411
    mtx_lock(mtx);
641
642
int thrd_equal(thrd_t thr0, thrd_t thr1)
642
643
{
643
644
#if defined(_TTHREAD_WIN32_)
644
 
  return thr0 == thr1;
 
645
  return GetThreadId(thr0) == GetThreadId(thr1);
645
646
#else
646
647
  return pthread_equal(thr0, thr1);
647
648
#endif
655
656
    _tinycthread_tss_cleanup();
656
657
  }
657
658
 
658
 
  ExitThread(res);
 
659
  ExitThread((DWORD)res);
659
660
#else
660
661
  pthread_exit((void*)(intptr_t)res);
661
662
#endif
674
675
  {
675
676
    if (GetExitCodeThread(thr, &dwRes) != 0)
676
677
    {
677
 
      *res = dwRes;
 
678
      *res = (int) dwRes;
678
679
    }
679
680
    else
680
681
    {
699
700
int thrd_sleep(const struct timespec *duration, struct timespec *remaining)
700
701
{
701
702
#if !defined(_TTHREAD_WIN32_)
702
 
  return nanosleep(duration, remaining);
 
703
  int res = nanosleep(duration, remaining);
 
704
  if (res == 0) {
 
705
    return 0;
 
706
  } else if (errno == EINTR) {
 
707
    return -1;
 
708
  } else {
 
709
    return -2;
 
710
  }
703
711
#else
704
712
  struct timespec start;
705
713
  DWORD t;
713
721
 
714
722
  if (t == 0) {
715
723
    return 0;
716
 
  } else if (remaining != NULL) {
717
 
    timespec_get(remaining, TIME_UTC);
718
 
    remaining->tv_sec -= start.tv_sec;
719
 
    remaining->tv_nsec -= start.tv_nsec;
720
 
    if (remaining->tv_nsec < 0)
721
 
    {
722
 
      remaining->tv_nsec += 1000000000;
723
 
      remaining->tv_sec -= 1;
 
724
  } else {
 
725
    if (remaining != NULL) {
 
726
      timespec_get(remaining, TIME_UTC);
 
727
      remaining->tv_sec -= start.tv_sec;
 
728
      remaining->tv_nsec -= start.tv_nsec;
 
729
      if (remaining->tv_nsec < 0)
 
730
      {
 
731
        remaining->tv_nsec += 1000000000;
 
732
        remaining->tv_sec -= 1;
 
733
      }
724
734
    }
725
 
  } else {
726
 
    return -1;
 
735
 
 
736
    return (t == WAIT_IO_COMPLETION) ? -1 : -2;
727
737
  }
728
 
 
729
 
  return 0;
730
738
#endif
731
739
}
732
740