My Project
Data Structures | Typedefs | Functions | Variables
LibThread Namespace Reference

Data Structures

class  AccTrigger
 
class  ByteBuf
 
class  Channel
 
class  Command
 
class  CountTrigger
 
class  EvalJob
 
class  ExecJob
 
class  InterpreterThread
 
class  Job
 
struct  JobCompare
 
class  KernelJob
 
class  ProcJob
 
class  ProcTrigger
 
class  RawKernelJob
 
class  Region
 
struct  SchedInfo
 
class  Scheduler
 
class  SetTrigger
 
class  SharedObject
 
class  SingularChannel
 
class  SingularSyncVar
 
class  SyncVar
 
class  ThreadPool
 
class  ThreadState
 
class  Transactional
 
class  Trigger
 
class  TxList
 
class  TxTable
 

Typedefs

typedef std::map< std::string, SharedObject * > SharedObjectTable
 
typedef SharedObjectSharedObjectPtr
 
typedef SharedObjectPtr(* SharedConstructor) ()
 
typedef queue< Job * > JobQueue
 
typedef void *(* ThreadFunc) (ThreadState *, void *)
 

Functions

char * allocate_space (size_t n)
 
void free_space (size_t n, char *p)
 
ThreadPoolcreateThreadPool (int threads, int prioThreads=0)
 
void closeThreadPool (ThreadPool *pool, bool wait)
 
ThreadPoolgetCurrentThreadPool ()
 
JobcreateJob (void(*func)(leftv result, leftv arg))
 
JobcreateJob (void(*func)(long ndeps, Job **deps))
 
JobgetCurrentJob ()
 
bool getJobCancelled ()
 
bool getJobCancelled (Job *job)
 
void addJobArgs (Job *job, leftv arg)
 
void setJobData (Job *job, void *data)
 
void * getJobData (Job *job)
 
leftv getJobResult (Job *job)
 
const char * getJobName ()
 
void setJobName (const char *)
 
JobstartJob (ThreadPool *pool, Job *job, leftv arg)
 
JobstartJob (ThreadPool *pool, Job *job)
 
void cancelJob (Job *job)
 
void waitJob (Job *job)
 
void release (Job *job)
 
void release (ThreadPool *pool)
 
void retain (Job *job)
 
void retain (ThreadPool *pool)
 
void acquireShared (SharedObject *obj)
 
void releaseShared (SharedObject *obj)
 
SharedObjectmakeSharedObject (SharedObjectTable &table, Lock *lock, int type, string &name, SharedConstructor scons)
 
SharedObjectfindSharedObject (SharedObjectTable &table, Lock *lock, string &name)
 
void * shared_init (blackbox *b)
 
void * new_shared (SharedObject *obj)
 
void shared_destroy (blackbox *b, void *d)
 
void rlock_destroy (blackbox *b, void *d)
 
void * shared_copy (blackbox *b, void *d)
 
BOOLEAN shared_assign (leftv l, leftv r)
 
BOOLEAN rlock_assign (leftv l, leftv r)
 
BOOLEAN shared_check_assign (blackbox *b, leftv l, leftv r)
 
BOOLEAN shared_op2 (int op, leftv res, leftv a1, leftv a2)
 
BOOLEAN shared_op3 (int op, leftv res, leftv a1, leftv a2, leftv a3)
 
char * shared_string (blackbox *b, void *d)
 
char * rlock_string (blackbox *b, void *d)
 
void report (const char *fmt, const char *name)
 
int wrong_num_args (const char *name, leftv arg, int n)
 
int not_a_uri (const char *name, leftv arg)
 
int not_a_region (const char *name, leftv arg)
 
char * str (leftv arg)
 
SharedObjectconsTable ()
 
SharedObjectconsList ()
 
SharedObjectconsChannel ()
 
SharedObjectconsSyncVar ()
 
SharedObjectconsRegion ()
 
static void appendArg (vector< leftv > &argv, string &s)
 
static void appendArg (vector< leftv > &argv, leftv arg)
 
static void appendArgCopy (vector< leftv > &argv, leftv arg)
 
static BOOLEAN executeProc (sleftv &result, const char *procname, const vector< leftv > &argv)
 
BOOLEAN makeAtomicTable (leftv result, leftv arg)
 
BOOLEAN makeAtomicList (leftv result, leftv arg)
 
BOOLEAN makeSharedTable (leftv result, leftv arg)
 
BOOLEAN makeSharedList (leftv result, leftv arg)
 
BOOLEAN makeChannel (leftv result, leftv arg)
 
BOOLEAN makeSyncVar (leftv result, leftv arg)
 
BOOLEAN makeRegion (leftv result, leftv arg)
 
BOOLEAN findSharedObject (leftv result, leftv arg)
 
BOOLEAN typeSharedObject (leftv result, leftv arg)
 
BOOLEAN bindSharedObject (leftv result, leftv arg)
 
BOOLEAN getTable (leftv result, leftv arg)
 
BOOLEAN inTable (leftv result, leftv arg)
 
BOOLEAN putTable (leftv result, leftv arg)
 
BOOLEAN getList (leftv result, leftv arg)
 
BOOLEAN putList (leftv result, leftv arg)
 
BOOLEAN lockRegion (leftv result, leftv arg)
 
BOOLEAN regionLock (leftv result, leftv arg)
 
BOOLEAN unlockRegion (leftv result, leftv arg)
 
BOOLEAN sendChannel (leftv result, leftv arg)
 
BOOLEAN receiveChannel (leftv result, leftv arg)
 
BOOLEAN statChannel (leftv result, leftv arg)
 
BOOLEAN writeSyncVar (leftv result, leftv arg)
 
BOOLEAN updateSyncVar (leftv result, leftv arg)
 
BOOLEAN readSyncVar (leftv result, leftv arg)
 
BOOLEAN statSyncVar (leftv result, leftv arg)
 
void encode_shared (LinTree::LinTree &lintree, leftv val)
 
leftv decode_shared (LinTree::LinTree &lintree)
 
void ref_shared (LinTree::LinTree &lintree, int by)
 
void installShared (int type)
 
void makeSharedType (int &type, const char *name)
 
void makeRegionlockType (int &type, const char *name)
 
void setOption (int ch)
 
void thread_init ()
 
void * thread_main (void *arg)
 
void * interpreter_thread (ThreadState *ts, void *arg)
 
static ThreadStatenewThread (void *(*thread_func)(ThreadState *, void *), void *arg, const char **error)
 
ThreadStatecreateThread (void *(*thread_func)(ThreadState *, void *), void *arg)
 
void * joinThread (ThreadState *ts)
 
static InterpreterThreadcreateInterpreterThread (const char **error)
 
static BOOLEAN createThread (leftv result, leftv arg)
 
static bool joinInterpreterThread (InterpreterThread *thread)
 
static BOOLEAN joinThread (leftv result, leftv arg)
 
static BOOLEAN createThreadPool (leftv result, leftv arg)
 
static BOOLEAN createThreadPoolSet (leftv result, leftv arg)
 
static BOOLEAN getThreadPoolWorkers (leftv result, leftv arg)
 
static BOOLEAN setThreadPoolWorkers (leftv result, leftv arg)
 
static BOOLEAN getThreadPoolConcurrency (leftv result, leftv arg)
 
static BOOLEAN setThreadPoolConcurrency (leftv result, leftv arg)
 
static BOOLEAN closeThreadPool (leftv result, leftv arg)
 
BOOLEAN currentThreadPool (leftv result, leftv arg)
 
BOOLEAN setCurrentThreadPool (leftv result, leftv arg)
 
static BOOLEAN createJob (leftv result, leftv arg)
 
static BOOLEAN startJob (leftv result, leftv arg)
 
static BOOLEAN waitJob (leftv result, leftv arg)
 
static BOOLEAN cancelJob (leftv result, leftv arg)
 
static BOOLEAN jobCancelled (leftv result, leftv arg)
 
const char * getJobName (Job *job)
 
void setJobName (Job *job, const char *name)
 
static BOOLEAN createTrigger (leftv result, leftv arg)
 
static BOOLEAN updateTrigger (leftv result, leftv arg)
 
static BOOLEAN chainTrigger (leftv result, leftv arg)
 
static BOOLEAN testTrigger (leftv result, leftv arg)
 
static BOOLEAN scheduleJob (leftv result, leftv arg)
 
BOOLEAN currentJob (leftv result, leftv arg)
 
BOOLEAN threadID (leftv result, leftv arg)
 
BOOLEAN mainThread (leftv result, leftv arg)
 
BOOLEAN threadEval (leftv result, leftv arg)
 
BOOLEAN threadExec (leftv result, leftv arg)
 
BOOLEAN threadPoolExec (leftv result, leftv arg)
 
BOOLEAN threadResult (leftv result, leftv arg)
 
BOOLEAN setSharedName (leftv result, leftv arg)
 
BOOLEAN getSharedName (leftv result, leftv arg)
 
ThreadStatecreateThread (ThreadFunc body, void **arg, const char **error)
 
template<typename T >
Tshared_alloc (std::size_t n)
 
template<typename T >
Tshared_alloc0 (std::size_t n)
 
template<typename T >
T shared_free (T *p)
 
template<typename T >
Tshared_alloc (size_t n)
 
template<typename T >
Tshared_alloc0 (size_t n)
 
template<typename T >
void shared_free (T *p)
 

Variables

const int have_threads = 0
 
Lock global_objects_lock
 
SharedObjectTable global_objects
 
Lock master_lock (true)
 
Lock name_lock (true)
 
VAR long thread_id
 
long thread_counter
 
int type_region
 
int type_regionlock
 
int type_channel
 
int type_syncvar
 
int type_atomic_table
 
int type_shared_table
 
int type_atomic_list
 
int type_shared_list
 
int type_thread
 
int type_threadpool
 
int type_job
 
int type_trigger
 
Lock thread_lock
 
ThreadStatethread_state
 
STATIC_VAR ThreadPoolcurrentThreadPoolRef
 
STATIC_VAR JobcurrentJobRef
 

Data Structure Documentation

◆ LibThread::SchedInfo

struct LibThread::SchedInfo

Definition at line 1624 of file shared.cc.

Data Fields
Job * job
int num
Scheduler * scheduler

Typedef Documentation

◆ JobQueue

typedef queue<Job *> LibThread::JobQueue

Definition at line 1620 of file shared.cc.

◆ SharedConstructor

typedef SharedObjectPtr(* LibThread::SharedConstructor) ()

Definition at line 247 of file shared.cc.

◆ SharedObjectPtr

Definition at line 246 of file shared.cc.

◆ SharedObjectTable

Definition at line 203 of file shared.cc.

◆ ThreadFunc

typedef void *(* LibThread::ThreadFunc) (ThreadState *, void *)

Definition at line 12 of file singthreads.h.

Function Documentation

◆ acquireShared()

void LibThread::acquireShared ( SharedObject obj)

Definition at line 193 of file shared.cc.

193 {
194 obj->incref();
195}
void incref(int by=1)
Definition: shared.cc:170

◆ addJobArgs()

void LibThread::addJobArgs ( Job job,
leftv  arg 
)

Definition at line 2665 of file shared.cc.

2665 {
2666 ThreadPool *pool = job->pool;
2667 if (pool) pool->scheduler->lock.lock();
2668 while (arg) {
2669 job->args.push_back(LinTree::to_string(arg));
2670 arg = arg->next;
2671 }
2672 if (pool) pool->scheduler->lock.unlock();
2673}
vector< string > args
Definition: shared.cc:1558
ThreadPool * pool
Definition: shared.cc:1551
Scheduler * scheduler
Definition: shared.cc:1635
void lock()
Definition: thread.h:46
void unlock()
Definition: thread.h:57
leftv next
Definition: subexpr.h:86
std::string to_string(leftv val)
Definition: lintree.cc:843

◆ allocate_space()

char * LibThread::allocate_space ( size_t  n)

◆ appendArg() [1/2]

static void LibThread::appendArg ( vector< leftv > &  argv,
leftv  arg 
)
static

Definition at line 738 of file shared.cc.

738 {
739 argv.push_back(arg);
740}

◆ appendArg() [2/2]

static void LibThread::appendArg ( vector< leftv > &  argv,
string s 
)
static

Definition at line 728 of file shared.cc.

728 {
729 if (s.size() == 0) return;
731 if (val->Typ() == NONE) {
732 omFreeBin(val, sleftv_bin);
733 return;
734 }
735 argv.push_back(val);
736}
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1011
const CanonicalForm int s
Definition: facAbsFact.cc:51
EXTERN_VAR omBin sleftv_bin
Definition: ipid.h:145
leftv from_string(std::string &str)
Definition: lintree.cc:854
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define NONE
Definition: tok.h:221

◆ appendArgCopy()

static void LibThread::appendArgCopy ( vector< leftv > &  argv,
leftv  arg 
)
static

Definition at line 742 of file shared.cc.

