gi-glib-2.0.24: GLib bindings

Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.GLib.Structs.ThreadPool

Contents

- Exported types
- Methods
  - Overloaded methods
  - free
  - getMaxIdleTime
  - getMaxThreads
  - getMaxUnusedThreads
  - getNumThreads
  - getNumUnusedThreads
  - moveToFront
  - push
  - setMaxIdleTime
  - setMaxThreads
  - setMaxUnusedThreads
  - stopUnusedThreads
  - unprocessed
- Properties
  - exclusive
  - func
  - userData

Description

The `ThreadPool` 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.

Synopsis

- newtype ThreadPool = ThreadPool (ManagedPtr ThreadPool)
- newZeroThreadPool :: MonadIO m => m ThreadPool
- threadPoolFree :: (HasCallStack, MonadIO m) => ThreadPool -> Bool -> Bool -> m ()
- threadPoolGetMaxIdleTime :: (HasCallStack, MonadIO m) => m Word32
- threadPoolGetMaxThreads :: (HasCallStack, MonadIO m) => ThreadPool -> m Int32
- threadPoolGetMaxUnusedThreads :: (HasCallStack, MonadIO m) => m Int32
- threadPoolGetNumThreads :: (HasCallStack, MonadIO m) => ThreadPool -> m Word32
- threadPoolGetNumUnusedThreads :: (HasCallStack, MonadIO m) => m Word32
- threadPoolMoveToFront :: (HasCallStack, MonadIO m) => ThreadPool -> Ptr () -> m Bool
- threadPoolPush :: (HasCallStack, MonadIO m) => ThreadPool -> Ptr () -> m ()
- threadPoolSetMaxIdleTime :: (HasCallStack, MonadIO m) => Word32 -> m ()
- threadPoolSetMaxThreads :: (HasCallStack, MonadIO m) => ThreadPool -> Int32 -> m ()
- threadPoolSetMaxUnusedThreads :: (HasCallStack, MonadIO m) => Int32 -> m ()
- threadPoolStopUnusedThreads :: (HasCallStack, MonadIO m) => m ()
- threadPoolUnprocessed :: (HasCallStack, MonadIO m) => ThreadPool -> m Word32
- getThreadPoolExclusive :: MonadIO m => ThreadPool -> m Bool
- setThreadPoolExclusive :: MonadIO m => ThreadPool -> Bool -> m ()
- clearThreadPoolFunc :: MonadIO m => ThreadPool -> m ()
- getThreadPoolFunc :: MonadIO m => ThreadPool -> m (Maybe Func_WithClosures)
- setThreadPoolFunc :: MonadIO m => ThreadPool -> FunPtr C_Func -> m ()
- clearThreadPoolUserData :: MonadIO m => ThreadPool -> m ()
- getThreadPoolUserData :: MonadIO m => ThreadPool -> m (Ptr ())
- setThreadPoolUserData :: MonadIO m => ThreadPool -> Ptr () -> m ()

# Exported types

newtype ThreadPool Source #

Memory-managed wrapper type.

Constructors

ThreadPool (ManagedPtr ThreadPool) |

#### Instances

Instances details

Eq ThreadPool Source # |
Instance details Defined in GI.GLib.Structs.ThreadPool Methods (==) :: ThreadPool -> ThreadPool -> Bool # (/=) :: ThreadPool -> ThreadPool -> Bool #
ManagedPtrNewtype ThreadPool Source # |
Instance details Defined in GI.GLib.Structs.ThreadPool Methods toManagedPtr :: ThreadPool -> ManagedPtr ThreadPool Source #
BoxedPtr ThreadPool Source # |
Instance details Defined in GI.GLib.Structs.ThreadPool Methods boxedPtrCopy :: ThreadPool -> IO ThreadPool Source # boxedPtrFree :: ThreadPool -> IO () Source #
CallocPtr ThreadPool Source # |
Instance details Defined in GI.GLib.Structs.ThreadPool Methods boxedPtrCalloc :: IO (Ptr ThreadPool) Source #
tag ~ 'AttrSet => Constructible ThreadPool tag Source # |
Instance details Defined in GI.GLib.Structs.ThreadPool Methods new :: MonadIO m => (ManagedPtr ThreadPool -> ThreadPool) -> [AttrOp ThreadPool tag] -> m ThreadPool Source #

newZeroThreadPool :: MonadIO m => m ThreadPool Source #

Construct a `ThreadPool` struct initialized to zero.

# Methods

## Overloaded methods

## free

