Skip to content

Commit 1a6b3c8

Browse files
author
rpj
committed
WinCE fixes
1 parent f295b6e commit 1a6b3c8

File tree

9 files changed

+98
-37
lines changed

9 files changed

+98
-37
lines changed

create.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ pthread_create (pthread_t * tid,
146146
#if defined(HAVE_SIGSET_T)
147147
tp->sigmask = sp->sigmask;
148148
#endif
149+
#if ! defined(WINCE)
149150
tp->cpuset = sp->cpuset;
151+
#endif
150152

151153
if (a != NULL)
152154
{
@@ -224,8 +226,12 @@ pthread_create (pthread_t * tid,
224226
(void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority);
225227
}
226228

229+
#if ! defined(WINCE)
230+
227231
SetThreadAffinityMask(tp->threadH, tp->cpuset);
228232

233+
#endif
234+
229235
if (run)
230236
{
231237
ResumeThread (threadH);
@@ -272,7 +278,12 @@ pthread_create (pthread_t * tid,
272278
(void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority);
273279
}
274280

281+
#if ! defined(WINCE)
282+
275283
SetThreadAffinityMask(tp->threadH, tp->cpuset);
284+
285+
#endif
286+
276287
}
277288

278289
ptw32_mcs_lock_release (&stateLock);

implement.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam);
5959
* Designed to allow error values to be set and retrieved in builds where
6060
* MSCRT libraries are statically linked to DLLs.
6161
*/
62-
#if ( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0800 ) || \
63-
( defined(_MSC_VER) && _MSC_VER >= 1400 ) /* MSVC8+ */
62+
#if ! defined(WINCE) && \
63+
(( defined(PTW32_CONFIG_MINGW) && __MSVCRT_VERSION__ >= 0x0800 ) || \
64+
( defined(_MSC_VER) && _MSC_VER >= 1400 )) /* MSVC8+ */
6465
# if defined(PTW32_CONFIG_MINGW)
6566
__attribute__((unused))
6667
# endif
@@ -224,7 +225,9 @@ struct ptw32_thread_t_
224225
int cancelType;
225226
int implicit:1;
226227
DWORD thread; /* Windows thread ID */
228+
#if ! defined(WINCE)
227229
size_t cpuset; /* Thread CPU affinity set */
230+
#endif
228231
#if defined(_UWIN)
229232
DWORD dummy[5];
230233
#endif

need_errno.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#error ERROR: Only Win32 targets supported!
2525
#endif
2626

27-
#include <winsock.h>
27+
//#include <winsock.h>
2828

2929
#if defined(__cplusplus)
3030
extern "C" {
@@ -114,18 +114,22 @@ _CRTIMP extern int errno;
114114
#define ERANGE 34
115115
#define EDEADLK 36
116116

117-
/* defined differently in winsock.h on WinCE */
118-
#if !defined(ENAMETOOLONG)
119-
#define ENAMETOOLONG 38
120-
#endif
117+
/* defined differently in winsock.h on WinCE
118+
* We don't use this value.
119+
*/
120+
//#if !defined(ENAMETOOLONG)
121+
//#define ENAMETOOLONG 38
122+
//#endif
121123

122124
#define ENOLCK 39
123125
#define ENOSYS 40
124126

125-
/* defined differently in winsock.h on WinCE */
126-
#if !defined(ENOTEMPTY)
127-
#define ENOTEMPTY 41
128-
#endif
127+
/* defined differently in winsock.h on WinCE
128+
* We don't use this value.
129+
*/
130+
//#if !defined(ENOTEMPTY)
131+
//#define ENOTEMPTY 41
132+
//#endif
129133

130134
#define EILSEQ 42
131135

@@ -134,7 +138,7 @@ _CRTIMP extern int errno;
134138
#define ENOTRECOVERABLE 44
135139

136140
/*
137-
* Support EDEADLOCK for compatibiity with older MS-C versions.
141+
* Support EDEADLOCK for compatibility with older MS-C versions.
138142
*/
139143
#define EDEADLOCK EDEADLK
140144

pthread_self.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,34 +123,40 @@ pthread_self (void)
123123
fail = PTW32_TRUE;
124124
}
125125
#endif
126-
/*
127-
* Get this threads CPU affinity by temporarily setting the threads
128-
* affinity to that of the process to get the old thread affinity,
129-
* then reset to the old affinity.
130-
*/
126+
131127
if (!fail)
132128
{
133-
if (GetProcessAffinityMask(GetCurrentProcess(), &vProcessMask, &vSystemMask))
134-
{
135-
vThreadMask = SetThreadAffinityMask(sp->threadH, vProcessMask);
136-
if (vThreadMask)
137-
{
138-
if (SetThreadAffinityMask(sp->threadH, vThreadMask))
139-
{
140-
sp->cpuset = (size_t) vThreadMask;
141-
}
142-
else fail = PTW32_TRUE;
143-
}
144-
else fail = PTW32_TRUE;
145-
}
146-
else fail = PTW32_TRUE;
147129

148-
/*
149-
* No need to explicitly serialise access to sched_priority
150-
* because the new handle is not yet public.
151-
*/
152-
sp->sched_priority = GetThreadPriority (sp->threadH);
153-
pthread_setspecific (ptw32_selfThreadKey, (void *) sp);
130+
#if ! defined(WINCE)
131+
132+
/*
133+
* Get this threads CPU affinity by temporarily setting the threads
134+
* affinity to that of the process to get the old thread affinity,
135+
* then reset to the old affinity.
136+
*/
137+
if (GetProcessAffinityMask(GetCurrentProcess(), &vProcessMask, &vSystemMask))
138+
{
139+
vThreadMask = SetThreadAffinityMask(sp->threadH, vProcessMask);
140+
if (vThreadMask)
141+
{
142+
if (SetThreadAffinityMask(sp->threadH, vThreadMask))
143+
{
144+
sp->cpuset = (size_t) vThreadMask;
145+
}
146+
else fail = PTW32_TRUE;
147+
}
148+
else fail = PTW32_TRUE;
149+
}
150+
else fail = PTW32_TRUE;
151+
152+
#endif
153+
154+
/*
155+
* No need to explicitly serialise access to sched_priority
156+
* because the new handle is not yet public.
157+
*/
158+
sp->sched_priority = GetThreadPriority (sp->threadH);
159+
pthread_setspecific (ptw32_selfThreadKey, (void *) sp);
154160
}
155161
}
156162

