/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/pthread_timechange_handler_np.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/pthread_timechange_handler_np.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 3871 byte(s)
committing r3113 initial commit again...
1 /*
2 * pthread_timechange_handler_np.c
3 *
4 * Description:
5 * This translation unit implements miscellaneous thread functions.
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 */
36
37 #include "ptw32pch.h"
38
39 /*
40 * Notes on handling system time adjustments (especially negative ones).
41 * ---------------------------------------------------------------------
42 *
43 * This solution was suggested by Alexander Terekhov, but any errors
44 * in the implementation are mine - [Ross Johnson]
45 *
46 * 1) The problem: threads doing a timedwait on a CV may expect to timeout
47 * at a specific absolute time according to a system timer. If the
48 * system clock is adjusted backwards then those threads sleep longer than
49 * expected. Also, pthreads-win32 converts absolute times to intervals in
50 * order to make use of the underlying Win32, and so waiting threads may
51 * awake before their proper abstimes.
52 *
53 * 2) We aren't able to distinquish between threads on timed or untimed waits,
54 * so we wake them all at the time of the adjustment so that they can
55 * re-evaluate their conditions and re-compute their timeouts.
56 *
57 * 3) We rely on correctly written applications for this to work. Specifically,
58 * they must be able to deal properly with spurious wakeups. That is,
59 * they must re-test their condition upon wakeup and wait again if
60 * the condition is not satisfied.
61 */
62
63 void *
64 pthread_timechange_handler_np (void *arg)
65 /*
66 * ------------------------------------------------------
67 * DOCPUBLIC
68 * Broadcasts all CVs to force re-evaluation and
69 * new timeouts if required.
70 *
71 * PARAMETERS
72 * NONE
73 *
74 *
75 * DESCRIPTION
76 * Broadcasts all CVs to force re-evaluation and
77 * new timeouts if required.
78 *
79 * This routine may be passed directly to pthread_create()
80 * as a new thread in order to run asynchronously.
81 *
82 *
83 * RESULTS
84 * 0 successfully broadcast all CVs
85 * EAGAIN Not all CVs were broadcast
86 *
87 * ------------------------------------------------------
88 */
89 {
90 int result = 0;
91 pthread_cond_t cv;
92
93 EnterCriticalSection (&ptw32_cond_list_lock);
94
95 cv = ptw32_cond_list_head;
96
97 while (cv != NULL && 0 == result)
98 {
99 result = pthread_cond_broadcast (&cv);
100 cv = cv->next;
101 }
102
103 LeaveCriticalSection (&ptw32_cond_list_lock);
104
105 return (void *) (result != 0 ? EAGAIN : 0);
106 }

  ViewVC Help
Powered by ViewVC 1.1.22