742 {
744 val->Copy(arg);
745 argv.push_back(val);
746}
void Copy(leftv e)
Definition: subexpr.cc:685
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
sleftv * leftv
Definition: structs.h:57

◆ bindSharedObject()

BOOLEAN LibThread::bindSharedObject ( leftv  result,
leftv  arg 
)

Definition at line 924 of file shared.cc.

924 {
925 if (wrong_num_args("bindSharedObject", arg, 1))
926 return TRUE;
927 if (not_a_uri("bindSharedObject", arg))
928 return TRUE;
929 string uri = str(arg);
931 &global_objects_lock, uri);
932 if (!obj) {
933 WerrorS("bindSharedObject: cannot find object");
934 return TRUE;
935 }
936 result->rtyp = obj->get_type();
937 result->data = new_shared(obj);
938 return FALSE;
939}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
return result
Definition: facAbsBiFact.cc:75
void WerrorS(const char *s)
Definition: feFopen.cc:24
char * str(leftv arg)
Definition: shared.cc:704
int not_a_uri(const char *name, leftv arg)
Definition: shared.cc:687
void * new_shared(SharedObject *obj)
Definition: shared.cc:491
Lock global_objects_lock
Definition: shared.cc:226
int wrong_num_args(const char *name, leftv arg, int n)
Definition: shared.cc:672
SharedObjectTable global_objects
Definition: shared.cc:227
BOOLEAN findSharedObject(leftv result, leftv arg)
Definition: shared.cc:880

◆ cancelJob() [1/2]

void LibThread::cancelJob ( Job job)

Definition at line 2514 of file shared.cc.

2514 {
2515 ThreadPool *pool = job->pool;
2516 if (pool) pool->cancelJob(job);
2517}
void cancelJob(Job *job)
Definition: shared.cc:1948

◆ cancelJob() [2/2]

static BOOLEAN LibThread::cancelJob ( leftv  result,
leftv  arg 
)
static

Definition at line 2595 of file shared.cc.

2595 {
2596 Command cmd("cancelJob", result, arg);
2597 cmd.check_argc(1);
2598 cmd.check_arg(0, type_job, "argument must be a job");
2599 cmd.check_init(0, "job not initialized");
2600 if (cmd.ok()) {
2601 Job *job = cmd.shared_arg<Job>(0);
2602 ThreadPool *pool = job->pool;
2603 if (!pool) {
2604 return cmd.abort("job has not yet been started or scheduled");
2605 }
2606 pool->cancelJob(job);
2607 cmd.no_result();
2608 }
2609 return cmd.status();
2610}
int type_job
Definition: shared.cc:243

◆ chainTrigger()

static BOOLEAN LibThread::chainTrigger ( leftv  result,
leftv  arg 
)
static

Definition at line 2757 of file shared.cc.

2757 {
2758 Command cmd("chainTrigger", result, arg);
2759 cmd.check_argc(2);
2760 cmd.check_arg(0, type_trigger, "first argument must be a trigger");
2761 cmd.check_arg(1, type_trigger, type_job,
2762 "second argument must be a trigger or job");
2763 cmd.check_init(0, "trigger not initialized");
2764 cmd.check_init(1, "trigger/job not initialized");
2765 if (cmd.ok()) {
2766 Trigger *trigger = cmd.shared_arg<Trigger>(0);
2767 Job *job = cmd.shared_arg<Job>(1);
2768 if (trigger->pool != job->pool)
2769 return cmd.abort("arguments use different threadpools");
2770 ThreadPool *pool = trigger->pool;
2771 pool->scheduler->lock.lock();
2772 job->triggers.push_back(trigger);
2773 pool->scheduler->lock.unlock();
2774 }
2775 return cmd.status();
2776}
int type_trigger
Definition: shared.cc:244

◆ closeThreadPool() [1/2]

static BOOLEAN LibThread::closeThreadPool ( leftv  result,
leftv  arg 
)
static

Definition at line 2313 of file shared.cc.

2313 {
2314 Command cmd("closeThreadPool", result, arg);
2315 cmd.check_argc(1, 2);
2316 cmd.check_arg(0, type_threadpool, "first argument must be a threadpool");
2317 cmd.check_init(0, "threadpool not initialized");
2318 if (cmd.nargs() > 1)
2319 cmd.check_arg(1, INT_CMD, "optional argument must be an integer");
2320 if (cmd.ok()) {
2321 ThreadPool *pool = *(ThreadPool **)(cmd.arg(0));
2322 bool wait = cmd.nargs() == 2 ? (cmd.int_arg(1) != 0) : 1;
2323 pool->shutdown(wait);
2324 cmd.no_result();
2325 }
2326 return cmd.status();
2327}
void shutdown(bool wait)
Definition: shared.cc:1929
int type_threadpool
Definition: shared.cc:242
wait
Definition: si_signals.h:51
@ INT_CMD
Definition: tok.h:96

◆ closeThreadPool() [2/2]

void LibThread::closeThreadPool ( ThreadPool pool,
bool  wait 
)

Definition at line 2329 of file shared.cc.

2329 {
2330 pool->shutdown(wait);
2331}

◆ consChannel()

SharedObject * LibThread::consChannel ( )

Definition at line 716 of file shared.cc.

716 {
717 return new SingularChannel();
718}

◆ consList()

SharedObject * LibThread::consList ( )

Definition at line 712 of file shared.cc.

712 {
713 return new TxList();
714}

◆ consRegion()

SharedObject * LibThread::consRegion ( )

Definition at line 724 of file shared.cc.

724 {
725 return new Region();
726}

◆ consSyncVar()

SharedObject * LibThread::consSyncVar ( )

Definition at line 720 of file shared.cc.

720 {
721 return new SingularSyncVar();
722}

◆ consTable()

SharedObject * LibThread::consTable ( )

Definition at line 708 of file shared.cc.

708 {
709 return new TxTable();
710}

◆ createInterpreterThread()

static InterpreterThread * LibThread::createInterpreterThread ( const char **  error)
static

Definition at line 1485 of file shared.cc.

1485 {
1487 if (*error) return NULL;
1488 InterpreterThread *thread = new InterpreterThread(ts);
1489 char buf[10];
1490 sprintf(buf, "%d", ts->index);
1491 string name(buf);
1492 thread->set_name(name);
1493 thread->set_type(type_thread);
1494 return thread;
1495}
void set_name(std::string &name_init)
Definition: shared.cc:165
void set_type(int type_init)
Definition: shared.cc:163
void error(const char *fmt,...)
Definition: emacs.cc:55
char name(const Variable &v)
Definition: factory.h:189
int type_thread
Definition: shared.cc:241
static ThreadState * newThread(void *(*thread_func)(ThreadState *, void *), void *arg, const char **error)
Definition: shared.cc:1436
void * interpreter_thread(ThreadState *ts, void *arg)
Definition: shared.cc:1391
#define NULL
Definition: omList.c:12
int status int void * buf
Definition: si_signals.h:59

◆ createJob() [1/3]

static BOOLEAN LibThread::createJob ( leftv  result,
leftv  arg 
)
static

Definition at line 2449 of file shared.cc.

2449 {
2450 Command cmd("createJob", result, arg);
2451 cmd.check_argc_min(1);
2452 cmd.check_arg(0, STRING_CMD, COMMAND,
2453 "job name must be a string or quote expression");
2454 if (cmd.ok()) {
2455 if (cmd.test_arg(0, STRING_CMD)) {
2456 ProcJob *job = new ProcJob((char *)(cmd.arg(0)));
2457 for (leftv a = arg->next; a != NULL; a = a->next) {
2458 job->args.push_back(LinTree::to_string(a));
2459 }
2460 cmd.set_result(type_job, new_shared(job));
2461 } else {
2462 cmd.check_argc(1);
2463 Job *job = new EvalJob();
2464 job->args.push_back(LinTree::to_string(arg));
2465 cmd.set_result(type_job, new_shared(job));
2466 }
2467 }
2468 return cmd.status();
2469}
@ STRING_CMD
Definition: tok.h:185
#define COMMAND
Definition: tok.h:29

◆ createJob() [2/3]

Job * LibThread::createJob ( void(*)(leftv result, leftv arg)  func)

Definition at line 2471 of file shared.cc.

2471 {
2472 KernelJob *job = new KernelJob(func);
2473 return job;
2474}

◆ createJob() [3/3]

Job * LibThread::createJob ( void(*)(long ndeps, Job **deps)  func)

Definition at line 2476 of file shared.cc.

2476 {
2477 RawKernelJob *job = new RawKernelJob(func);
2478 return job;
2479}

◆ createThread() [1/3]

static BOOLEAN LibThread::createThread ( leftv  result,
leftv  arg 
)
static

Definition at line 1497 of file shared.cc.

1497 {
1498 Command cmd("createThread", result, arg);
1499 cmd.check_argc(0);
1500 const char *error;
1501 if (!have_threads)
1502 cmd.report("thread support not available");
1503 if (!cmd.ok()) return cmd.status();
1505 if (error) {
1506 return cmd.abort(error);
1507 }
1508 cmd.set_result(type_thread, new_shared(thread));
1509 return cmd.status();
1510}
static InterpreterThread * createInterpreterThread(const char **error)
Definition: shared.cc:1485
const int have_threads
Definition: shared.cc:38

◆ createThread() [2/3]

ThreadState * LibThread::createThread ( ThreadFunc  body,
void **  arg,
const char **  error 
)

◆ createThread() [3/3]

ThreadState * LibThread::createThread ( void *(*)(ThreadState *, void *)  thread_func,
void *  arg 
)

Definition at line 1469 of file shared.cc.

1470 {
1471 return newThread(thread_func, arg, NULL);
1472}

◆ createThreadPool() [1/2]

ThreadPool * LibThread::createThreadPool ( int  threads,
int  prioThreads = 0 
)

Definition at line 2218 of file shared.cc.

2218 {
2219 ThreadPool *pool = new ThreadPool((int) nthreads);
2221 for (int i = 0; i <nthreads; i++) {
2222 const char *error;
2223 SchedInfo *info = new SchedInfo();
2224 info->scheduler = pool->scheduler;
2225 acquireShared(pool);
2226 info->job = NULL;
2227 info->num = i;
2229 if (!thread) {
2230 return NULL;
2231 }
2232 pool->addThread(thread);
2233 }
2234 return pool;
2235}
int i
Definition: cfEzgcd.cc:132
void addThread(ThreadState *thread)
Definition: shared.cc:1930
const ExtensionInfo & info
< [in] sqrfree poly
void acquireShared(SharedObject *obj)
Definition: shared.cc:193
int main(int argc, char *argv[])
Definition: omTables.c:165

◆ createThreadPool() [2/2]

static BOOLEAN LibThread::createThreadPool ( leftv  result,
leftv  arg 
)
static

Definition at line 2132 of file shared.cc.

2132 {
2133 long n;
2134 Command cmd("createThreadPool", result, arg);
2135 cmd.check_argc(1, 2);
2136 cmd.check_arg(0, INT_CMD, "first argument must be an integer");
2137 if (cmd.ok()) {
2138 n = (long) cmd.arg(0);
2139 if (n < 0) cmd.report("number of threads must be non-negative");
2140 else if (n >= 256) cmd.report("number of threads too large");
2141 if (!have_threads && n != 0)
2142 cmd.report("in single-threaded mode, number of threads must be zero");
2143 }
2144 if (cmd.ok()) {
2145 ThreadPool *pool = new ThreadPool((int) n);
2147 for (int i = 0; i <n; i++) {
2148 const char *error;
2149 SchedInfo *info = new SchedInfo();
2150 info->scheduler = pool->scheduler;
2151 acquireShared(pool->scheduler);
2152 info->job = NULL;
2153 info->num = i;
2155 if (!thread) {
2156 // TODO: clean up bad pool
2157 return cmd.abort(error);
2158 }
2159 pool->addThread(thread);
2160 }
2161 cmd.set_result(type_threadpool, new_shared(pool));
2162 }
2163 return cmd.status();
2164}

◆ createThreadPoolSet()

static BOOLEAN LibThread::createThreadPoolSet ( leftv  result,
leftv  arg 
)
static

Definition at line 2166 of file shared.cc.

