Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Thread_WIN32.h
Go to the documentation of this file.
1//
2// Thread_WIN32.h
3//
4// Library: Foundation
5// Package: Threading
6// Module: Thread
7//
8// Definition of the ThreadImpl class for WIN32.
9//
10// Copyright (c) 2004-2009, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Thread_WIN32_INCLUDED
18#define Foundation_Thread_WIN32_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Runnable.h"
23#include "Poco/SharedPtr.h"
24#include "Poco/UnWindows.h"
25
26
27namespace Poco {
28
29
31{
32public:
33 typedef DWORD TIDImpl;
34 typedef void (*Callable)(void*);
35
36#if defined(_DLL)
37 typedef DWORD (WINAPI *Entry)(LPVOID);
38#else
39 typedef unsigned (__stdcall *Entry)(void*);
40#endif
41
43 {
44 PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST,
45 PRIO_LOW_IMPL = THREAD_PRIORITY_BELOW_NORMAL,
46 PRIO_NORMAL_IMPL = THREAD_PRIORITY_NORMAL,
47 PRIO_HIGH_IMPL = THREAD_PRIORITY_ABOVE_NORMAL,
48 PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST
49 };
50
51 enum Policy
52 {
54 };
55
58
59 TIDImpl tidImpl() const;
60 void setPriorityImpl(int prio);
61 int getPriorityImpl() const;
62 void setOSPriorityImpl(int prio, int policy = 0);
63 int getOSPriorityImpl() const;
64 static int getMinOSPriorityImpl(int policy);
65 static int getMaxOSPriorityImpl(int policy);
66 void setStackSizeImpl(int size);
67 int getStackSizeImpl() const;
69 void joinImpl();
70 bool joinImpl(long milliseconds);
71 bool isRunningImpl() const;
72 static void sleepImpl(long milliseconds);
73 static void yieldImpl();
76
77protected:
78#if defined(_DLL)
80#else
81 static unsigned __stdcall runnableEntry(void* pThread);
82#endif
83
84 void createImpl(Entry ent, void* pData);
86
87private:
89 {
90 public:
92 {
93 if (_slot == TLS_OUT_OF_INDEXES)
94 throw SystemException("cannot allocate thread context key");
95 }
97 {
98 TlsFree(_slot);
99 }
101 {
102 return reinterpret_cast<ThreadImpl*>(TlsGetValue(_slot));
103 }
104 void set(ThreadImpl* pThread)
105 {
106 TlsSetValue(_slot, pThread);
107 }
108
109 private:
110 DWORD _slot;
111 };
112
114 HANDLE _thread;
116 int _prio;
118
120};
121
122
123//
124// inlines
125//
126inline int ThreadImpl::getPriorityImpl() const
127{
128 return _prio;
129}
130
131
132inline int ThreadImpl::getOSPriorityImpl() const
133{
134 return _prio;
135}
136
137
138inline int ThreadImpl::getMinOSPriorityImpl(int /* policy */)
139{
140 return PRIO_LOWEST_IMPL;
141}
142
143
144inline int ThreadImpl::getMaxOSPriorityImpl(int /* policy */)
145{
146 return PRIO_HIGHEST_IMPL;
147}
148
149
150inline void ThreadImpl::sleepImpl(long milliseconds)
151{
152 Sleep(DWORD(milliseconds));
153}
154
155
156inline void ThreadImpl::yieldImpl()
157{
158 Sleep(0);
159}
160
161
162inline void ThreadImpl::setStackSizeImpl(int size)
163{
164 _stackSize = size;
165}
166
167
168inline int ThreadImpl::getStackSizeImpl() const
169{
170 return _stackSize;
171}
172
173
175{
176 return _threadId;
177}
178
179
180} // namespace Poco
181
182
183#endif // Foundation_Thread_WIN32_INCLUDED
#define Foundation_API
Definition Foundation.h:60
void set(ThreadImpl *pThread)
void setPriorityImpl(int prio)
void createImpl(Entry ent, void *pData)
static void yieldImpl()
int getPriorityImpl() const
void setStackSizeImpl(int size)
bool joinImpl(long milliseconds)
static unsigned __stdcall runnableEntry(void *pThread)
TIDImpl tidImpl() const
void setOSPriorityImpl(int prio, int policy=0)
SharedPtr< Runnable > _pRunnableTarget
void startImpl(SharedPtr< Runnable > pTarget)
int getOSPriorityImpl() const
static TIDImpl currentTidImpl()
static int getMaxOSPriorityImpl(int policy)
static void sleepImpl(long milliseconds)
void(* Callable)(void *)
unsigned(__stdcall * Entry)(void *)
int getStackSizeImpl() const
static CurrentThreadHolder _currentThreadHolder
bool isRunningImpl() const
static int getMinOSPriorityImpl(int policy)
static ThreadImpl * currentImpl()