pthread_setaffinity.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ pthread_setaffinity_np (pthread_t thread, size_t cpusetsize,
8080
* ESRCH Thread does not exist
8181
* EFAULT pcuset is NULL
8282
* EAGAIN The thread affinity could not be set
83+
* ENOSYS The platform does not support this function
8384
*
8485
* ------------------------------------------------------
8586
*/
8687
{
88+
#if defined(WINCE)
89+
90+
return ENOSYS;
91+
92+
#else
93+
8794
int result = 0;
8895
ptw32_thread_t * tp;
8996
ptw32_mcs_local_node_t node;
@@ -146,6 +153,8 @@ pthread_setaffinity_np (pthread_t thread, size_t cpusetsize,
146153
ptw32_mcs_lock_release (&node);
147154

148155
return result;
156+
157+
#endif
149158
}
150159

151160
int
@@ -177,10 +186,17 @@ pthread_getaffinity_np (pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset)
177186
* 0 Success
178187
* ESRCH thread does not exist
179188
* EFAULT cpuset is NULL
189+
* ENOSYS The platform does not support this function
180190
*
181191
* ------------------------------------------------------
182192
*/
183193
{
194+
#if defined(WINCE)
195+
196+
return ENOSYS;
197+
198+
#else
199+
184200
int result = 0;
185201
ptw32_thread_t * tp;
186202
ptw32_mcs_local_node_t node;
@@ -222,4 +238,6 @@ pthread_getaffinity_np (pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset)
222238
ptw32_mcs_lock_release(&node);
223239

224240
return result;
241+
242+
#endif
225243
}

ptw32_new.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ ptw32_new (void)
8484
tp->threadLock = 0;
8585
tp->robustMxListLock = 0;
8686
tp->robustMxList = NULL;
87+
#if ! defined(WINCE)
8788
CPU_ZERO((cpu_set_t*)&tp->cpuset);
89+
#endif
8890
tp->cancelEvent = CreateEvent (0, (int) PTW32_TRUE, /* manualReset */
8991
(int) PTW32_FALSE, /* setSignaled */
9092
NULL);

tests/affinity3.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ main()
5656
CPU_ZERO(&switchmask);
5757
CPU_ZERO(&flipmask);
5858

59+
if (pthread_getaffinity_np(self, sizeof(cpu_set_t), &processCpus) == ENOSYS)
60+
{
61+
printf("pthread_get/set_affinity_np API not supported for this platform: skipping test.");
62+
return 0;
63+
}
5964
assert(pthread_getaffinity_np(self, sizeof(cpu_set_t), &processCpus) == 0);
6065
printf("This thread has a starting affinity with %d CPUs\n", CPU_COUNT(&processCpus));
6166
assert(!CPU_EQUAL(&mask, &processCpus));

tests/affinity4.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ main()
4949
cpu_set_t keepCpus;
5050
pthread_t self = pthread_self();
5151

52+
if (pthread_getaffinity_np(self, sizeof(cpu_set_t), &threadCpus) == ENOSYS)
53+
{
54+
printf("pthread_get/set_affinity_np API not supported for this platform: skipping test.");
55+
return 0;
56+
}
57+
5258
CPU_ZERO(&keepCpus);
5359
for (cpu = 1; cpu < sizeof(cpu_set_t)*8; cpu += 2)
5460
{

tests/affinity5.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ main()
7979
cpu_set_t keepCpus;
8080
pthread_t self = pthread_self();
8181

82+
if (pthread_getaffinity_np(self, sizeof(cpu_set_t), &threadCpus) == ENOSYS)
83+
{
84+
printf("pthread_get/set_affinity_np API not supported for this platform: skipping test.");
85+
return 0;
86+
}
87+
8288
CPU_ZERO(&keepCpus);
8389
for (cpu = 1; cpu < sizeof(cpu_set_t)*8; cpu += 2)
8490
{

0 commit comments

Comments
 (0)