2166 {
2167 Command cmd("createThreadPoolSet", result, arg);
2168 cmd.check_argc(2);
2169 cmd.check_arg(0, INT_CMD, "first argument must be an integer");
2170 cmd.check_arg(1, LIST_CMD, "second argument must be a list of integers");
2171 lists l;
2172 int n;
2173 if (cmd.ok()) {
2174 l = (lists) (cmd.arg(1));
2175 n = lSize(l)+1;
2176 if (n == 0)
2177 return cmd.abort("second argument must not be empty");
2178 for (int i = 0; i < n; i++) {
2179 if (l->m[i].Typ() != INT_CMD)
2180 return cmd.abort("second argument must be a list of integers");
2181 }
2182 }
2183 lists pools = (lists) omAlloc0Bin(slists_bin);
2184 pools->Init(n);
2185 if (cmd.ok()) {
2186 long s = 0;
2187 for (int i = 0; i < n; i++) {
2188 s += (long) (l->m[i].Data());
2189 }
2190 Scheduler *sched = new Scheduler((int)s);
2191 sched->set_maxconcurrency(cmd.int_arg(0));
2192 for (int i = 0; i < n; i++) {
2193 long m = (long) (l->m[i].Data());
2194 ThreadPool *pool = new ThreadPool(sched, (int) m);
2196 for (int j = 0; j < m; j++) {
2197 const char *error;
2198 SchedInfo *info = new SchedInfo();
2199 info->scheduler = pool->scheduler;
2200 acquireShared(pool->scheduler);
2201 info->job = NULL;
2202 info->num = i;
2204 if (!thread) {
2205 // TODO: clean up bad pool
2206 return cmd.abort(error);
2207 }
2208 pool->addThread(thread);
2209 }
2210 pools->m[i].rtyp = type_threadpool;
2211 pools->m[i].data = new_shared(pool);
2212 }
2213 cmd.set_result(LIST_CMD, pools);
2214 }
2215 return cmd.status();
2216}
int l
Definition: cfEzgcd.cc:100
int m
Definition: cfEzgcd.cc:128
void set_maxconcurrency(int n)
Definition: shared.cc:1682
int rtyp
Definition: subexpr.h:91
void * data
Definition: subexpr.h:88
Definition: lists.h:24
sleftv * m
Definition: lists.h:46
INLINE_THIS void Init(int l=0)
int j
Definition: facHensel.cc:110
VAR omBin slists_bin
Definition: lists.cc:23
int lSize(lists L)
Definition: lists.cc:25
slists * lists
Definition: mpr_numeric.h:146
@ LIST_CMD
Definition: tok.h:118

◆ createTrigger()

static BOOLEAN LibThread::createTrigger ( leftv  result,
leftv  arg 
)
static

Definition at line 2692 of file shared.cc.

2692 {
2693 Command cmd("createTrigger", result, arg);
2694 cmd.check_argc_min(1);
2695 int has_pool = cmd.test_arg(0, type_threadpool);
2696 ThreadPool *pool;
2697 if (has_pool) {
2698 cmd.check_init(0, "threadpool not initialized");
2699 pool = cmd.shared_arg<ThreadPool>(0);
2700 } else {
2701 pool = currentThreadPoolRef;
2702 if (!pool)
2703 return cmd.abort("no default threadpool");
2704 }
2705 cmd.check_argc(has_pool + 2);
2706 cmd.check_arg(has_pool + 0, STRING_CMD, "trigger subtype must be a string");
2707 const char *kind = (const char *)(cmd.arg(has_pool + 0));
2708 if (0 == strcmp(kind, "proc")) {
2709 cmd.check_arg(has_pool + 1, STRING_CMD, "proc trigger argument must be a string");
2710 } else {
2711 cmd.check_arg(has_pool + 1, INT_CMD, "trigger argument must be an integer");
2712 }
2713 if (cmd.ok()) {
2714 Trigger *trigger;
2715 long n = (long) (cmd.arg(has_pool + 1));
2716 if (n < 0)
2717 return cmd.abort("trigger argument must be a non-negative integer");
2718 if (0 == strcmp(kind, "acc")) {
2719 trigger = new AccTrigger(n);
2720 } else if (0 == strcmp(kind, "count")) {
2721 trigger = new CountTrigger(n);
2722 } else if (0 == strcmp(kind, "set")) {
2723 trigger = new SetTrigger(n);
2724 } else if (0 == strcmp(kind, "proc")) {
2725 trigger = new ProcTrigger((const char *) cmd.arg(has_pool + 1));
2726 } else {
2727 return cmd.abort("unknown trigger subtype");
2728 }
2729 pool->attachJob(trigger);
2730 cmd.set_result(type_trigger, new_shared(trigger));
2731 }
2732 return cmd.status();
2733}
void attachJob(Job *job)
Definition: shared.cc:1933
STATIC_VAR ThreadPool * currentThreadPoolRef
Definition: shared.cc:1630

◆ currentJob()

BOOLEAN LibThread::currentJob ( leftv  result,
leftv  arg 
)

Definition at line 2898 of file shared.cc.

2898 {
2899 Command cmd("currentJob", result, arg);
2900 cmd.check_argc(0);
2901 Job *job = currentJobRef;
2902 if (job) {
2903 cmd.set_result(type_job, new_shared(job));
2904 } else {
2905 cmd.report("no current job");
2906 }
2907 return cmd.status();
2908}
STATIC_VAR Job * currentJobRef
Definition: shared.cc:1631

◆ currentThreadPool()

BOOLEAN LibThread::currentThreadPool ( leftv  result,
leftv  arg 
)

Definition at line 2334 of file shared.cc.

2334 {
2335 Command cmd("currentThreadPool", result, arg);
2336 cmd.check_argc(0);
2338 if (pool) {
2339 cmd.set_result(type_threadpool, new_shared(pool));
2340 } else {
2341 cmd.report("no current threadpool");
2342 }
2343 return cmd.status();
2344}

◆ decode_shared()

leftv LibThread::decode_shared ( LinTree::LinTree lintree)

Definition at line 1281 of file shared.cc.

1281 {
1282 int type = lintree.get_prev<int>();
1283 SharedObject *obj = lintree.get<SharedObject *>();
1285 result->rtyp = type;
1286 result->data = (void *)new_shared(obj);
1287 return result;
1288}

◆ encode_shared()

void LibThread::encode_shared ( LinTree::LinTree lintree,
leftv  val 
)

Definition at line 1275 of file shared.cc.

1275 {
1276 SharedObject *obj = *(SharedObject **)(val->Data());
1277 acquireShared(obj);
1278 lintree.put(obj);
1279}
void put(T data)
Definition: lintree.h:61
void * Data()
Definition: subexpr.cc:1154

◆ executeProc()

static BOOLEAN LibThread::executeProc ( sleftv result,
const char *  procname,
const vector< leftv > &  argv 
)
static

Definition at line 749 of file shared.cc.

751{
752 leftv procnode = (leftv) omAlloc0Bin(sleftv_bin);
753 procnode->name = omStrDup(procname);
754 procnode->req_packhdl = basePack;
755 int error = procnode->Eval();
756 if (error) {
757 Werror("procedure \"%s\" not found", procname);
758 omFreeBin(procnode, sleftv_bin);
759 return TRUE;
760 }
761 memset(&result, 0, sizeof(result));
762 leftv *tail = &procnode->next;
763 for (unsigned i = 0; i < argv.size(); i++) {
764 *tail = argv[i];
765 tail = &(*tail)->next;
766 }
767 *tail = NULL;
768 error = iiExprArithM(&result, procnode, '(');
769 procnode->CleanUp();
770 omFreeBin(procnode, sleftv_bin);
771 if (error) {
772 Werror("procedure call of \"%s\" failed", procname);
773 return TRUE;
774 }
775 return FALSE;
776}
const char * name
Definition: subexpr.h:87
package req_packhdl
Definition: subexpr.h:106
int Eval()
Definition: subexpr.cc:1908
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:9416
VAR package basePack
Definition: ipid.cc:58
#define omStrDup(s)
Definition: omAllocDecl.h:263
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ findSharedObject() [1/2]

BOOLEAN LibThread::findSharedObject ( leftv  result,
leftv  arg 
)

Definition at line 880 of file shared.cc.

880 {
881 if (wrong_num_args("findSharedObject", arg, 1))
882 return TRUE;
883 if (not_a_uri("findSharedObject", arg))
884 return TRUE;
885 string uri = str(arg);
887 &global_objects_lock, uri);
888 result->rtyp = INT_CMD;
889 result->data = (char *)(long)(obj != NULL);
890 return FALSE;
891}

◆ findSharedObject() [2/2]

SharedObject * LibThread::findSharedObject ( SharedObjectTable table,
Lock lock,
string name 
)

Definition at line 271 of file shared.cc.

273{
274 int was_locked = lock->is_locked();
276 if (!was_locked)
277 lock->lock();
278 if (table.count(name)) {
279 result = table[name];
280 }
281 if (!was_locked)
282 lock->unlock();
283 return result;
284}
bool is_locked()
Definition: thread.h:68

◆ free_space()

void LibThread::free_space ( size_t  n,
char *  p 
)

◆ getCurrentJob()

Job * LibThread::getCurrentJob ( )

Definition at line 2519 of file shared.cc.

2519 {
2520 return currentJobRef;
2521}

◆ getCurrentThreadPool()

ThreadPool * LibThread::getCurrentThreadPool ( )

Definition at line 2245 of file shared.cc.

2245 {
2246 return currentThreadPoolRef;
2247}

◆ getJobCancelled() [1/2]

bool LibThread::getJobCancelled ( )

Definition at line 2645 of file shared.cc.

2645 {
2647}
bool getJobCancelled()
Definition: shared.cc:2645

◆ getJobCancelled() [2/2]

bool LibThread::getJobCancelled ( Job job)

Definition at line 2637 of file shared.cc.

2637 {
2638 ThreadPool *pool = job->pool;
2639 if (pool) pool->scheduler->lock.lock();
2640 bool result = job->cancelled;
2641 if (pool) pool->scheduler->lock.unlock();
2642 return result;
2643}
bool cancelled
Definition: shared.cc:1565

◆ getJobData()

void * LibThread::getJobData ( Job job)

Definition at line 2657 of file shared.cc.

2657 {
2658 ThreadPool *pool = job->pool;
2659 if (pool) pool->scheduler->lock.lock();
2660 void *result = job->data;
2661 if (pool) pool->scheduler->lock.unlock();
2662 return result;
2663}
void * data
Definition: shared.cc:1560

◆ getJobName() [1/2]

const char * LibThread::getJobName ( )

◆ getJobName() [2/2]

const char * LibThread::getJobName ( Job job)

Definition at line 2683 of file shared.cc.

2683 {
2684 // TODO
2685 return "";
2686}

◆ getJobResult()

leftv LibThread::getJobResult ( Job job)

Definition at line 2675 of file shared.cc.

2675 {
2676 ThreadPool *pool = job->pool;
2677 if (pool) pool->scheduler->lock.lock();
2679 if (pool) pool->scheduler->lock.unlock();
2680 return result;
2681}
string result
Definition: shared.cc:1559

◆ getList()

BOOLEAN LibThread::getList ( leftv  result,
leftv  arg 
)

Definition at line 1028 of file shared.cc.

1028 {
1029 if (wrong_num_args("getList", arg, 2))
1030 return TRUE;
1031 if (arg->Typ() != type_atomic_list && arg->Typ() != type_shared_list) {
1032 WerrorS("getList: not a valid list (atomic or shared)");
1033 return TRUE;
1034 }
1035 if (arg->next->Typ() != INT_CMD) {
1036 WerrorS("getList: index must be an integer");
1037 return TRUE;
1038 }
1039 TxList *list = *(TxList **) arg->Data();
1040 if (!list) {
1041 WerrorS("getList: list has not been initialized");
1042 return TRUE;
1043 }
1044 long index = (long)(arg->next->Data());
1045 string value;
1046 int success = list->get(index, value);
1047 if (success < 0) {
1048 WerrorS("getList: region not acquired");
1049 return TRUE;
1050 }
1051 if (success == 0) {
1052 WerrorS("getList: no value at position");
1053 return TRUE;
1054 }
1055 leftv tmp = LinTree::from_string(value);
1056 result->rtyp = tmp->Typ();
1057 result->data = tmp->Data();
1058 return FALSE;
1059}
int get(size_t index, string &value)
Definition: shared.cc:377
int type_atomic_list
Definition: shared.cc:239
int type_shared_list
Definition: shared.cc:240
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592

◆ getSharedName()

BOOLEAN LibThread::getSharedName ( leftv  result,
leftv  arg 
)

Definition at line 3056 of file shared.cc.

3056 {
3057 Command cmd("getSharedName", result, arg);
3058 cmd.check_argc(1);
3059 int type = cmd.argtype(0);
3060 cmd.check_init(0, "first argument is not initialized");
3061 if (type != type_job && type != type_trigger && type != type_threadpool) {
3062 cmd.report("first argument must be a job, trigger, or threadpool");
3063 }
3064 if (cmd.ok()) {
3065 SharedObject *obj = cmd.shared_arg<SharedObject>(0);
3066 name_lock.lock();
3067 cmd.set_result(obj->get_name().c_str());
3068 name_lock.unlock();
3069 }
3070 return cmd.status();
3071}
std::string & get_name()
Definition: shared.cc:169
Lock name_lock(true)

◆ getTable()

BOOLEAN LibThread::getTable ( leftv  result,
leftv  arg 
)

Definition at line 941 of file shared.cc.

