terom@19: #ifndef PNGTILE_CTX_H terom@19: #define PNGTILE_CTX_H terom@19: terom@19: /** terom@19: * Shared context between images, used to provide a threadpool for parralelizing tile operations terom@19: */ terom@19: #include "pngtile.h" terom@19: terom@19: #include terom@19: #include terom@19: #include terom@19: terom@19: /** terom@19: * Worker thread terom@19: */ terom@19: struct pt_thread { terom@19: /** Shared context */ terom@19: struct pt_ctx *ctx; terom@19: terom@19: /** Thread handle */ terom@19: pthread_t tid; terom@19: terom@19: /** @see pt_ctx::threads */ terom@19: TAILQ_ENTRY(pt_thread) ctx_threads; terom@19: }; terom@19: terom@19: /** terom@19: * Work function terom@19: */ terom@19: typedef void (*pt_work_func) (void *arg); terom@19: terom@19: /** terom@19: * Work that needs to be done terom@19: */ terom@19: struct pt_work { terom@19: /** Work func */ terom@19: pt_work_func func; terom@19: terom@19: /** Work info */ terom@19: void *arg; terom@19: terom@19: /** @see pt_ctx::work */ terom@19: TAILQ_ENTRY(pt_work) ctx_work; terom@19: }; terom@19: terom@19: /** terom@19: * Shared context terom@19: */ terom@19: struct pt_ctx { terom@19: /** Accepting new work */ terom@19: bool running; terom@19: terom@19: /** Threadpool */ terom@19: TAILQ_HEAD(pt_ctx_threads, pt_thread) threads; terom@19: terom@19: /** Pending work */ terom@19: TAILQ_HEAD(pt_ctx_work, pt_work) work; terom@19: terom@19: /** Control access to ::work */ terom@19: pthread_mutex_t work_mutex; terom@19: terom@19: /** Wait for work to become available */ terom@19: pthread_cond_t work_cond; terom@19: terom@19: /** Thread is idle */ terom@19: pthread_cond_t idle_cond; terom@19: }; terom@19: terom@19: /** terom@19: * Enqueue a work unit terom@19: */ terom@19: int pt_ctx_work (struct pt_ctx *ctx, pt_work_func func, void *arg); terom@19: terom@19: terom@19: #endif