rwlock2_t.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * rwlock2_t.c
  3. *
  4. *
  5. * --------------------------------------------------------------------------
  6. *
  7. * Pthreads-win32 - POSIX Threads Library for Win32
  8. * Copyright(C) 1998 John E. Bossom
  9. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  10. *
  11. * Contact Email: [email protected]
  12. *
  13. * The current list of contributors is contained
  14. * in the file CONTRIBUTORS included with the source
  15. * code distribution. The list can also be seen at the
  16. * following World Wide Web location:
  17. * http://sources.redhat.com/pthreads-win32/contributors.html
  18. *
  19. * This library is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Lesser General Public
  21. * License as published by the Free Software Foundation; either
  22. * version 2 of the License, or (at your option) any later version.
  23. *
  24. * This library is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. * Lesser General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Lesser General Public
  30. * License along with this library in the file COPYING.LIB;
  31. * if not, write to the Free Software Foundation, Inc.,
  32. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  33. *
  34. * --------------------------------------------------------------------------
  35. *
  36. * Declare a static rwlock object, timed-lock it,
  37. * and then unlock it again.
  38. *
  39. * Depends on API functions:
  40. * pthread_rwlock_timedrdlock()
  41. * pthread_rwlock_unlock()
  42. */
  43. #include "test.h"
  44. #include <sys/timeb.h>
  45. pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
  46. int
  47. main()
  48. {
  49. struct timespec abstime = { 0, 0 };
  50. PTW32_STRUCT_TIMEB currSysTime;
  51. const DWORD NANOSEC_PER_MILLISEC = 1000000;
  52. PTW32_FTIME(&currSysTime);
  53. abstime.tv_sec = (long)currSysTime.time;
  54. abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
  55. abstime.tv_sec += 1;
  56. assert(rwlock == PTHREAD_RWLOCK_INITIALIZER);
  57. assert(pthread_rwlock_timedrdlock(&rwlock, &abstime) == 0);
  58. assert(rwlock != PTHREAD_RWLOCK_INITIALIZER);
  59. assert(rwlock != NULL);
  60. assert(pthread_rwlock_unlock(&rwlock) == 0);
  61. assert(pthread_rwlock_destroy(&rwlock) == 0);
  62. assert(rwlock == NULL);
  63. return 0;
  64. }