941 {
942 if (wrong_num_args("getTable", arg, 2))
943 return TRUE;
944 if (arg->Typ() != type_atomic_table && arg->Typ() != type_shared_table) {
945 WerrorS("getTable: not a valid table");
946 return TRUE;
947 }
948 if (arg->next->Typ() != STRING_CMD) {
949 WerrorS("getTable: not a valid table key");
950 return TRUE;
951 }
952 TxTable *table = *(TxTable **) arg->Data();
953 if (!table) {
954 WerrorS("getTable: table has not been initialized");
955 return TRUE;
956 }
957 string key = (char *)(arg->next->Data());
958 string value;
959 int success = table->get(key, value);
960 if (success < 0) {
961 WerrorS("getTable: region not acquired");
962 return TRUE;
963 }
964 if (success == 0) {
965 WerrorS("getTable: key not found");
966 return TRUE;
967 }
968 leftv tmp = LinTree::from_string(value);
969 result->rtyp = tmp->Typ();
970 result->data = tmp->Data();
971 return FALSE;
972}
int get(string &key, string &value)
Definition: shared.cc:338
int type_atomic_table
Definition: shared.cc:237
int type_shared_table
Definition: shared.cc:238

◆ getThreadPoolConcurrency()

static BOOLEAN LibThread::getThreadPoolConcurrency ( leftv  result,
leftv  arg 
)
static

Definition at line 2281 of file shared.cc.

2281 {
2282 Command cmd("getThreadPoolConcurrency", result, arg);
2283 cmd.check_argc(1);
2284 cmd.check_arg(0, type_threadpool, "argument must be a threadpool");
2285 cmd.check_init(0, "threadpool not initialized");
2286 if (cmd.ok()) {
2287 ThreadPool *pool = cmd.shared_arg<ThreadPool>(0);
2288 Scheduler *sched = pool->scheduler;
2289 sched->lock.lock();
2290 cmd.set_result(INT_CMD, sched->get_maxconcurrency());
2291 sched->lock.unlock();
2292 }
2293 return cmd.status();
2294}

◆ getThreadPoolWorkers()

static BOOLEAN LibThread::getThreadPoolWorkers ( leftv  result,
leftv  arg 
)
static

Definition at line 2249 of file shared.cc.

2249 {
2250 Command cmd("getThreadPoolWorkers", result, arg);
2251 cmd.check_argc(1);
2252 cmd.check_arg(0, type_threadpool, "argument must be a threadpool");
2253 cmd.check_init(0, "threadpool not initialized");
2254 int r = 0;
2255 if (cmd.ok()) {
2256 ThreadPool *pool = cmd.shared_arg<ThreadPool>(0);
2257 Scheduler *sched = pool->scheduler;
2258 sched->lock.lock();
2259 r = sched->threadpool_size(pool);
2260 sched->lock.unlock();
2261 cmd.set_result(INT_CMD, r);
2262 }
2263 return cmd.status();
2264}

◆ installShared()

void LibThread::installShared ( int  type)

Definition at line 1302 of file shared.cc.

1302 {
1304}
void ref_shared(LinTree::LinTree &lintree, int by)
Definition: shared.cc:1290
void encode_shared(LinTree::LinTree &lintree, leftv val)
Definition: shared.cc:1275
leftv decode_shared(LinTree::LinTree &lintree)
Definition: shared.cc:1281
void install(int typ, LinTreeEncodeFunc enc, LinTreeDecodeFunc dec, LinTreeRefFunc ref)
Definition: lintree.cc:51

◆ inTable()

BOOLEAN LibThread::inTable ( leftv  result,
leftv  arg 
)

Definition at line 974 of file shared.cc.

974 {
975 if (wrong_num_args("inTable", arg, 2))
976 return TRUE;
977 if (arg->Typ() != type_atomic_table && arg->Typ() != type_shared_table) {
978 WerrorS("inTable: not a valid table");
979 return TRUE;
980 }
981 if (arg->next->Typ() != STRING_CMD) {
982 WerrorS("inTable: not a valid table key");
983 return TRUE;
984 }
985 TxTable *table = *(TxTable **) arg->Data();
986 if (!table) {
987 WerrorS("inTable: table has not been initialized");
988 return TRUE;
989 }
990 string key = (char *)(arg->next->Data());
991 int success = table->check(key);
992 if (success < 0) {
993 WerrorS("inTable: region not acquired");
994 return TRUE;
995 }
996 result->rtyp = INT_CMD;
997 result->data = (char *)(long)(success);
998 return FALSE;
999}
int check(string &key)
Definition: shared.cc:348

◆ interpreter_thread()

void * LibThread::interpreter_thread ( ThreadState ts,
void *  arg 
)

Definition at line 1391 of file shared.cc.

1391 {
1392 ts->lock.lock();
1393 for (;;) {
1394 bool eval = false;
1395 while (ts->to_thread.empty())
1396 ts->to_cond.wait();
1397 /* TODO */
1398 string expr = ts->to_thread.front();
1399 switch (expr[0]) {
1400 case '\0': case 'q':
1401 ts->lock.unlock();
1402 return NULL;
1403 case 'x':
1404 eval = false;
1405 break;
1406 case 'e':
1407 eval = true;
1408 break;
1409 }
1410 ts->to_thread.pop();
1411 expr = ts->to_thread.front();
1412 /* this will implicitly eval commands */
1413 leftv val = LinTree::from_string(expr);
1414 expr = LinTree::to_string(val);
1415 ts->to_thread.pop();
1416 if (eval)
1417 ts->from_thread.push(expr);
1418 ts->from_cond.signal();
1419 }
1420 ts->lock.unlock();
1421 return NULL;
1422}
void wait()
Definition: thread.h:88
void signal()
Definition: thread.h:97
ConditionVariable to_cond
Definition: shared.cc:1346
queue< string > from_thread
Definition: shared.cc:1349
ConditionVariable from_cond
Definition: shared.cc:1347
queue< string > to_thread
Definition: shared.cc:1348
CFList & eval
Definition: facFactorize.cc:47

◆ jobCancelled()

static BOOLEAN LibThread::jobCancelled ( leftv  result,
leftv  arg 
)
static

Definition at line 2612 of file shared.cc.

2612 {
2613 Job *job;
2614 Command cmd("jobCancelled", result, arg);
2615 cmd.check_argc(0, 1);
2616 if (cmd.nargs() == 1) {
2617 cmd.check_arg(0, type_job, "argument must be a job");
2618 cmd.check_init(0, "job not initialized");
2619 job = cmd.shared_arg<Job>(0);
2620 } else {
2621 job = currentJobRef;
2622 if (!job)
2623 cmd.report("no current job");
2624 }
2625 if (cmd.ok()) {
2626 ThreadPool *pool = job->pool;
2627 if (!pool) {
2628 return cmd.abort("job has not yet been started or scheduled");
2629 }
2630 pool->scheduler->lock.lock();
2631 cmd.set_result((long) job->cancelled);
2632 pool->scheduler->lock.unlock();
2633 }
2634 return cmd.status();
2635}

◆ joinInterpreterThread()

static bool LibThread::joinInterpreterThread ( InterpreterThread thread)
static

Definition at line 1512 of file shared.cc.

1512 {
1513 ThreadState *ts = thread->getThreadState();
1514 if (ts && ts->parent != pthread_self()) {
1515 return false;
1516 }
1517 ts->lock.lock();
1518 string quit("q");
1519 ts->to_thread.push(quit);
1520 ts->to_cond.signal();
1521 ts->lock.unlock();
1522 pthread_join(ts->id, NULL);
1523 thread_lock.lock();
1524 ts->running = false;
1525 ts->active = false;
1526 thread->clearThreadState();
1528 return true;
1529}
ThreadState * getThreadState()
Definition: shared.cc:1430
Lock thread_lock
Definition: shared.cc:1364

◆ joinThread() [1/2]

static BOOLEAN LibThread::joinThread ( leftv  result,
leftv  arg 
)
static

Definition at line 1531 of file shared.cc.

1531 {
1532 if (wrong_num_args("joinThread", arg, 1))
1533 return TRUE;
1534 if (arg->Typ() != type_thread) {
1535 WerrorS("joinThread: argument is not a thread");
1536 return TRUE;
1537 }
1538 InterpreterThread *thread = *(InterpreterThread **)arg->Data();
1539 if (!joinInterpreterThread(thread)) {
1540 WerrorS("joinThread: can only be called from parent thread");
1541 return TRUE;
1542 }
1543 return FALSE;
1544}
static bool joinInterpreterThread(InterpreterThread *thread)
Definition: shared.cc:1512

◆ joinThread() [2/2]

void * LibThread::joinThread ( ThreadState ts)

Definition at line 1474 of file shared.cc.

1474 {
1475 void *result;
1476 pthread_join(ts->id, NULL);
1477 result = ts->result;
1478 thread_lock.lock();
1479 ts->running = false;
1480 ts->active = false;
1482 return result;
1483}

◆ lockRegion()

BOOLEAN LibThread::lockRegion ( leftv  result,
leftv  arg 
)

Definition at line 1088 of file shared.cc.

1088 {
1089 if (wrong_num_args("lockRegion", arg, 1))
1090 return TRUE;
1091 if (not_a_region("lockRegion", arg))
1092 return TRUE;
1093 Region *region = *(Region **)arg->Data();
1094 if (region->is_locked()) {
1095 WerrorS("lockRegion: region is already locked");
1096 return TRUE;
1097 }
1098 region->lock();
1099 result->rtyp = NONE;
1100 return FALSE;
1101}
int not_a_region(const char *name, leftv arg)
Definition: shared.cc:695

◆ mainThread()

BOOLEAN LibThread::mainThread ( leftv  result,
leftv  arg 
)

Definition at line 2919 of file shared.cc.

2919 {
2920 if (wrong_num_args("mainThread", arg, 0))
2921 return TRUE;
2922 result->rtyp = INT_CMD;
2923 result->data = (char *)(long)(thread_id == 0L);
2924 return FALSE;
2925}
VAR long thread_id
Definition: shared.cc:230

◆ makeAtomicList()

BOOLEAN LibThread::makeAtomicList ( leftv  result,
leftv  arg 
)

Definition at line 792 of file shared.cc.

792 {
793 if (wrong_num_args("makeAtomicList", arg, 1))
794 return TRUE;
795 if (not_a_uri("makeAtomicList", arg))
796 return TRUE;
797 string uri = str(arg);
800 ((TxList *) obj)->set_region(NULL);
801 result->rtyp = type_atomic_list;
802 result->data = new_shared(obj);
803 return FALSE;
804}
SharedObject * makeSharedObject(SharedObjectTable &table, Lock *lock, int type, string &name, SharedConstructor scons)
Definition: shared.cc:249
SharedObject * consList()
Definition: shared.cc:712

◆ makeAtomicTable()

BOOLEAN LibThread::makeAtomicTable ( leftv  result,
leftv  arg 
)

Definition at line 778 of file shared.cc.

778 {
779 if (wrong_num_args("makeAtomicTable", arg, 1))
780 return TRUE;
781 if (not_a_uri("makeAtomicTable", arg))
782 return TRUE;
783 string uri = str(arg);
786 ((TxTable *) obj)->set_region(NULL);
788 result->data = new_shared(obj);
789 return FALSE;
790}
SharedObject * consTable()
Definition: shared.cc:708

◆ makeChannel()

BOOLEAN LibThread::makeChannel ( leftv  result,
leftv  arg 
)

Definition at line 841 of file shared.cc.

841 {
842 if (wrong_num_args("makeChannel", arg, 1))
843 return TRUE;
844 if (not_a_uri("makeChannel", arg))
845 return TRUE;
846 string uri = str(arg);
849 result->rtyp = type_channel;
850 result->data = new_shared(obj);
851 return FALSE;
852}
SharedObject * consChannel()
Definition: shared.cc:716
int type_channel
Definition: shared.cc:235

◆ makeRegion()

BOOLEAN LibThread::makeRegion ( leftv  result,
leftv  arg 
)

Definition at line 867 of file shared.cc.

867 {
868 if (wrong_num_args("makeRegion", arg, 1))
869 return TRUE;
870 if (not_a_uri("makeRegion", arg))
871 return TRUE;
872 string uri = str(arg);
875 result->rtyp = type_region;
876 result->data = new_shared(obj);
877 return FALSE;
878}
int type_region
Definition: shared.cc:233
SharedObject * consRegion()
Definition: shared.cc:724

◆ makeRegionlockType()

void LibThread::makeRegionlockType ( int &  type,
const char *  name 
)

Definition at line 1321 of file shared.cc.

