pkvthreads.h

Go to the documentation of this file.
00001 
00002 /* ///////////////////////////////////////////////////////////////////////// */
00003 /* This file is a part of the BSTools package                                */
00004 /* written by Przemyslaw Kiciak                                              */
00005 /* ///////////////////////////////////////////////////////////////////////// */
00006 /* (C) Copyright by Przemyslaw Kiciak, 2012                                  */
00007 /* this package is distributed under the terms of the                        */
00008 /* Lesser GNU Public License, see the file COPYING.LIB                       */
00009 /* ///////////////////////////////////////////////////////////////////////// */
00010 
00011 #ifndef PKVTHREADS_H
00012 #define PKVTHREADS_H
00013 
00014 #ifndef _PTHREAD_H
00015 #include <pthread.h>
00016 #endif
00017 
00018 #ifndef PKVARIA_H
00019 #include "pkvaria.h"
00020 #endif
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 typedef void*(*PKVThreadProc)(void*);
00027 typedef boolean (*PKVThreadWorkToDo)(void*,int3*);
00028 
00029 typedef struct {
00030     short int         next;        /* list link */
00031     pthread_t         thread;      /* pthread identifier */
00032     pthread_mutex_t   mutex;
00033     pthread_cond_t    cond;
00034     PKVThreadWorkToDo jobproc;
00035     void              *jobdata;
00036     void              *auxdata;
00037     int3              jobnum;
00038     boolean           valid, waiting, success, pad;
00039     char              *ScratchPtr, *FreeScratchPtr;
00040     size_t            ScratchSize, FreeScratchSize, MinFreeScratch;
00041   } pkv_thread;
00042 
00043 
00044 extern pthread_mutex_t thread_mutex;
00045 extern pthread_t       main_thread;
00046 
00047 extern short int       max_threads;
00048 extern pkv_thread      *pkvthread;
00049 
00050 boolean pkv_InitPThreads ( short int maxthreads );
00051 void pkv_DestroyPThreads ( void );
00052 
00053 short int pkv_PThreadMyPos ( pthread_t *thr );
00054 short int pkv_PThreadIPos ( pthread_t thr );
00055 
00056 void pkv_CancelPThread ( short int pos );
00057 void pkv_CancelPThreads ( void );
00058 
00059 boolean pkv_SetPThreadsToWork ( int3 *jobsize, int npthreads,
00060                                 size_t stacksize, size_t scratchmemsize,
00061                                 void *usrdata,
00062                                 PKVThreadWorkToDo jobproc,
00063                                 void *extradata,
00064                                 PKVThreadWorkToDo extrajob,
00065                                 boolean *success );
00066 
00067 short int pkv_NewJoinablePThread ( size_t stacksize, size_t scratchmemsize,
00068                                    PKVThreadWorkToDo jobproc, void *jobdata,
00069                                    int3 *jobnum, void *auxdata,
00070                                    pthread_t *thread );
00071 
00072 int pkv_FindNCPU ( void );
00073 #ifdef __cplusplus
00074 }
00075 #endif
00076 
00077 #endif /*PKVTHREADS_H*/
00078