Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* $Id$12Copyright (C) 2013 The PARI group.34This file is part of the PARI/GP package.56PARI/GP is free software; you can redistribute it and/or modify it under the7terms of the GNU General Public License as published by the Free Software8Foundation; either version 2 of the License, or (at your option) any later9version. It is distributed in the hope that it will be useful, but WITHOUT10ANY WARRANTY WHATSOEVER.1112Check the License for details. You should have received a copy of it, along13with the package; see the file 'COPYING'. If not, write to the Free Software14Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */15#include "pari.h"16#include "paripriv.h"17#include "mt.h"1819static GEN20mtsingle_queue_get(struct mt_state *mt, long *workid, long *pending)21{22GEN done = mt->pending;23if (workid) *workid = mt->workid;24mt->pending = NULL; *pending = 0;25return done;26}2728static int single_is_thread = 0;29static long single_trace_level = 0;3031static void32mtsingle_queue_submit(struct mt_state *mt, long workid, GEN work)33{34single_is_thread = 1;35mt->pending = work? closure_callgenvec(mt->worker, work): NULL;36single_is_thread = 0;37mt->workid = workid;38}3940static void41mtsingle_queue_end(void) { }4243int44mtsingle_is_thread(void) { return single_is_thread; }4546void47mtsingle_err_recover(long er)48{49(void) er;50if (single_is_thread)51{52evalstate_set_trace(single_trace_level);53single_is_thread = 0;54}55}5657void58mtsingle_queue_start(struct pari_mt *pt, GEN worker)59{60pt->get = mtsingle_queue_get;61pt->submit = mtsingle_queue_submit;62pt->end = mtsingle_queue_end;63pt->mt.worker = worker;64pt->mt.pending = NULL;65single_trace_level = evalstate_get_trace();66}6768void69mt_queue_end(struct pari_mt *pt) { pt->end(); }7071void72mt_queue_submit(struct pari_mt *pt, long workid, GEN work)73{ pt->submit(&pt->mt, workid, work); }7475GEN76mt_queue_get(struct pari_mt *pt, long *workid, long *pending)77{ return pt->get(&pt->mt, workid, pending); }7879void80mt_queue_start(struct pari_mt *pt, GEN worker)81{ return mt_queue_start_lim(pt, worker, 0); }8283void84mtstate_save(struct pari_mtstate *mt)85{86mt->is_thread = single_is_thread;87mt->trace_level = single_trace_level;88mt->pending_threads = mt_is_parallel();89}9091void92mtstate_restore(struct pari_mtstate *mt)93{94single_is_thread = mt->is_thread;95single_trace_level = mt->trace_level;96if (!mt->pending_threads && mt_is_parallel())97mt_queue_reset();98}99100void101mtstate_reset(void)102{103single_is_thread = 0;104single_trace_level = 0;105if (mt_is_parallel())106mt_queue_reset();107}108109110