1321 {
1322 if (type != 0) return;
1323 blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
1324 b->blackbox_Init = shared_init;
1325 b->blackbox_destroy = rlock_destroy;
1326 b->blackbox_Copy = shared_copy;
1327 b->blackbox_String = shared_string;
1328 b->blackbox_Assign = rlock_assign;
1329 b->blackbox_CheckAssign = shared_check_assign;
1330 type = setBlackboxStuff(b, name);
1331 installShared(type);
1332}
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:142
CanonicalForm b
Definition: cfModGcd.cc:4103
BOOLEAN shared_check_assign(blackbox *b, leftv l, leftv r)
Definition: shared.cc:573
void * shared_init(blackbox *b)
Definition: shared.cc:487
void * shared_copy(blackbox *b, void *d)
Definition: shared.cc:515
char * shared_string(blackbox *b, void *d)
Definition: shared.cc:595
BOOLEAN rlock_assign(leftv l, leftv r)
Definition: shared.cc:549
void rlock_destroy(blackbox *b, void *d)
Definition: shared.cc:506
void installShared(int type)
Definition: shared.cc:1302
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ makeSharedList()

BOOLEAN LibThread::makeSharedList ( leftv  result,
leftv  arg 
)

Definition at line 824 of file shared.cc.

824 {
825 if (wrong_num_args("makeSharedList", arg, 2))
826 return TRUE;
827 if (not_a_region("makeSharedList", arg))
828 return TRUE;
829 if (not_a_uri("makeSharedList", arg->next))
830 return TRUE;
831 Region *region = *(Region **) arg->Data();
832 string s = str(arg->next);
834 region->get_lock(), type_shared_list, s, consList);
835 ((TxList *) obj)->set_region(region);
836 result->rtyp = type_shared_list;
837 result->data = new_shared(obj);
838 return FALSE;
839}
SharedObjectTable objects
Definition: shared.cc:209
Lock * get_lock()
Definition: shared.cc:212

◆ makeSharedObject()

SharedObject * LibThread::makeSharedObject ( SharedObjectTable table,
Lock lock,
int  type,
string name,
SharedConstructor  scons 
)

Definition at line 249 of file shared.cc.

251{
252 int was_locked = lock->is_locked();
254 if (!was_locked)
255 lock->lock();
256 if (table.count(name)) {
257 result = table[name];
258 if (result->get_type() != type)
259 result = NULL;
260 } else {
261 result = scons();
262 result->set_type(type);
263 result->set_name(name);
264 table.insert(pair<string,SharedObject *>(name, result));
265 }
266 if (!was_locked)
267 lock->unlock();
268 return result;
269}

◆ makeSharedTable()

BOOLEAN LibThread::makeSharedTable ( leftv  result,
leftv  arg 
)

Definition at line 806 of file shared.cc.

806 {
807 if (wrong_num_args("makeSharedTable", arg, 2))
808 return TRUE;
809 if (not_a_region("makeSharedTable", arg))
810 return TRUE;
811 if (not_a_uri("makeSharedTable", arg->next))
812 return TRUE;
813 Region *region = *(Region **) arg->Data();
814 fflush(stdout);
815 string s = str(arg->next);
818 ((TxTable *) obj)->set_region(region);
820 result->data = new_shared(obj);
821 return FALSE;
822}

◆ makeSharedType()

void LibThread::makeSharedType ( int &  type,
const char *  name 
)

Definition at line 1306 of file shared.cc.

1306 {
1307 if (type != 0) return;
1308 blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
1309 b->blackbox_Init = shared_init;
1310 b->blackbox_destroy = shared_destroy;
1311 b->blackbox_Copy = shared_copy;
1312 b->blackbox_String = shared_string;
1313 b->blackbox_Assign = shared_assign;
1314 b->blackbox_CheckAssign = shared_check_assign;
1315 // b->blackbox_Op2 = shared_op2;
1316 // b->blackbox_Op3 = shared_op3;
1317 type = setBlackboxStuff(b, name);
1318 installShared(type);
1319}
BOOLEAN shared_assign(leftv l, leftv r)
Definition: shared.cc:524
void shared_destroy(blackbox *b, void *d)
Definition: shared.cc:498

◆ makeSyncVar()

BOOLEAN LibThread::makeSyncVar ( leftv  result,
leftv  arg 
)

Definition at line 854 of file shared.cc.

854 {
855 if (wrong_num_args("makeSyncVar", arg, 1))
856 return TRUE;
857 if (not_a_uri("makeSyncVar", arg))
858 return TRUE;
859 string uri = str(arg);
862 result->rtyp = type_syncvar;
863 result->data = new_shared(obj);
864 return FALSE;
865}
SharedObject * consSyncVar()
Definition: shared.cc:720
int type_syncvar
Definition: shared.cc:236

◆ new_shared()

void * LibThread::new_shared ( SharedObject obj)

Definition at line 491 of file shared.cc.

491 {
492 acquireShared(obj);
493 void *result = omAlloc0(sizeof(SharedObject *));
494 *(SharedObject **)result = obj;
495 return result;
496}

◆ newThread()

static ThreadState * LibThread::newThread ( void *(*)(ThreadState *, void *)  thread_func,
void *  arg,
const char **  error 
)
static

Definition at line 1436 of file shared.cc.

1437 {
1438 ThreadState *ts = NULL;
1439 if (error) *error = NULL;
1440 thread_lock.lock();
1441 for (int i=0; i<MAX_THREADS; i++) {
1442 if (!thread_state[i].active) {
1443 ts = thread_state + i;
1444 ts->index = i;
1445 ts->parent = pthread_self();
1446 ts->active = true;
1447 ts->running = true;
1448 ts->to_thread = queue<string>();
1449 ts->from_thread = queue<string>();
1450 ts->thread_func = thread_func;
1451 ts->arg = arg;
1452 ts->result = NULL;
1453 if (pthread_create(&ts->id, NULL, thread_main, ts)<0) {
1454 if (error)
1455 *error = "createThread: internal error: failed to create thread";
1456 goto fail;
1457 }
1458 goto exit;
1459 }
1460 }
1461 if (error) *error = "createThread: too many threads";
1462 fail:
1463 ts = NULL;
1464 exit:
1466 return ts;
1467}
void *(* thread_func)(ThreadState *, void *)
Definition: shared.cc:1341
ThreadState * thread_state
Definition: shared.cc:1366
void * thread_main(void *arg)
Definition: shared.cc:1385
#define MAX_THREADS
Definition: shared.cc:1334

◆ not_a_region()

int LibThread::not_a_region ( const char *  name,
leftv  arg 
)

Definition at line 695 of file shared.cc.

695 {
696 if (arg->Typ() != type_region || !arg->Data()) {
697 report("%s: not a region", name);
698 return TRUE;
699 }
700 return FALSE;
701}
void report(const char *fmt, const char *name)
Definition: shared.cc:666

◆ not_a_uri()

int LibThread::not_a_uri ( const char *  name,
leftv  arg 
)

Definition at line 687 of file shared.cc.

687 {
688 if (arg->Typ() != STRING_CMD) {
689 report("%s: not a valid URI", name);
690 return TRUE;
691 }
692 return FALSE;
693}

◆ putList()

BOOLEAN LibThread::putList ( leftv  result,
leftv  arg 
)

Definition at line 1061 of file shared.cc.

1061 {
1062 if (wrong_num_args("putList", arg, 3))
1063 return TRUE;
1064 if (arg->Typ() != type_atomic_list && arg->Typ() != type_shared_list) {
1065 WerrorS("putList: not a valid list (shared or atomic)");
1066 return TRUE;
1067 }
1068 if (arg->next->Typ() != INT_CMD) {
1069 WerrorS("putList: index must be an integer");
1070 return TRUE;
1071 }
1072 TxList *list = *(TxList **) arg->Data();
1073 if (!list) {
1074 WerrorS("putList: list has not been initialized");
1075 return TRUE;
1076 }
1077 long index = (long)(arg->next->Data());
1078 string value = LinTree::to_string(arg->next->next);
1079 int success = list->put(index, value);
1080 if (success < 0) {
1081 WerrorS("putList: region not acquired");
1082 return TRUE;
1083 }
1084 result->rtyp = NONE;
1085 return FALSE;
1086}
int put(size_t index, string &value)
Definition: shared.cc:363

◆ putTable()

BOOLEAN LibThread::putTable ( leftv  result,
leftv  arg 
)

Definition at line 1001 of file shared.cc.

1001 {
1002 if (wrong_num_args("putTable", arg, 3))
1003 return TRUE;
1004 if (arg->Typ() != type_atomic_table && arg->Typ() != type_shared_table) {
1005 WerrorS("putTable: not a valid table");
1006 return TRUE;
1007 }
1008 if (arg->next->Typ() != STRING_CMD) {
1009 WerrorS("putTable: not a valid table key");
1010 return TRUE;
1011 }
1012 TxTable *table = *(TxTable **) arg->Data();
1013 if (!table) {
1014 WerrorS("putTable: table has not been initialized");
1015 return TRUE;
1016 }
1017 string key = (char *)(arg->next->Data());
1018 string value = LinTree::to_string(arg->next->next);
1019 int success = table->put(key, value);
1020 if (success < 0) {
1021 WerrorS("putTable: region not acquired");
1022 return TRUE;
1023 }
1024 result->rtyp = NONE;
1025 return FALSE;
1026}
int put(string &key, string &value)
Definition: shared.cc:326

◆ readSyncVar()

BOOLEAN LibThread::readSyncVar ( leftv  result,
leftv  arg 
)

Definition at line 1238 of file shared.cc.

1238 {
1239 if (wrong_num_args("readSyncVar", arg, 1))
1240 return TRUE;
1241 if (arg->Typ() != type_syncvar) {
1242 WerrorS("readSyncVar: argument is not a syncvar");
1243 return TRUE;
1244 }
1245 SingularSyncVar *syncvar = *(SingularSyncVar **)arg->Data();
1246 if (!syncvar) {
1247 WerrorS("readSyncVar: syncvar has not been initialized");
1248 return TRUE;
1249 }
1250 string item = syncvar->read();
1251 leftv val = LinTree::from_string(item);
1252 result->rtyp = val->Typ();
1253 result->data = val->Data();
1254 return FALSE;
1255}

◆ receiveChannel()

BOOLEAN LibThread::receiveChannel ( leftv  result,
leftv  arg 
)

Definition at line 1152 of file shared.cc.

1152 {
1153 if (wrong_num_args("receiveChannel", arg, 1))
1154 return TRUE;
1155 if (arg->Typ() != type_channel) {
1156 WerrorS("receiveChannel: argument is not a channel");
1157 return TRUE;
1158 }
1159 SingularChannel *channel = *(SingularChannel **)arg->Data();
1160 if (!channel) {
1161 WerrorS("receiveChannel: channel has not been initialized");
1162 return TRUE;
1163 }
1164 string item = channel->receive();
1165 leftv val = LinTree::from_string(item);
1166 result->rtyp = val->Typ();
1167 result->data = val->Data();
1168 return FALSE;
1169}

◆ ref_shared()

void LibThread::ref_shared ( LinTree::LinTree lintree,
int  by 
)

Definition at line 1290 of file shared.cc.

1290 {
1291 SharedObject *obj = lintree.get<SharedObject *>();
1292 while (by > 0) {
1293 obj->incref();
1294 by--;
1295 }
1296 while (by < 0) {
1297 obj->decref();
1298 by++;
1299 }
1300}

◆ regionLock()

BOOLEAN LibThread::regionLock ( leftv  result,
leftv  arg 
)

Definition at line 1103 of file shared.cc.

1103 {
1104 if (wrong_num_args("lockRegion", arg, 1))
1105 return TRUE;
1106 if (not_a_region("lockRegion", arg))
1107 return TRUE;
1108 Region *region = *(Region **)arg->Data();
1109 if (region->is_locked()) {
1110 WerrorS("lockRegion: region is already locked");
1111 return TRUE;
1112 }
1113 region->lock();
1114 result->rtyp = type_regionlock;
1115 result->data = new_shared(region);
1116 return FALSE;
1117}
int type_regionlock
Definition: shared.cc:234

◆ release() [1/2]

void LibThread::release ( Job job)

◆ release() [2/2]

void LibThread::release ( ThreadPool pool)

Definition at line 2237 of file shared.cc.

2237 {
2238 releaseShared(pool);
2239}
void releaseShared(SharedObject *obj)
Definition: shared.cc:197

◆ releaseShared()

void LibThread::releaseShared ( SharedObject obj)

Definition at line 197 of file shared.cc.

197 {
198 if (obj->decref() == 0) {
199 // delete obj;
200 }
201}

◆ report()

void LibThread::report ( const char *  fmt,
const char *  name 
)

Definition at line 666 of file shared.cc.

666 {
667 char buf[80];
668 sprintf(buf, fmt, name);
669 WerrorS(buf);
670}

◆ retain() [1/2]

void LibThread::retain ( Job job)

◆ retain() [2/2]

void LibThread::retain ( ThreadPool pool)

Definition at line 2241 of file shared.cc.

2241 {
2242 acquireShared(pool);
2243}

◆ rlock_assign()

BOOLEAN LibThread::rlock_assign ( leftv  l,
leftv  r 
)

Definition at line 549 of file shared.cc.