threadPoolFree Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> Bool | `immediate`: should `pool` shut down immediately?
-> Bool | `wait_`: should the function wait for all tasks to be finished?
-> m () |

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`, this function does not return before all tasks to be processed (dependent on `immediate`, whether all or only the currently running) are ready. Otherwise this function returns immediately.

After calling this function `pool` must not be used anymore.

## getMaxIdleTime

threadPoolGetMaxIdleTime Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Word32 | Returns: the maximum `interval` (milliseconds) to wait for new tasks in the thread pool before stopping the thread

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.

Since: 2.10

## getMaxThreads

threadPoolGetMaxThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> m Int32 | Returns: the maximal number of threads

Returns the maximal number of threads for `pool`.

## getMaxUnusedThreads

threadPoolGetMaxUnusedThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Int32 | Returns: the maximal number of unused threads

Returns the maximal allowed number of unused threads.

## getNumThreads

threadPoolGetNumThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> m Word32 | Returns: the number of threads currently running

Returns the number of threads currently running in `pool`.

## getNumUnusedThreads

threadPoolGetNumUnusedThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Word32 | Returns: the number of currently unused threads

Returns the number of currently unused threads.

## moveToFront

threadPoolMoveToFront Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> Ptr () | `data`: an unprocessed item in the pool
-> m Bool | Returns: `True` if the item was found and moved

Moves the item to the front of the queue of unprocessed items, so that it will be processed next.

Since: 2.46

## push

threadPoolPush Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> Ptr () | `data`: a new task for `pool`
-> m () | (Can throw `GError`)

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 `Nothing` to ignore errors, or non-`Nothing` 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.

## setMaxIdleTime

threadPoolSetMaxIdleTime Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Word32 | `interval`: the maximum `interval` (in milliseconds) a thread can be idle
-> m () |

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 `threadPoolStopUnusedThreads` 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).

Since: 2.10

## setMaxThreads

threadPoolSetMaxThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> Int32 | `maxThreads`: a new maximal number of threads for `pool`, or -1 for unlimited
-> m () | (Can throw `GError`)

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 `maxThreads` to 0 means stopping all work for `pool`. It is effectively frozen until `maxThreads` 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 `threadPoolPush`. A new thread is allocated, whenever the number of currently running threads in `pool` is smaller than the maximal number.

`error` can be `Nothing` to ignore errors, or non-`Nothing` 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.

## setMaxUnusedThreads

threadPoolSetMaxUnusedThreads Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Int32 | `maxThreads`: maximal number of unused threads
-> m () |

Sets the maximal number of unused threads to `maxThreads`. If `maxThreads` is -1, no limit is imposed on the number of unused threads.

The default value is 2.

## stopUnusedThreads

threadPoolStopUnusedThreads :: (HasCallStack, MonadIO m) => m () Source #

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()`.

## unprocessed

threadPoolUnprocessed Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ThreadPool | `pool`: a `ThreadPool`
-> m Word32 | Returns: the number of unprocessed tasks

Returns the number of tasks still unprocessed in `pool`.

# Properties

## exclusive

are all threads exclusive to this pool

getThreadPoolExclusive :: MonadIO m => ThreadPool -> m Bool Source #

Get the value of the “`exclusive`” field. When overloading is enabled, this is equivalent to

    get threadPool #exclusive

setThreadPoolExclusive :: MonadIO m => ThreadPool -> Bool -> m () Source #

Set the value of the “`exclusive`” field. When overloading is enabled, this is equivalent to

    set threadPool [ #exclusive := value ]

## func

the function to execute in the threads of this pool

clearThreadPoolFunc :: MonadIO m => ThreadPool -> m () Source #

Set the value of the “`func`” field to `Nothing`. When overloading is enabled, this is equivalent to

    clear #func

getThreadPoolFunc :: MonadIO m => ThreadPool -> m (Maybe Func_WithClosures) Source #

Get the value of the “`func`” field. When overloading is enabled, this is equivalent to

    get threadPool #func

setThreadPoolFunc :: MonadIO m => ThreadPool -> FunPtr C_Func -> m () Source #

Set the value of the “`func`” field. When overloading is enabled, this is equivalent to

    set threadPool [ #func := value ]

## userData

the user data for the threads of this pool

clearThreadPoolUserData :: MonadIO m => ThreadPool -> m () Source #

Set the value of the “`user_data`” field to `Nothing`. When overloading is enabled, this is equivalent to

    clear #userData

getThreadPoolUserData :: MonadIO m => ThreadPool -> m (Ptr ()) Source #

Get the value of the “`user_data`” field. When overloading is enabled, this is equivalent to

    get threadPool #userData

setThreadPoolUserData :: MonadIO m => ThreadPool -> Ptr () -> m () Source #

Set the value of the “`user_data`” field. When overloading is enabled, this is equivalent to

    set threadPool [ #userData := value ]