2
* Copyright (c) 2005, Eric Crahen
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is furnished
9
* to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in all
12
* copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
#ifndef __ZTTHREADOPS_H__
24
#define __ZTTHREADOPS_H__
26
#include "zthread/Priority.h"
36
* @author Eric Crahen <http://www.code-foo.com>
37
* @date <2003-07-16T23:33:59-0400>
40
* This class is an abstraction used to perform various operations on a
41
* native WIN32 thread.
45
//! Dispatch function for native thread
46
static unsigned int __stdcall _dispatch(void*);
48
//! TID while the thread is executing.
52
ThreadOps(DWORD tid) : _tid(tid) { }
56
const static ThreadOps INVALID;
59
* Create a new ThreadOps to represent a native thread.
61
ThreadOps() : _tid(0), _hThread(NULL) {}
64
inline bool operator==(const ThreadOps& ops) const {
65
return _tid == ops._tid;
69
static ThreadOps self() {
70
return ThreadOps(::GetCurrentThreadId());
74
* Update the native tid for this thread so it matches the current
77
static void activate(ThreadOps* ops) {
80
assert(ops->_tid == 0);
82
ops->_tid = ::GetCurrentThreadId();
87
* Test if this object representative of the currently executing
90
* @return bool true if successful
92
static bool isCurrent(ThreadOps* ops) {
96
return ops->_tid == ::GetCurrentThreadId();
101
* Join a native thread.
103
* @return bool true if successful
105
static bool join(ThreadOps*);
108
* Force the current native thread to yield, letting the scheduler
109
* give the CPU time to another thread.
111
* @return bool true if successful
116
* Set the priority for the native thread if supported by the
119
* @param PRIORITY requested priority
120
* @return bool false if unsuccessful
122
static bool setPriority(ThreadOps*, Priority);
125
* Set the priority for the native thread if supported by the
128
* @param Thread::PRIORITY& current priority
129
* @return bool false if unsuccessful
131
static bool getPriority(ThreadOps*, Priority&);
136
* Spawn a native thread.
138
* @param ThreadImpl* parent thread
139
* @param ThreadImpl* child thread being started.
140
* @param Runnable* task being executed.
142
* @return bool true if successful
144
bool spawn(Runnable*);