549 {
550 if (r->Typ() == l->Typ()) {
551 if (l->rtyp == IDHDL) {
552 omFree(IDDATA((idhdl)l->data));
553 IDDATA((idhdl)l->data) = (char*)shared_copy(NULL,r->Data());
554 } else {
555 leftv ll=l->LData();
556 if (ll==NULL)
557 {
558 return TRUE; // out of array bounds or similiar
559 }
560 rlock_destroy(NULL, ll->data);
561 omFree(ll->data);
562 ll->data = shared_copy(NULL,r->Data());
563 }
564 } else {
565 Werror("assign %s(%d) = %s(%d)",
566 Tok2Cmdname(l->Typ()),l->Typ(),Tok2Cmdname(r->Typ()),r->Typ());
567 return TRUE;
568 }
569 return FALSE;
570}
Definition: idrec.h:35
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
#define IDDATA(a)
Definition: ipid.h:126
#define omFree(addr)
Definition: omAllocDecl.h:261
#define IDHDL
Definition: tok.h:31

◆ rlock_destroy()

void LibThread::rlock_destroy ( blackbox *  b,
void *  d 
)

Definition at line 506 of file shared.cc.

506 {
507 SharedObject *obj = *(SharedObject **)d;
508 ((Region *) obj)->unlock();
509 if (obj) {
511 *(SharedObject **)d = NULL;
512 }
513}

◆ rlock_string()

char * LibThread::rlock_string ( blackbox *  b,
void *  d 
)

Definition at line 657 of file shared.cc.

657 {
658 char buf[80];
659 SharedObject *obj = *(SharedObject **)d;
660 if (!obj)
661 return omStrDup("<uninitialized region lock>");
662 sprintf(buf, "<region lock \"%.40s\">", obj->get_name().c_str());
663 return omStrDup(buf);
664}

◆ scheduleJob()

static BOOLEAN LibThread::scheduleJob ( leftv  result,
leftv  arg 
)
static

Definition at line 2794 of file shared.cc.

2794 {
2795 vector<Job *> jobs;
2796 vector<Job *> deps;
2797 Command cmd("scheduleJob", result, arg);
2798 cmd.check_argc_min(1);
2799 int has_pool = cmd.test_arg(0, type_threadpool);
2800 if (has_pool) {
2801 cmd.check_arg(0, type_threadpool, "first argument must be a threadpool");
2802 cmd.check_init(0, "threadpool not initialized");
2803 }
2804 cmd.check_argc_min(has_pool+1);
2805 int has_prio = cmd.test_arg(has_pool, INT_CMD);
2806 ThreadPool *pool;
2807 if (has_pool)
2808 pool = cmd.shared_arg<ThreadPool>(0);
2809 else {
2811 return cmd.abort("no current threadpool defined");
2812 pool = currentThreadPoolRef;
2813 }
2814 long prio = has_prio ? (long) cmd.arg(has_pool) : 0L;
2815 int first_arg = has_pool + has_prio;
2816 if (cmd.test_arg(first_arg, type_job)) {
2817 jobs.push_back(*(Job **)(cmd.arg(first_arg)));
2818 } else if (cmd.test_arg(first_arg, STRING_CMD)) {
2819 jobs.push_back(new ProcJob((char *)(cmd.arg(first_arg))));
2820 } else if (cmd.test_arg(first_arg, LIST_CMD)) {
2821 lists l = (lists) (cmd.arg(first_arg));
2822 int n = lSize(l);
2823 for (int i = 0; i < n; i++) {
2824 if (l->m[i].Typ() != type_job)
2825 return cmd.abort("job argument must be a job, string, or list of jobs");
2826 }
2827 for (int i = 0; i < n; i++) {
2828 Job *job = *(Job **) (l->m[i].Data());
2829 if (!job)
2830 return cmd.abort("job not initialized");
2831 jobs.push_back(job);
2832 }
2833 } else {
2834 return cmd.abort("job argument must be a job, string, or list of jobs");
2835 }
2836 bool error = false;
2837 leftv a = arg->next;
2838 if (has_pool) a = a->next;
2839 if (has_prio) a = a->next;
2840 for (; !error && a; a = a->next) {
2841 if (a->Typ() == type_job || a->Typ() == type_trigger) {
2842 deps.push_back(*(Job **)(a->Data()));
2843 } else if (a->Typ() == LIST_CMD) {
2844 lists l = (lists) a->Data();
2845 int n = lSize(l);
2846 for (int i = 0; i < n; i++) {
2847 if (l->m[i].Typ() == type_job || l->m[i].Typ() == type_trigger) {
2848 deps.push_back(*(Job **)(l->m[i].Data()));
2849 } else {
2850 error = true;
2851 break;
2852 }
2853 }
2854 }
2855 }
2856 if (error) {
2857 return cmd.abort("illegal dependency");
2858 }
2859 for (unsigned i = 0; i < jobs.size(); i++) {
2860 Job *job = jobs[i];
2861 if (job->pool) {
2862 return cmd.abort("job has already been scheduled");
2863 }
2864 job->prio = prio;
2865 }
2866 for (unsigned i = 0; i < deps.size(); i++) {
2867 Job *job = deps[i];
2868 if (!job->pool) {
2869 return cmd.abort("dependency has not yet been scheduled");
2870 }
2871 if (job->pool != pool) {
2872 return cmd.abort("dependency has been scheduled on a different threadpool");
2873 }
2874 }
2875 pool->scheduler->lock.lock();
2876 bool cancelled = false;
2877 for (unsigned i = 0; i < jobs.size(); i++) {
2878 jobs[i]->addDep(deps);
2879 }
2880 for (unsigned i = 0; i < deps.size(); i++) {
2881 deps[i]->addNotify(jobs);
2882 cancelled |= deps[i]->cancelled;
2883 }
2884 for (unsigned i = 0; i < jobs.size(); i++) {
2885 if (cancelled) {
2886 jobs[i]->pool = pool;
2887 pool->cancelJob(jobs[i]);
2888 }
2889 else
2890 pool->attachJob(jobs[i]);
2891 }
2892 pool->scheduler->lock.unlock();
2893 if (jobs.size() > 0)
2894 cmd.set_result(type_job, new_shared(jobs[0]));
2895 return cmd.status();
2896}

◆ sendChannel()

BOOLEAN LibThread::sendChannel ( leftv  result,
leftv  arg 
)

Definition at line 1135 of file shared.cc.

1135 {
1136 if (wrong_num_args("sendChannel", arg, 2))
1137 return TRUE;
1138 if (arg->Typ() != type_channel) {
1139 WerrorS("sendChannel: argument is not a channel");
1140 return TRUE;
1141 }
1142 SingularChannel *channel = *(SingularChannel **)arg->Data();
1143 if (!channel) {
1144 WerrorS("sendChannel: channel has not been initialized");
1145 return TRUE;
1146 }
1147 channel->send(LinTree::to_string(arg->next));
1148 result->rtyp = NONE;
1149 return FALSE;
1150}
void send(string item)
Definition: shared.cc:405

◆ setCurrentThreadPool()

BOOLEAN LibThread::setCurrentThreadPool ( leftv  result,
leftv  arg 
)

Definition at line 2346 of file shared.cc.

2346 {
2347 Command cmd("setCurrentThreadPool", result, arg);
2348 cmd.check_argc(1);
2349 cmd.check_init(0, "threadpool not initialized");
2350 if (cmd.ok()) {
2351 ThreadPool *pool = *(ThreadPool **)(cmd.arg(0));
2352 acquireShared(pool);
2355 currentThreadPoolRef = pool;
2356 }
2357 return cmd.status();
2358}

◆ setJobData()

void LibThread::setJobData ( Job job,
void *  data 
)

Definition at line 2649 of file shared.cc.

2649 {
2650 ThreadPool *pool = job->pool;
2651 if (pool) pool->scheduler->lock.lock();
2652 job->data = data;
2653 if (pool) pool->scheduler->lock.unlock();
2654}

◆ setJobName() [1/2]

void LibThread::setJobName ( const char *  )

◆ setJobName() [2/2]

void LibThread::setJobName ( Job job,
const char *  name 
)

Definition at line 2688 of file shared.cc.

2688 {
2689 // TODO
2690}

◆ setOption()

void LibThread::setOption ( int  ch)

Definition at line 1368 of file shared.cc.

1368 {
1369 int index = feGetOptIndex(ch);
1370 feSetOptValue((feOptIndex) index, (int) 1);
1371}
feOptIndex
Definition: feOptGen.h:15
feOptIndex feGetOptIndex(const char *name)
Definition: feOpt.cc:104
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:154

◆ setSharedName()

BOOLEAN LibThread::setSharedName ( leftv  result,
leftv  arg 
)

Definition at line 3038 of file shared.cc.

3038 {
3039 Command cmd("setSharedName", result, arg);
3040 cmd.check_argc(2);
3041 int type = cmd.argtype(0);
3042 cmd.check_init(0, "first argument is not initialized");
3043 if (type != type_job && type != type_trigger && type != type_threadpool) {
3044 cmd.report("first argument must be a job, trigger, or threadpool");
3045 }
3046 cmd.check_arg(1, STRING_CMD, "second argument must be a string");
3047 if (cmd.ok()) {
3048 SharedObject *obj = cmd.shared_arg<SharedObject>(0);
3049 name_lock.lock();
3050 obj->set_name((char *) cmd.arg(1));
3051 name_lock.unlock();
3052 }
3053 return cmd.status();
3054}

◆ setThreadPoolConcurrency()

static BOOLEAN LibThread::setThreadPoolConcurrency ( leftv  result,
leftv  arg 
)
static

Definition at line 2296 of file shared.cc.

2296 {
2297 Command cmd("setThreadPoolWorkers", result, arg);
2298 cmd.check_argc(2);
2299 cmd.check_arg(0, type_threadpool, "first argument must be a threadpool");
2300 cmd.check_arg(1, INT_CMD, "second argument must be an integer");
2301 cmd.check_init(0, "threadpool not initialized");
2302 if (cmd.ok()) {
2303 ThreadPool *pool = cmd.shared_arg<ThreadPool>(0);
2304 Scheduler *sched = pool->scheduler;
2305 sched->lock.lock();
2306 sched->set_maxconcurrency(cmd.int_arg(1));
2307 sched->lock.unlock();
2308 cmd.no_result();
2309 }
2310 return cmd.status();
2311}

◆ setThreadPoolWorkers()

static BOOLEAN LibThread::setThreadPoolWorkers ( leftv  result,
leftv  arg 
)
static

Definition at line 2266 of file shared.cc.

2266 {
2267 Command cmd("setThreadPoolWorkers", result, arg);
2268 cmd.check_argc(2);
2269 cmd.check_arg(0, type_threadpool, "first argument must be a threadpool");
2270 cmd.check_arg(1, INT_CMD, "second argument must be an integer");
2271 cmd.check_init(0, "threadpool not initialized");
2272 if (cmd.ok()) {
2273 ThreadPool *pool = cmd.shared_arg<ThreadPool>(0);
2274 Scheduler *sched = pool->scheduler;
2275 // TODO: count/add threads
2276 cmd.no_result();
2277 }
2278 return cmd.status();
2279}

◆ shared_alloc() [1/2]

template<typename T >
T * LibThread::shared_alloc ( size_t  n)

Definition at line 42 of file thread.cc.

42 {
43 T *p = (T *) malloc(n * sizeof(T));
44 return p;
45 }
int p
Definition: cfModGcd.cc:4078
STATIC_VAR jList * T
Definition: janet.cc:30
void * malloc(size_t size)
Definition: omalloc.c:85

◆ shared_alloc() [2/2]

template<typename T >
T * LibThread::shared_alloc ( std::size_t  n)

◆ shared_alloc0() [1/2]

template<typename T >
T * LibThread::shared_alloc0 ( size_t  n)

Definition at line 47 of file thread.cc.

47 {
48 T *p = (T *) calloc(n, sizeof(T));
49 return p;
50 }
#define calloc
Definition: omAllocFunc.c:13

◆ shared_alloc0() [2/2]

template<typename T >
T * LibThread::shared_alloc0 ( std::size_t  n)

◆ shared_assign()

BOOLEAN LibThread::shared_assign ( leftv  l,
leftv  r 
)

Definition at line 524 of file shared.cc.

524 {
525 if (r->Typ() == l->Typ()) {
526 if (l->rtyp == IDHDL) {
527 omFree(IDDATA((idhdl)l->data));
528 IDDATA((idhdl)l->data) = (char*)shared_copy(NULL,r->Data());
529 } else {
530 leftv ll=l->LData();
531 if (ll==NULL)
532 {
533 return TRUE; // out of array bounds or similiar
534 }
535 if (ll->data) {
537 omFree(ll->data);
538 }
539 ll->data = shared_copy(NULL,r->Data());
540 }
541 } else {
542 Werror("assign %s(%d) = %s(%d)",
543 Tok2Cmdname(l->Typ()),l->Typ(),Tok2Cmdname(r->Typ()),r->Typ());
544 return TRUE;
545 }
546 return FALSE;
547}

