1
1
// **********************************************************************
3
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
168
186
IceUtil::ThreadControl
169
187
IceUtil::Thread::start(size_t stackSize)
189
return start(stackSize, THREAD_PRIORITY_NORMAL);
192
IceUtil::ThreadControl
193
IceUtil::Thread::start(size_t stackSize, int priority)
172
196
// Keep this alive for the duration of start
197
reinterpret_cast<HANDLE>(
199
static_cast<unsigned int>(stackSize),
200
startHook, this, 0, &id));
220
reinterpret_cast<HANDLE>(
222
static_cast<unsigned int>(stackSize),
223
startHook, this, CREATE_SUSPENDED, &id));
206
229
throw ThreadSyscallException(__FILE__, __LINE__, GetLastError());
231
if(SetThreadPriority(_handle, priority) == 0)
233
throw ThreadSyscallException(__FILE__, __LINE__, GetLastError());
235
if(ResumeThread(_handle) == -1)
238
throw ThreadSyscallException(__FILE__, __LINE__, GetLastError());
212
244
return ThreadControl(_handle, _id);
381
431
IceUtil::ThreadControl
382
432
IceUtil::Thread::start(size_t stackSize)
434
return start(stackSize, false, 0);
437
IceUtil::ThreadControl
438
IceUtil::Thread::start(size_t stackSize, int priority)
440
return start(stackSize, true, priority);
442
IceUtil::ThreadControl
443
IceUtil::Thread::start(size_t stackSize, bool realtimeScheduling, int priority)
385
446
// Keep this alive for the duration of start
469
int rc = pthread_attr_init(&attr);
473
pthread_attr_destroy(&attr);
474
throw ThreadSyscallException(__FILE__, __LINE__, rc);
407
476
if(stackSize > 0)
410
int rc = pthread_attr_init(&attr);
414
throw ThreadSyscallException(__FILE__, __LINE__, rc);
416
478
if(stackSize < PTHREAD_STACK_MIN)
418
480
stackSize = PTHREAD_STACK_MIN;
430
throw ThreadSyscallException(__FILE__, __LINE__, rc);
432
rc = pthread_create(&_thread, &attr, startHook, this);
436
throw ThreadSyscallException(__FILE__, __LINE__, rc);
441
int rc = pthread_create(&_thread, 0, startHook, this);
445
throw ThreadSyscallException(__FILE__, __LINE__, rc);
492
pthread_attr_destroy(&attr);
493
throw ThreadSyscallException(__FILE__, __LINE__, rc);
497
if(realtimeScheduling)
499
rc = pthread_attr_setschedpolicy(&attr, SCHED_RR);
503
throw ThreadSyscallException(__FILE__, __LINE__, rc);
506
param.sched_priority = priority;
507
rc = pthread_attr_setschedparam(&attr, ¶m);
511
pthread_attr_destroy(&attr);
512
throw ThreadSyscallException(__FILE__, __LINE__, rc);
514
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
516
rc = pthread_create(&_thread, &attr, startHook, this);
517
pthread_attr_destroy(&attr);
521
throw ThreadSyscallException(__FILE__, __LINE__, rc);
452
526
return ThreadControl(_thread);