summaryrefslogtreecommitdiffstats
path: root/3rdparty/openpgm-svn-r1135/pgm/thread.c.c89.patch
blob: 34acaafe75e58cc5ae565dd84e80310b2d903c33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--- thread.c	2010-05-21 11:35:21.000000000 +0800
+++ thread.c89	2010-08-05 11:31:03.000000000 +0800
@@ -46,7 +46,8 @@
 		} while (0)
 #	define posix_check_cmd(cmd) posix_check_err ((cmd), #cmd)
 #else
-#	define win32_check_err(err, name) \
+#	ifdef __PRETTY_FUNCTION
+#		define win32_check_err(err, name) \
 		do { \
 			const bool save_error = (err); \
 			if (PGM_UNLIKELY(!save_error)) { \
@@ -55,6 +56,17 @@
 					pgm_wsastrerror (GetLastError ()), name); \
 			} \
 		} while (0)
+#	else
+#		define win32_check_err(err, name) \
+		do { \
+			const bool save_error = (err); \
+			if (PGM_UNLIKELY(!save_error)) { \
+				pgm_error ("file %s: line %d: error '%s' during '%s'", \
+					__FILE__, __LINE__, \
+					pgm_wsastrerror (GetLastError ()), name); \
+			} \
+		} while (0)
+#	endif
 #	define win32_check_cmd(cmd) win32_check_err ((cmd), #cmd)
 #endif /* !_WIN32 */
 
@@ -94,9 +106,11 @@
 #ifndef _WIN32
 	posix_check_cmd (pthread_mutex_init (&mutex->pthread_mutex, NULL));
 #else
+	{
 	HANDLE handle;
-	win32_check_cmd (handle = CreateMutex (NULL, FALSE, NULL));
+	win32_check_cmd (NULL != (handle = CreateMutex (NULL, FALSE, NULL)));
 	mutex->win32_mutex = handle;
+	}
 #endif /* !_WIN32 */
 }
 
@@ -113,9 +127,11 @@
 	posix_check_err (result, "pthread_mutex_trylock");
 	return TRUE;
 #else
+	{
 	DWORD result;
 	win32_check_cmd (WAIT_FAILED != (result = WaitForSingleObject (mutex->win32_mutex, 0)));
 	return WAIT_TIMEOUT != result;
+	}
 #endif /* !_WIN32 */
 }
 
@@ -227,8 +243,11 @@
 	WakeAllConditionVariable (&cond->win32_cond);
 #else
 	EnterCriticalSection (&cond->win32_spinlock);
-	for (unsigned i = 0; i < cond->len; i++)
+	{
+	unsigned i;
+	for (i = 0; i < cond->len; i++)
 		SetEvent (cond->phandle[ i ]);
+	}
 	cond->len = 0;
 	LeaveCriticalSection (&cond->win32_spinlock);
 #endif /* !_WIN32 */
@@ -257,11 +276,12 @@
 #	if defined(CONFIG_HAVE_WIN_COND)
 	SleepConditionVariableCS (&cond->win32_cond, spinlock, INFINITE);
 #	else
+	{
 	DWORD status;
 	HANDLE event = TlsGetValue (cond_event_tls);
 
 	if (!event) {
-		win32_check_cmd (event = CreateEvent (0, FALSE, FALSE, NULL));
+		win32_check_cmd (NULL != (event = CreateEvent (0, FALSE, FALSE, NULL)));
 		TlsSetValue (cond_event_tls, event);
 	}
 
@@ -280,7 +300,9 @@
 
 	if (WAIT_TIMEOUT == status) {
 		EnterCriticalSection (&cond->win32_spinlock);
-		for (unsigned i = 0; i < cond->len; i++) {
+		{
+		unsigned i;
+		for (i = 0; i < cond->len; i++) {
 			if (cond->phandle[ i ] == event) {
 				if (i != cond->len - 1)
 					memmove (&cond->phandle[ i ], &cond->phandle[ i + 1 ], sizeof(HANDLE) * (cond->len - i - 1));
@@ -288,9 +310,11 @@
 				break;
 			}
 		}
+		}
 		win32_check_cmd (WAIT_FAILED != (status = WaitForSingleObject (event, 0)));
 		LeaveCriticalSection (&cond->win32_spinlock);
 	}
+	}
 #	endif /* !CONFIG_HAVE_WIN_COND */
 }
 #endif /* !_WIN32 */
@@ -384,6 +408,7 @@
 	)
 {
 	pgm_assert (NULL != rwlock);
+	{
 	bool status;
 	EnterCriticalSection (&rwlock->win32_spinlock);
 	if (!rwlock->have_writer && !rwlock->want_to_write) {
@@ -393,6 +418,7 @@
 		status = FALSE;
 	LeaveCriticalSection (&rwlock->win32_spinlock);
 	return status;
+	}
 }
 
 void
@@ -429,6 +455,7 @@
 	)
 {
 	pgm_assert (NULL != rwlock);
+	{
 	bool status;
 	EnterCriticalSection (&rwlock->win32_spinlock);
 	if (!rwlock->have_writer && !rwlock->read_counter) {
@@ -438,6 +465,7 @@
 		status = FALSE;
 	LeaveCriticalSection (&rwlock->win32_spinlock);
 	return status;
+	}
 }
 
 void