/usr/include/d/gtkd-3/glib/ThreadPool.d is in libgtkd-3-dev 3.7.5-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | /*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version, with
* some exceptions, please read the COPYING file.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage
module glib.ThreadPool;
private import glib.ConstructionException;
private import glib.ErrorG;
private import glib.GException;
private import glib.c.functions;
public import glib.c.types;
public import gtkc.glibtypes;
private import gtkd.Loader;
/**
* The #GThreadPool struct represents a thread pool. It has three
* public read-only members, but the underlying struct is bigger,
* so you must not copy this struct.
*/
public final class ThreadPool
{
/** the main Gtk struct */
protected GThreadPool* gThreadPool;
protected bool ownedRef;
/** Get the main Gtk struct */
public GThreadPool* getThreadPoolStruct(bool transferOwnership = false)
{
if (transferOwnership)
ownedRef = false;
return gThreadPool;
}
/** the main Gtk struct as a void* */
protected void* getStruct()
{
return cast(void*)gThreadPool;
}
/**
* Sets our main struct and passes it to the parent class.
*/
public this (GThreadPool* gThreadPool, bool ownedRef = false)
{
this.gThreadPool = gThreadPool;
this.ownedRef = ownedRef;
}
~this ()
{
if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
g_free(gThreadPool);
}
/**
* the function to execute in the threads of this pool
*/
public @property GFunc func()
{
return gThreadPool.func;
}
/** Ditto */
public @property void func(GFunc value)
{
gThreadPool.func = value;
}
/**
* the user data for the threads of this pool
*/
public @property void* userData()
{
return gThreadPool.userData;
}
/** Ditto */
public @property void userData(void* value)
{
gThreadPool.userData = value;
}
/**
* are all threads exclusive to this pool
*/
public @property bool exclusive()
{
return gThreadPool.exclusive != 0;
}
/** Ditto */
public @property void exclusive(bool value)
{
gThreadPool.exclusive = value;
}
/**
* Frees all resources allocated for @pool.
*
* If @immediate is %TRUE, no new task is processed for @pool.
* Otherwise @pool is not freed before the last task is processed.
* Note however, that no thread of this pool is interrupted while
* processing a task. Instead at least all still running threads
* can finish their tasks before the @pool is freed.
*
* If @wait_ is %TRUE, the functions does not return before all
* tasks to be processed (dependent on @immediate, whether all
* or only the currently running) are ready.
* Otherwise the function returns immediately.
*
* After calling this function @pool must not be used anymore.
*
* Params:
* immediate = should @pool shut down immediately?
* wait = should the function wait for all tasks to be finished?
*/
public void free(bool immediate, bool wait)
{
g_thread_pool_free(gThreadPool, immediate, wait);
}
/**
* Returns the maximal number of threads for @pool.
*
* Returns: the maximal number of threads
*/
public int getMaxThreads()
{
return g_thread_pool_get_max_threads(gThreadPool);
}
/**
* Returns the number of threads currently running in @pool.
*
* Returns: the number of threads currently running
*/
public uint getNumThreads()
{
return g_thread_pool_get_num_threads(gThreadPool);
}
/**
* Moves the item to the front of the queue of unprocessed
* items, so that it will be processed next.
*
* Params:
* data = an unprocessed item in the pool
*
* Returns: %TRUE if the item was found and moved
*
* Since: 2.46
*/
public bool moveToFront(void* data)
{
return g_thread_pool_move_to_front(gThreadPool, data) != 0;
}
/**
* Inserts @data into the list of tasks to be executed by @pool.
*
* When the number of currently running threads is lower than the
* maximal allowed number of threads, a new thread is started (or
* reused) with the properties given to g_thread_pool_new().
* Otherwise, @data stays in the queue until a thread in this pool
* finishes its previous task and processes @data.
*
* @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when a new thread couldn't be
* created. In that case @data is simply appended to the queue of
* work to do.
*
* Before version 2.32, this function did not return a success status.
*
* Params:
* data = a new task for @pool
*
* Returns: %TRUE on success, %FALSE if an error occurred
*
* Throws: GException on failure.
*/
public bool push(void* data)
{
GError* err = null;
auto p = g_thread_pool_push(gThreadPool, data, &err) != 0;
if (err !is null)
{
throw new GException( new ErrorG(err) );
}
return p;
}
/**
* Sets the maximal allowed number of threads for @pool.
* A value of -1 means that the maximal number of threads
* is unlimited. If @pool is an exclusive thread pool, setting
* the maximal number of threads to -1 is not allowed.
*
* Setting @max_threads to 0 means stopping all work for @pool.
* It is effectively frozen until @max_threads is set to a non-zero
* value again.
*
* A thread is never terminated while calling @func, as supplied by
* g_thread_pool_new(). Instead the maximal number of threads only
* has effect for the allocation of new threads in g_thread_pool_push().
* A new thread is allocated, whenever the number of currently
* running threads in @pool is smaller than the maximal number.
*
* @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when a new thread couldn't be
* created.
*
* Before version 2.32, this function did not return a success status.
*
* Params:
* maxThreads = a new maximal number of threads for @pool,
* or -1 for unlimited
*
* Returns: %TRUE on success, %FALSE if an error occurred
*
* Throws: GException on failure.
*/
public bool setMaxThreads(int maxThreads)
{
GError* err = null;
auto p = g_thread_pool_set_max_threads(gThreadPool, maxThreads, &err) != 0;
if (err !is null)
{
throw new GException( new ErrorG(err) );
}
return p;
}
/**
* Sets the function used to sort the list of tasks. This allows the
* tasks to be processed by a priority determined by @func, and not
* just in the order in which they were added to the pool.
*
* Note, if the maximum number of threads is more than 1, the order
* that threads are executed cannot be guaranteed 100%. Threads are
* scheduled by the operating system and are executed at random. It
* cannot be assumed that threads are executed in the order they are
* created.
*
* Params:
* func = the #GCompareDataFunc used to sort the list of tasks.
* This function is passed two tasks. It should return
* 0 if the order in which they are handled does not matter,
* a negative value if the first task should be processed before
* the second or a positive value if the second task should be
* processed first.
* userData = user data passed to @func
*
* Since: 2.10
*/
public void setSortFunction(GCompareDataFunc func, void* userData)
{
g_thread_pool_set_sort_function(gThreadPool, func, userData);
}
/**
* Returns the number of tasks still unprocessed in @pool.
*
* Returns: the number of unprocessed tasks
*/
public uint unprocessed()
{
return g_thread_pool_unprocessed(gThreadPool);
}
/**
* This function will return the maximum @interval that a
* thread will wait in the thread pool for new tasks before
* being stopped.
*
* If this function returns 0, threads waiting in the thread
* pool for new work are not stopped.
*
* Returns: the maximum @interval (milliseconds) to wait
* for new tasks in the thread pool before stopping the
* thread
*
* Since: 2.10
*/
public static uint getMaxIdleTime()
{
return g_thread_pool_get_max_idle_time();
}
/**
* Returns the maximal allowed number of unused threads.
*
* Returns: the maximal number of unused threads
*/
public static int getMaxUnusedThreads()
{
return g_thread_pool_get_max_unused_threads();
}
/**
* Returns the number of currently unused threads.
*
* Returns: the number of currently unused threads
*/
public static uint getNumUnusedThreads()
{
return g_thread_pool_get_num_unused_threads();
}
/**
* This function creates a new thread pool.
*
* Whenever you call g_thread_pool_push(), either a new thread is
* created or an unused one is reused. At most @max_threads threads
* are running concurrently for this thread pool. @max_threads = -1
* allows unlimited threads to be created for this thread pool. The
* newly created or reused thread now executes the function @func
* with the two arguments. The first one is the parameter to
* g_thread_pool_push() and the second one is @user_data.
*
* The parameter @exclusive determines whether the thread pool owns
* all threads exclusive or shares them with other thread pools.
* If @exclusive is %TRUE, @max_threads threads are started
* immediately and they will run exclusively for this thread pool
* until it is destroyed by g_thread_pool_free(). If @exclusive is
* %FALSE, threads are created when needed and shared between all
* non-exclusive thread pools. This implies that @max_threads may
* not be -1 for exclusive thread pools. Besides, exclusive thread
* pools are not affected by g_thread_pool_set_max_idle_time()
* since their threads are never considered idle and returned to the
* global pool.
*
* @error can be %NULL to ignore errors, or non-%NULL to report
* errors. An error can only occur when @exclusive is set to %TRUE
* and not all @max_threads threads could be created.
* See #GThreadError for possible errors that may occur.
* Note, even in case of error a valid #GThreadPool is returned.
*
* Params:
* func = a function to execute in the threads of the new thread pool
* userData = user data that is handed over to @func every time it
* is called
* maxThreads = the maximal number of threads to execute concurrently
* in the new thread pool, -1 means no limit
* exclusive = should this thread pool be exclusive?
*
* Returns: the new #GThreadPool
*
* Throws: GException on failure.
* Throws: ConstructionException GTK+ fails to create the object.
*/
public this(GFunc func, void* userData, int maxThreads, bool exclusive)
{
GError* err = null;
auto p = g_thread_pool_new(func, userData, maxThreads, exclusive, &err);
if (err !is null)
{
throw new GException( new ErrorG(err) );
}
if(p is null)
{
throw new ConstructionException("null returned by new");
}
this(cast(GThreadPool*) p);
}
/**
* This function will set the maximum @interval that a thread
* waiting in the pool for new tasks can be idle for before
* being stopped. This function is similar to calling
* g_thread_pool_stop_unused_threads() on a regular timeout,
* except this is done on a per thread basis.
*
* By setting @interval to 0, idle threads will not be stopped.
*
* The default value is 15000 (15 seconds).
*
* Params:
* interval = the maximum @interval (in milliseconds)
* a thread can be idle
*
* Since: 2.10
*/
public static void setMaxIdleTime(uint interval)
{
g_thread_pool_set_max_idle_time(interval);
}
/**
* Sets the maximal number of unused threads to @max_threads.
* If @max_threads is -1, no limit is imposed on the number
* of unused threads.
*
* The default value is 2.
*
* Params:
* maxThreads = maximal number of unused threads
*/
public static void setMaxUnusedThreads(int maxThreads)
{
g_thread_pool_set_max_unused_threads(maxThreads);
}
/**
* Stops all currently unused threads. This does not change the
* maximal number of unused threads. This function can be used to
* regularly stop all unused threads e.g. from g_timeout_add().
*/
public static void stopUnusedThreads()
{
g_thread_pool_stop_unused_threads();
}
}
|