2009-11-23 01:55:08 +01:00
|
|
|
/*
|
2014-10-15 23:08:53 +02:00
|
|
|
THREADPOOL.h - Manage pools of threads
|
2009-11-23 01:55:08 +01:00
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2009, Michael Ploujnikov <ploujj@gmail.com>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
2009-11-23 01:55:08 +01:00
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2014-10-15 23:08:53 +02:00
|
|
|
|
2009-11-23 01:55:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 23:08:53 +02:00
|
|
|
#ifndef BACKEND_THREADPOOL_H
|
|
|
|
|
#define BACKEND_THREADPOOL_H
|
|
|
|
|
|
2010-01-04 23:03:47 +01:00
|
|
|
#include "lib/condition.h"
|
2009-11-23 01:55:08 +01:00
|
|
|
#include "lib/llist.h"
|
|
|
|
|
#include "threads.h"
|
|
|
|
|
|
|
|
|
|
#include <nobug.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Acquire a thread from a threadpool.
|
2009-11-23 22:40:31 +01:00
|
|
|
* This may either pick a thread from an appropriate pool or create a new one when the pool is empty.
|
2009-11-23 01:55:08 +01:00
|
|
|
* This function doesn't need to be accessible outside of the threadpool implementation.
|
|
|
|
|
*/
|
|
|
|
|
LumieraThread
|
|
|
|
|
lumiera_threadpool_acquire_thread(enum lumiera_thread_class kind,
|
|
|
|
|
const char* purpose,
|
|
|
|
|
struct nobug_flag* flag);
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-23 19:10:31 +01:00
|
|
|
* Park a thread
|
|
|
|
|
* This ends up putting a finished thread back on the list of an appropriate threadpool.
|
2009-11-23 01:55:08 +01:00
|
|
|
* This function doesn't need to be accessible outside of the threadpool implementation.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
lumiera_threadpool_release_thread(LumieraThread thread);
|
|
|
|
|
|
2009-11-23 22:40:31 +01:00
|
|
|
typedef struct lumiera_threadpool_struct lumiera_threadpool;
|
|
|
|
|
typedef lumiera_threadpool* LumieraThreadpool;
|
|
|
|
|
|
2010-01-18 17:53:33 +01:00
|
|
|
enum lumiera_threadpool_state {
|
|
|
|
|
LUMIERA_THREADPOOL_OFFLINE,
|
|
|
|
|
LUMIERA_THREADPOOL_ONLINE
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-23 22:40:31 +01:00
|
|
|
struct lumiera_threadpool_struct
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2010-01-10 03:36:20 +01:00
|
|
|
llist working_list;
|
2010-01-11 21:04:52 +01:00
|
|
|
llist idle_list;
|
2009-12-03 04:21:49 +01:00
|
|
|
pthread_attr_t pthread_attrs;
|
2009-12-24 01:54:49 +01:00
|
|
|
lumiera_condition sync;
|
2010-01-18 17:53:33 +01:00
|
|
|
enum lumiera_threadpool_state status;
|
2009-11-26 17:27:50 +01:00
|
|
|
} pool[LUMIERA_THREADCLASS_COUNT];
|
2009-11-23 22:40:31 +01:00
|
|
|
};
|
|
|
|
|
|
2014-10-15 23:08:53 +02:00
|
|
|
|
|
|
|
|
/** Initialise the thread pool. */
|
2009-11-23 22:40:31 +01:00
|
|
|
void
|
2009-12-31 13:24:07 +01:00
|
|
|
lumiera_threadpool_init(void);
|
2009-11-23 01:55:08 +01:00
|
|
|
|
2009-11-25 04:25:00 +01:00
|
|
|
void
|
|
|
|
|
lumiera_threadpool_destroy(void);
|
|
|
|
|
|
2014-10-15 23:08:53 +02:00
|
|
|
|
|
|
|
|
#endif /*BACKEND_THREADPOOL_H*/
|
2009-11-23 01:55:08 +01:00
|
|
|
/*
|
|
|
|
|
// Local Variables:
|
|
|
|
|
// mode: C
|
|
|
|
|
// c-file-style: "gnu"
|
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
|
// End:
|
|
|
|
|
*/
|