github.com/256dpi/max-go@v0.7.0/lib/max/ext_sysparallel.h (about) 1 #ifndef _EXT_SYSPARALLEL_H_ 2 #define _EXT_SYSPARALLEL_H_ 3 4 #include "ext_prefix.h" 5 #include "ext_mess.h" 6 7 #if C74_PRAGMA_STRUCT_PACKPUSH 8 #pragma pack(push, 2) 9 #elif C74_PRAGMA_STRUCT_PACK 10 #pragma pack(2) 11 #endif 12 13 BEGIN_USING_C_LINKAGE 14 15 enum t_sysparallel_priority { 16 SYSPARALLEL_PRIORITY_DEFAULT = 0x00, 17 SYSPARALLEL_PRIORITY_LOW = 0x00, 18 SYSPARALLEL_PRIORITY_MEDIUM = 0x04, 19 SYSPARALLEL_PRIORITY_HIGH = 0x08, 20 SYSPARALLEL_PRIORITY_TASK_LOCAL = 0xa0 21 }; 22 23 enum { 24 SYSPARALLEL_STATE_IDLE = 0, 25 SYSPARALLEL_STATE_RUN = 1, 26 SYSPARALLEL_STATE_DONE = 0, // changed to be the same as IDLE since it means the same thing 27 SYSPARALLEL_STATE_QUIT = 3 28 }; 29 30 enum { 31 SYSPARALLEL_MAX_WORKERS = 64, 32 SYSPARALLEL_TASK_FLAG_WORKERTRIGGERS = 0x00000001 // first worker signals other works as necessary 33 }; 34 35 typedef struct _sysparallel_task 36 { 37 t_object ob; 38 void *obex; 39 void *data; // global task data 40 method workerproc; // worker callback function 41 long workercount; // number of workers to use 42 struct _sysparallel_worker **workers; // worker array 43 unsigned char priority; // thread priority 44 char benchmark; // benchmark 45 long iteration; // for benchmarking 46 double begintime; // for benchmarking 47 double endtime; // for benchmarking 48 long cancel; // for cancel request 49 struct _sysparallel_thread_pool *pool; // this will be NULL. unless using SYSPARALLEL_PRIORITY_TASK_LOCAL 50 long maxworkercount; // maximum number of workers to use 51 long flags; // flags can be set after sysparallel_task_new but before running 52 } t_sysparallel_task; 53 54 55 typedef struct _sysparallel_worker 56 { 57 t_object ob; 58 void *obex; 59 void *data; // worker specific data 60 method workerproc; // worker callback function, worker object passed in 61 t_sysparallel_task *task; // pointer to task parent (can be used to access global task data) 62 long id; // worker id 63 double begintime; // for benchmarking (uses task info) 64 double endtime; // for benchmarking (uses task info) 65 66 } t_sysparallel_worker; 67 68 69 void sysparallel_init(void); 70 long sysparallel_processorcount(void); 71 long sysparallel_physical_processorcount(void); 72 t_sysparallel_task *sysparallel_task_new(void *data, method workerproc, long maxworkercount); 73 t_max_err sysparallel_task_workercount(t_sysparallel_task *x, long workercount); 74 t_max_err sysparallel_task_execute(t_sysparallel_task *x); 75 void sysparallel_task_signalworkers(t_sysparallel_task *x, long count); 76 t_max_err sysparallel_task_cancel(t_sysparallel_task *x); 77 void sysparallel_task_free(t_sysparallel_task *x); 78 void sysparallel_task_benchprint(t_sysparallel_task *x); 79 void sysparallel_task_data(t_sysparallel_task *x, void * data); 80 void sysparallel_task_workerproc(t_sysparallel_task *x, method workerproc); 81 82 t_sysparallel_worker *sysparallel_worker_new(void *data, method workerproc, t_sysparallel_task *task); 83 t_max_err sysparallel_worker_execute(t_sysparallel_worker *x); 84 void sysparallel_worker_free(t_sysparallel_worker *x); 85 86 END_USING_C_LINKAGE 87 88 #if C74_PRAGMA_STRUCT_PACKPUSH 89 #pragma pack(pop) 90 #elif C74_PRAGMA_STRUCT_PACK 91 #pragma pack() 92 #endif 93 94 #endif // _EXT_SYSPARALLEL_H_