◆ shared_check_assign()

BOOLEAN LibThread::shared_check_assign ( blackbox *  b,
leftv  l,
leftv  r 
)

Definition at line 573 of file shared.cc.

573 {
574 int lt = l->Typ();
575 int rt = r->Typ();
576 if (lt != DEF_CMD && lt != rt) {
577 const char *rn=Tok2Cmdname(rt);
578 const char *ln=Tok2Cmdname(lt);
579 Werror("cannot assign %s (%d) to %s (%d)\n", rn, rt, ln, lt);
580 return TRUE;
581 }
582 return FALSE;
583}
@ DEF_CMD
Definition: tok.h:58

◆ shared_copy()

void * LibThread::shared_copy ( blackbox *  b,
void *  d 
)

Definition at line 515 of file shared.cc.

515 {
516 SharedObject *obj = *(SharedObject **)d;
517 void *result = shared_init(b);
518 *(SharedObject **)result = obj;
519 if (obj)
520 acquireShared(obj);
521 return result;
522}

◆ shared_destroy()

void LibThread::shared_destroy ( blackbox *  b,
void *  d 
)

Definition at line 498 of file shared.cc.

498 {
499 SharedObject *obj = *(SharedObject **)d;
500 if (obj) {
502 *(SharedObject **)d = NULL;
503 }
504}

◆ shared_free() [1/2]

template<typename T >
T LibThread::shared_free ( T p)

Definition at line 52 of file thread.cc.

52 {
53 free(p);
54 }
#define free
Definition: omAllocFunc.c:14

◆ shared_free() [2/2]

template<typename T >
void LibThread::shared_free ( T p)

Definition at line 52 of file thread.cc.

52 {
53 free(p);
54 }

◆ shared_init()

void * LibThread::shared_init ( blackbox *  b)

Definition at line 487 of file shared.cc.

487 {
488 return omAlloc0(sizeof(SharedObject *));
489}

◆ shared_op2()

BOOLEAN LibThread::shared_op2 ( int  op,
leftv  res,
leftv  a1,
leftv  a2 
)

Definition at line 585 of file shared.cc.

585 {
586 SharedObject *obj = *(SharedObject **)a1->Data();
587 return obj->op2(op, res, a1, a2);
588}
virtual BOOLEAN op2(int op, leftv res, leftv a1, leftv a2)
Definition: shared.cc:185
CanonicalForm res
Definition: facAbsFact.cc:60

◆ shared_op3()

BOOLEAN LibThread::shared_op3 ( int  op,
leftv  res,
leftv  a1,
leftv  a2,
leftv  a3 
)

Definition at line 590 of file shared.cc.

590 {
591 SharedObject *obj = *(SharedObject **)a1->Data();
592 return obj->op3(op, res, a1, a2, a3);
593}
virtual BOOLEAN op3(int op, leftv res, leftv a1, leftv a2, leftv a3)
Definition: shared.cc:188

◆ shared_string()

char * LibThread::shared_string ( blackbox *  b,
void *  d 
)

Definition at line 595 of file shared.cc.

595 {
596 char buf[80];
597 SharedObject *obj = *(SharedObject **)d;
598 if (!obj)
599 return omStrDup("<uninitialized shared object>");
600 int type = obj->get_type();
601 string &name = obj->get_name();
602 const char *type_name = "unknown";
603 if (type == type_channel)
604 type_name = "channel";
605 else if (type == type_atomic_table)
606 type_name = "atomic_table";
607 else if (type == type_shared_table)
608 type_name = "shared_table";
609 else if (type == type_atomic_list)
610 type_name = "atomic_list";
611 else if (type == type_shared_list)
612 type_name = "shared_list";
613 else if (type == type_syncvar)
614 type_name = "syncvar";
615 else if (type == type_region)
616 type_name = "region";
617 else if (type == type_regionlock)
618 type_name = "regionlock";
619 else if (type == type_thread) {
620 sprintf(buf, "<thread #%s>", name.c_str());
621 return omStrDup(buf);
622 }
623 else if (type == type_threadpool) {
624 if (name.size() > 0) {
625 name_lock.lock();
626 sprintf(buf, "<threadpool \"%.40s\"@%p>", name.c_str(), obj);
628 } else
629 sprintf(buf, "<threadpool @%p>", obj);
630 return omStrDup(buf);
631 }
632 else if (type == type_job) {
633 if (name.size() > 0) {
634 name_lock.lock();
635 sprintf(buf, "<job \"%.40s\"@%p>", name.c_str(), obj);
637 } else
638 sprintf(buf, "<job @%p>", obj);
639 return omStrDup(buf);
640 }
641 else if (type == type_trigger) {
642 if (name.size() > 0) {
643 name_lock.lock();
644 sprintf(buf, "<trigger \"%.40s\"@%p>", name.c_str(), obj);
646 } else
647 sprintf(buf, "<trigger @%p>", obj);
648 return omStrDup(buf);
649 } else {
650 sprintf(buf, "<unknown type %d>", type);
651 return omStrDup(buf);
652 }
653 sprintf(buf, "<%s \"%.40s\">", type_name, name.c_str());
654 return omStrDup(buf);
655}

◆ startJob() [1/3]

static BOOLEAN LibThread::startJob ( leftv  result,
leftv  arg 
)
static

Definition at line 2523 of file shared.cc.

2523 {
2524 Command cmd("startJob", result, arg);
2525 cmd.check_argc_min(1);
2526 int has_pool = cmd.test_arg(0, type_threadpool);
2527 cmd.check_argc_min(1+has_pool);
2528 if (has_pool)
2529 cmd.check_init(0, "threadpool not initialized");
2530 int has_prio = cmd.test_arg(has_pool, INT_CMD);
2531 long prio = has_prio ? (long) cmd.arg(has_pool) : 0L;
2532 int first_arg = has_pool + has_prio;
2533 cmd.check_arg(first_arg, type_job, STRING_CMD,
2534 "job argument must be a job or string");
2535 if (cmd.ok() && cmd.argtype(first_arg) == type_job)
2536 cmd.check_init(first_arg, "job not initialized");
2537 if (!cmd.ok()) return cmd.status();
2538 ThreadPool *pool;
2539 if (has_pool)
2540 pool = cmd.shared_arg<ThreadPool>(0);
2541 else {
2543 return cmd.abort("no current threadpool defined");
2544 pool = currentThreadPoolRef;
2545 }
2546 Job *job;
2547 if (cmd.argtype(first_arg) == type_job)
2548 job = *(Job **)(cmd.arg(first_arg));
2549 else
2550 job = new ProcJob((char *)(cmd.arg(first_arg)));
2551 leftv a = arg->next;
2552 if (has_pool) a = a->next;
2553 if (has_prio) a = a->next;
2554 for (; a != NULL; a = a->next) {
2555 job->args.push_back(LinTree::to_string(a));
2556 }
2557 if (job->pool)
2558 return cmd.abort("job has already been scheduled");
2559 job->prio = prio;
2560 pool->attachJob(job);
2561 cmd.set_result(type_job, new_shared(job));
2562 return cmd.status();
2563}

◆ startJob() [2/3]

Job * LibThread::startJob ( ThreadPool pool,
Job job 
)

Definition at line 2491 of file shared.cc.

2491 {
2492 return startJob(pool, job, NULL);
2493}
static BOOLEAN startJob(leftv result, leftv arg)
Definition: shared.cc:2523

◆ startJob() [3/3]

Job * LibThread::startJob ( ThreadPool pool,
Job job,
leftv  arg 
)

Definition at line 2481 of file shared.cc.

2481 {
2482 if (job->pool) return NULL;
2483 while (arg) {
2484 job->args.push_back(LinTree::to_string(arg));
2485 arg = arg->next;
2486 }
2487 pool->attachJob(job);
2488 return job;
2489}

◆ statChannel()

BOOLEAN LibThread::statChannel ( leftv  result,
leftv  arg 
)

Definition at line 1171 of file shared.cc.

1171 {
1172 if (wrong_num_args("statChannel", arg, 1))
1173 return TRUE;
1174 if (arg->Typ() != type_channel) {
1175 WerrorS("statChannel: argument is not a channel");
1176 return TRUE;
1177 }
1178 SingularChannel *channel = *(SingularChannel **)arg->Data();
1179 if (!channel) {
1180 WerrorS("receiveChannel: channel has not been initialized");
1181 return TRUE;
1182 }
1183 long n = channel->count();
1184 result->rtyp = INT_CMD;
1185 result->data = (char *)n;
1186 return FALSE;
1187}

◆ statSyncVar()

BOOLEAN LibThread::statSyncVar ( leftv  result,
leftv  arg 
)

Definition at line 1257 of file shared.cc.

1257 {
1258 if (wrong_num_args("statSyncVar", arg, 1))
1259 return TRUE;
1260 if (arg->Typ() != type_syncvar) {
1261 WerrorS("statSyncVar: argument is not a syncvar");
1262 return TRUE;
1263 }
1264 SingularSyncVar *syncvar = *(SingularSyncVar **)arg->Data();
1265 if (!syncvar) {
1266 WerrorS("statSyncVar: syncvar has not been initialized");
1267 return TRUE;
1268 }
1269 int init = syncvar->check();
1270 result->rtyp = INT_CMD;
1271 result->data = (char *)(long) init;
1272 return FALSE;
1273}
void init()
Definition: lintree.cc:864

◆ str()

char * LibThread::str ( leftv  arg)

Definition at line 704 of file shared.cc.

704 {
705 return (char *)(arg->Data());
706}

◆ testTrigger()

static BOOLEAN LibThread::testTrigger ( leftv  result,
leftv  arg 
)
static

Definition at line 2778 of file shared.cc.

2778 {
2779 Command cmd("testTrigger", result, arg);
2780 cmd.check_argc(1);
2781 cmd.check_arg(0, type_trigger, "argument must be a trigger");
2782 cmd.check_init(0, "trigger not initialized");
2783 if (cmd.ok()) {
2784 Trigger *trigger = cmd.shared_arg<Trigger>(0);
2785 ThreadPool *pool = trigger->pool;
2786 pool->scheduler->lock.lock();
2787 cmd.set_result((long)trigger->ready());
2788 pool->scheduler->lock.unlock();
2789 }
2790 return cmd.status();
2791}
virtual bool ready()
Definition: shared.cc:1605

◆ thread_init()

void LibThread::thread_init ( )

Definition at line 1373 of file shared.cc.

1373 {
1374 master_lock.lock();
1377#ifdef ENABLE_THREADS
1379 siInit(global_argv0);
1380#endif
1381 setOption('q');
1382 // setOption('b');
1383}
void siInit(char *)
Definition: misc_ip.cc:1370
long thread_counter
Definition: shared.cc:231
void setOption(int ch)
Definition: shared.cc:1368
Lock master_lock(true)
void pSingular_initialize_thread()

◆ thread_main()

void * LibThread::thread_main ( void *  arg)

Definition at line 1385 of file shared.cc.

1385 {
1386 ThreadState *ts = (ThreadState *)arg;
1387 thread_init();
1388 return ts->thread_func(ts, ts->arg);
1389}
void thread_init()
Definition: shared.cc:1373

◆ threadEval()

BOOLEAN LibThread::threadEval ( leftv  result,
leftv  arg 
)

Definition at line 2927 of file shared.cc.

2927 {
2928 if (wrong_num_args("threadEval", arg, 2))
2929 return TRUE;
2930 if (arg->Typ() != type_thread) {
2931 WerrorS("threadEval: argument is not a thread");
2932 return TRUE;
2933 }
2934 InterpreterThread *thread = *(InterpreterThread **)arg->Data();
2935 string expr = LinTree::to_string(arg->next);
2936 ThreadState *ts = thread->getThreadState();
2937 if (ts && ts->parent != pthread_self()) {
2938 WerrorS("threadEval: can only be called from parent thread");
2939 return TRUE;
2940 }
2941 if (ts) ts->lock.lock();
2942 if (!ts || !ts->running || !ts->active) {
2943 WerrorS("threadEval: thread is no longer running");
2944 if (ts) ts->lock.unlock();
2945 return TRUE;
2946 }
2947 ts->to_thread.push("e");
2948 ts->to_thread.push(expr);
2949 ts->to_cond.signal();
2950 ts->lock.unlock();
2951 result->rtyp = NONE;
2952 return FALSE;
2953}

◆ threadExec()

BOOLEAN LibThread::threadExec ( leftv  result,
leftv  arg 
)

Definition at line 2955 of file shared.cc.

