8 #ifdef ZMQ_HAVE_WINDOWS
21 #ifdef ZMQ_HAVE_WINDOWS
24 #if defined _WIN32_WCE
32 self->_tfn (
self->_arg);
42 strncpy (_name,
name_,
sizeof (_name) - 1);
45 unsigned int stack = 0;
50 #if defined _WIN32_WCE
57 win_assert (_descriptor !=
NULL);
63 return GetCurrentThreadId () == _thread_id;
69 const DWORD rc = WaitForSingleObject (_descriptor, INFINITE);
70 win_assert (rc != WAIT_FAILED);
71 const BOOL rc2 = CloseHandle (_descriptor);
72 win_assert (rc2 != 0);
77 int priority_,
int scheduling_policy_,
const std::set<int> &affinity_cpus_)
111 if (!_name[0] || !IsDebuggerPresent ())
116 thread_info_t thread_info;
117 thread_info._type = 0x1000;
118 thread_info._name = _name;
119 thread_info._thread_id = -1;
120 thread_info._flags = 0;
123 const DWORD MS_VC_EXCEPTION = 0x406D1388;
124 RaiseException (MS_VC_EXCEPTION, 0,
125 sizeof (thread_info) /
sizeof (ULONG_PTR),
126 (ULONG_PTR *) &thread_info);
128 __except (EXCEPTION_CONTINUE_EXECUTION) {
131 #elif defined(__MINGW32__)
133 int rc = pthread_setname_np (pthread_self (), _name);
145 #elif defined ZMQ_HAVE_VXWORKS
152 self->_tfn (
self->_arg);
162 _descriptor = taskSpawn (
NULL, DEFAULT_PRIORITY, DEFAULT_OPTIONS,
164 (
int)
this, 0, 0, 0, 0, 0, 0, 0, 0, 0);
165 if (_descriptor !=
NULL || _descriptor > 0)
172 while ((_descriptor !=
NULL || _descriptor > 0)
173 && taskIdVerify (_descriptor) == 0) {
179 return taskIdSelf () == _descriptor;
183 int priority_,
int schedulingPolicy_,
const std::set<int> &affinity_cpus_)
185 _thread_priority = priority_;
186 _thread_sched_policy = schedulingPolicy_;
187 _thread_affinity_cpus = affinity_cpus_;
194 (_thread_priority >= 0 ? _thread_priority : DEFAULT_PRIORITY);
195 priority = (priority < UCHAR_MAX ? priority : DEFAULT_PRIORITY);
196 if (_descriptor !=
NULL || _descriptor > 0) {
197 taskPrioritySet (_descriptor, priority);
211 #include <sys/time.h>
212 #include <sys/resource.h>
217 #if !defined ZMQ_HAVE_OPENVMS && !defined ZMQ_HAVE_ANDROID
221 int rc = sigfillset (&signal_set);
223 rc = pthread_sigmask (SIG_BLOCK, &signal_set,
NULL);
228 self->applyThreadName ();
229 self->_tfn (
self->_arg);
239 strncpy (_name,
name_,
sizeof (_name) - 1);
248 int rc = pthread_join (_descriptor,
NULL);
255 return bool (pthread_equal (pthread_self (), _descriptor));
259 int priority_,
int scheduling_policy_,
const std::set<int> &affinity_cpus_)
261 _thread_priority = priority_;
262 _thread_sched_policy = scheduling_policy_;
263 _thread_affinity_cpus = affinity_cpus_;
269 #if defined _POSIX_THREAD_PRIORITY_SCHEDULING \
270 && _POSIX_THREAD_PRIORITY_SCHEDULING >= 0
272 struct sched_param
param;
274 #if _POSIX_THREAD_PRIORITY_SCHEDULING == 0 \
275 && defined _SC_THREAD_PRIORITY_SCHEDULING
276 if (sysconf (_SC_THREAD_PRIORITY_SCHEDULING) < 0) {
280 int rc = pthread_getschedparam (pthread_self (), &policy, &
param);
284 policy = _thread_sched_policy;
292 bool use_nice_instead_priority =
293 (policy != SCHED_FIFO) && (policy != SCHED_RR);
295 if (use_nice_instead_priority)
296 param.sched_priority =
299 param.sched_priority =
303 if (policy == SCHED_OTHER)
304 param.sched_priority = -1;
307 rc = pthread_setschedparam (pthread_self (), policy, &
param);
309 #if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
317 #if !defined ZMQ_HAVE_VXWORKS
318 if (use_nice_instead_priority
320 && _thread_priority > 0) {
332 #ifdef ZMQ_HAVE_PTHREAD_SET_AFFINITY
333 if (!_thread_affinity_cpus.empty ()) {
336 for (std::set<int>::const_iterator
it = _thread_affinity_cpus.begin (),
337 end = _thread_affinity_cpus.end ();
339 CPU_SET ((
int) (*
it), &cpuset);
342 pthread_setaffinity_np (pthread_self (),
sizeof (cpu_set_t), &cpuset);
363 #if defined(ZMQ_HAVE_ANDROID)
367 #if defined(ZMQ_HAVE_PTHREAD_SETNAME_1)
368 int rc = pthread_setname_np (_name);
371 #elif defined(ZMQ_HAVE_PTHREAD_SETNAME_2)
372 int rc = pthread_setname_np (pthread_self (), _name);
375 #elif defined(ZMQ_HAVE_PTHREAD_SETNAME_3)
376 int rc = pthread_setname_np (pthread_self (), _name,
NULL);
379 #elif defined(ZMQ_HAVE_PTHREAD_SET_NAME)
380 pthread_set_name_np (pthread_self (), _name);