/** @file  psThread.h
 *
 *  @brief tools to manage a pool of threads
 *
 *  @author EAM, IFA
 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2008-07-31 23:56:29 $
 *
 *  Copyright 2004-2005 Insitute for Astronomy, University of Hawaii
 */

#ifndef PS_THREAD_H
#define PS_THREAD_H

/// @addtogroup SysUtils System Utilities
/// @{

typedef struct {
    psString type;
    psArray *args;
} psThreadJob;

typedef struct {
    bool busy;
    bool fault;
    pthread_t pt;
} psThread;

typedef bool (*psThreadTaskFunction)(psThreadJob *job);

typedef struct {
    psString type;
    int nArgs;
    psThreadTaskFunction function;
} psThreadTask;

// typedef void *(*psThreadLaunchJobsFunction)(void *data);

void psThreadLock ();
void psThreadUnlock ();

psThread *psThreadAlloc ();

psThreadJob *psThreadJobAlloc (char *type);
bool psThreadJobAddPending (psThreadJob *job);
psThreadJob *psThreadJobGetPending ();
psThreadJob *psThreadJobGetDone ();

psThreadTask *psThreadTaskAlloc (char *type, int nArgs);
bool psThreadTaskAdd (psThreadTask *task);
void *psThreadLauncher (void *data);

bool psThreadPoolInit (int nThreads);
bool psThreadPoolWait ();
bool psThreadPoolFinalize ();

/// @}
#endif /* PS_THREAD_H */