2955 {
2956 if (wrong_num_args("threadExec", arg, 2))
2957 return TRUE;
2958 if (arg->Typ() != type_thread) {
2959 WerrorS("threadExec: argument is not a thread");
2960 return TRUE;
2961 }
2962 InterpreterThread *thread = *(InterpreterThread **)arg->Data();
2963 string expr = LinTree::to_string(arg->next);
2964 ThreadState *ts = thread->getThreadState();
2965 if (ts && ts->parent != pthread_self()) {
2966 WerrorS("threadExec: can only be called from parent thread");
2967 return TRUE;
2968 }
2969 if (ts) ts->lock.lock();
2970 if (!ts || !ts->running || !ts->active) {
2971 WerrorS("threadExec: thread is no longer running");
2972 if (ts) ts->lock.unlock();
2973 return TRUE;
2974 }
2975 ts->to_thread.push("x");
2976 ts->to_thread.push(expr);
2977 ts->to_cond.signal();
2978 ts->lock.unlock();
2979 result->rtyp = NONE;
2980 return FALSE;
2981}

◆ threadID()

BOOLEAN LibThread::threadID ( leftv  result,
leftv  arg 
)

Definition at line 2911 of file shared.cc.

2911 {
2912 if (wrong_num_args("threadID", arg, 0))
2913 return TRUE;
2914 result->rtyp = INT_CMD;
2915 result->data = (char *)thread_id;
2916 return FALSE;
2917}

◆ threadPoolExec()

BOOLEAN LibThread::threadPoolExec ( leftv  result,
leftv  arg 
)

Definition at line 2983 of file shared.cc.

2983 {
2984 Command cmd("threadPoolExec", result, arg);
2985 ThreadPool *pool;
2986 cmd.check_argc(1, 2);
2987 int has_pool = cmd.nargs() == 2;
2988 if (has_pool) {
2989 cmd.check_arg(0, type_threadpool, "first argument must be a threadpool");
2990 cmd.check_init(0, "threadpool not initialized");
2991 pool = cmd.shared_arg<ThreadPool>(0);
2992 } else {
2993 pool = currentThreadPoolRef;
2994 if (!pool)
2995 return cmd.abort("no current threadpool");
2996 }
2997 if (cmd.ok()) {
2998 string expr = LinTree::to_string(has_pool ? arg->next : arg);
2999 Job* job = new ExecJob();
3000 job->args.push_back(expr);
3001 job->pool = pool;
3002 pool->broadcastJob(job);
3003 }
3004 return cmd.status();
3005}
void broadcastJob(Job *job)
Definition: shared.cc:1942

◆ threadResult()

BOOLEAN LibThread::threadResult ( leftv  result,
leftv  arg 
)

Definition at line 3007 of file shared.cc.

3007 {
3008 if (wrong_num_args("threadResult", arg, 1))
3009 return TRUE;
3010 if (arg->Typ() != type_thread) {
3011 WerrorS("threadResult: argument is not a thread");
3012 return TRUE;
3013 }
3014 InterpreterThread *thread = *(InterpreterThread **)arg->Data();
3015 ThreadState *ts = thread->getThreadState();
3016 if (ts && ts->parent != pthread_self()) {
3017 WerrorS("threadResult: can only be called from parent thread");
3018 return TRUE;
3019 }
3020 if (ts) ts->lock.lock();
3021 if (!ts || !ts->running || !ts->active) {
3022 WerrorS("threadResult: thread is no longer running");
3023 if (ts) ts->lock.unlock();
3024 return TRUE;
3025 }
3026 while (ts->from_thread.empty()) {
3027 ts->from_cond.wait();
3028 }
3029 string expr = ts->from_thread.front();
3030 ts->from_thread.pop();
3031 ts->lock.unlock();
3032 leftv val = LinTree::from_string(expr);
3033 result->rtyp = val->Typ();
3034 result->data = val->Data();
3035 return FALSE;
3036}

◆ typeSharedObject()

BOOLEAN LibThread::typeSharedObject ( leftv  result,
leftv  arg 
)

Definition at line 893 of file shared.cc.

893 {
894 if (wrong_num_args("findSharedObject", arg, 1))
895 return TRUE;
896 if (not_a_uri("findSharedObject", arg))
897 return TRUE;
898 string uri = str(arg);
900 &global_objects_lock, uri);
901 int type = obj ? obj->get_type() : -1;
902 const char *type_name = "undefined";
903 if (type == type_channel)
904 type_name = "channel";
905 else if (type == type_atomic_table)
906 type_name = "atomic_table";
907 else if (type == type_shared_table)
908 type_name = "shared_table";
909 else if (type == type_atomic_list)
910 type_name = "atomic_list";
911 else if (type == type_shared_list)
912 type_name = "shared_list";
913 else if (type == type_syncvar)
914 type_name = "syncvar";
915 else if (type == type_region)
916 type_name = "region";
917 else if (type == type_regionlock)
918 type_name = "regionlock";
919 result->rtyp = STRING_CMD;
920 result->data = (char *)(omStrDup(type_name));
921 return FALSE;
922}

◆ unlockRegion()

BOOLEAN LibThread::unlockRegion ( leftv  result,
leftv  arg 
)

Definition at line 1120 of file shared.cc.

1120 {
1121 if (wrong_num_args("unlockRegion", arg, 1))
1122 return TRUE;
1123 if (not_a_region("unlockRegion", arg))
1124 return TRUE;
1125 Region *region = *(Region **)arg->Data();
1126 if (!region->is_locked()) {
1127 WerrorS("unlockRegion: region is not locked");
1128 return TRUE;
1129 }
1130 region->unlock();
1131 result->rtyp = NONE;
1132 return FALSE;
1133}

◆ updateSyncVar()

BOOLEAN LibThread::updateSyncVar ( leftv  result,
leftv  arg 
)

Definition at line 1209 of file shared.cc.

1209 {
1210 Command cmd("updateSyncVar", result, arg);
1211 cmd.check_argc_min(2);
1212 cmd.check_arg(0, type_syncvar, "first argument must be a syncvar");
1213 cmd.check_init(0, "syncvar has not been initialized");
1214 cmd.check_arg(1, STRING_CMD, "second argument must be a string");
1215 if (cmd.ok()) {
1216 SingularSyncVar *syncvar = cmd.shared_arg<SingularSyncVar>(0);
1217 char *procname = (char *) cmd.arg(1);
1218 arg = arg->next->next;
1219 syncvar->acquire();
1220 syncvar->wait_init();
1221 vector<leftv> argv;
1222 appendArg(argv, syncvar->get());
1223 while (arg) {
1224 appendArgCopy(argv, arg);
1225 arg = arg->next;
1226 }
1227 int error = executeProc(*result, procname, argv);
1228 if (!error) {
1229 syncvar->update(result);
1230 }
1231 syncvar->release();
1232 return error;
1233 }
1234 return cmd.status();
1235}
void update(leftv val)
Definition: shared.cc:454
static void appendArgCopy(vector< leftv > &argv, leftv arg)
Definition: shared.cc:742
static void appendArg(vector< leftv > &argv, leftv arg)
Definition: shared.cc:738
static BOOLEAN executeProc(sleftv &result, const char *procname, const vector< leftv > &argv)
Definition: shared.cc:749

◆ updateTrigger()

static BOOLEAN LibThread::updateTrigger ( leftv  result,
leftv  arg 
)
static

Definition at line 2735 of file shared.cc.

2735 {
2736 Command cmd("updateTrigger", result, arg);
2737 cmd.check_argc_min(1);
2738 cmd.check_arg(0, type_trigger, "first argument must be a trigger");
2739 cmd.check_init(0, "trigger not initialized");
2740 if (cmd.ok()) {
2741 Trigger *trigger = cmd.shared_arg<Trigger>(0);
2742 trigger->pool->scheduler->lock.lock();
2743 if (!trigger->accept(arg->next))
2744 cmd.report("incompatible argument type(s) for this trigger");
2745 else {
2746 trigger->activate(arg->next);
2747 if (trigger->ready()) {
2748 trigger->run();
2749 Scheduler::notifyDeps(trigger->pool->scheduler, trigger);
2750 }
2751 }
2752 trigger->pool->scheduler->lock.unlock();
2753 }
2754 return cmd.status();
2755}
void run()
Definition: shared.cc:1982
virtual void activate(leftv arg)=0
virtual bool accept(leftv arg)=0

◆ waitJob() [1/2]

void LibThread::waitJob ( Job job)

Definition at line 2590 of file shared.cc.

2590 {
2591 assert(job->pool != NULL);
2592 job->pool->waitJob(job);
2593}
void waitJob(Job *job)
Definition: shared.cc:1951
#define assert(A)
Definition: svd_si.h:3

◆ waitJob() [2/2]

static BOOLEAN LibThread::waitJob ( leftv  result,
leftv  arg 
)
static

Definition at line 2565 of file shared.cc.

2565 {
2566 Command cmd("waitJob", result, arg);
2567 cmd.check_argc(1);
2568 cmd.check_arg(0, type_job, "argument must be a job");
2569 cmd.check_init(0, "job not initialized");
2570 if (cmd.ok()) {
2571 Job *job = *(Job **)(cmd.arg(0));
2572 ThreadPool *pool = job->pool;
2573 if (!pool) {
2574 return cmd.abort("job has not yet been started or scheduled");
2575 }
2576 pool->waitJob(job);
2577 if (job->cancelled) {
2578 return cmd.abort("job has been cancelled");
2579 }
2580 if (job->result.size() == 0)
2581 cmd.no_result();
2582 else {
2584 cmd.set_result(res->Typ(), res->Data());
2585 }
2586 }
2587 return cmd.status();
2588}

◆ writeSyncVar()

BOOLEAN LibThread::writeSyncVar ( leftv  result,
leftv  arg 
)

Definition at line 1189 of file shared.cc.

1189 {
1190 if (wrong_num_args("writeSyncVar", arg, 2))
1191 return TRUE;
1192 if (arg->Typ() != type_syncvar) {
1193 WerrorS("writeSyncVar: argument is not a syncvar");
1194 return TRUE;
1195 }
1196 SingularSyncVar *syncvar = *(SingularSyncVar **)arg->Data();
1197 if (!syncvar) {
1198 WerrorS("writeSyncVar: syncvar has not been initialized");
1199 return TRUE;
1200 }
1201 if (!syncvar->write(LinTree::to_string(arg->next))) {
1202 WerrorS("writeSyncVar: variable already has a value");
1203 return TRUE;
1204 }
1205 result->rtyp = NONE;
1206 return FALSE;
1207}
int write(string item)
Definition: shared.cc:459

◆ wrong_num_args()

int LibThread::wrong_num_args ( const char *  name,
leftv  arg,
int  n 
)

Definition at line 672 of file shared.cc.

672 {
673 for (int i=1; i<=n; i++) {
674 if (!arg) {
675 report("%s: too few arguments", name);
676 return TRUE;
677 }
678 arg = arg->next;
679 }
680 if (arg) {
681 report("%s: too many arguments", name);
682 return TRUE;
683 }
684 return FALSE;
685}

Variable Documentation

◆ currentJobRef

STATIC_VAR Job* LibThread::currentJobRef

Definition at line 1631 of file shared.cc.

◆ currentThreadPoolRef

STATIC_VAR ThreadPool* LibThread::currentThreadPoolRef

Definition at line 1630 of file shared.cc.

◆ global_objects

SharedObjectTable LibThread::global_objects

Definition at line 227 of file shared.cc.

◆ global_objects_lock

Lock LibThread::global_objects_lock

Definition at line 226 of file shared.cc.

◆ have_threads

const int LibThread::have_threads = 0

Definition at line 38 of file shared.cc.

◆ master_lock

Lock LibThread::master_lock(true) ( true  )

◆ name_lock

Lock LibThread::name_lock(true) ( true  )

◆ thread_counter

long LibThread::thread_counter

Definition at line 231 of file shared.cc.

◆ thread_id

VAR long LibThread::thread_id

Definition at line 230 of file shared.cc.

◆ thread_lock

Lock LibThread::thread_lock

Definition at line 1364 of file shared.cc.

◆ thread_state

ThreadState* LibThread::thread_state

Definition at line 1366 of file shared.cc.

◆ type_atomic_list

int LibThread::type_atomic_list

Definition at line 239 of file shared.cc.

◆ type_atomic_table

int LibThread::type_atomic_table

Definition at line 237 of file shared.cc.

◆ type_channel

int LibThread::type_channel

Definition at line 235 of file shared.cc.

◆ type_job

int LibThread::type_job

Definition at line 243 of file shared.cc.

◆ type_region

int LibThread::type_region

Definition at line 233 of file shared.cc.

◆ type_regionlock

int LibThread::type_regionlock

Definition at line 234 of file shared.cc.

◆ type_shared_list

int LibThread::type_shared_list

Definition at line 240 of file shared.cc.

◆ type_shared_table

int LibThread::type_shared_table

Definition at line 238 of file shared.cc.

◆ type_syncvar

int LibThread::type_syncvar

Definition at line 236 of file shared.cc.

◆ type_thread

int LibThread::type_thread

Definition at line 241 of file shared.cc.

◆ type_threadpool

int LibThread::type_threadpool

Definition at line 242 of file shared.cc.

◆ type_trigger

int LibThread::type_trigger

Definition at line 244 of file shared.cc.