My Project
thread.cc
Go to the documentation of this file.
1 #include "threadconf.h"
2 #include <list>
3 #include <vector>
4 
5 #include <cstring>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/mman.h>
10 
11 #include "thread.h"
12 #include "singthreads.h"
13 
14 using namespace std;
15 
16 pthread_t no_thread;
17 
18 void ThreadError(const char *message) {
19  fprintf(stderr, "FATAL ERROR: %s\n", message);
20  abort(); // should not happen
21 }
22 
24  lock.lock();
25  waiting++;
26  while (count == 0)
27  cond.wait();
28  waiting--;
29  count--;
30  lock.unlock();
31 }
32 
34  lock.lock();
35  if (count++ == 0 && waiting)
36  cond.signal();
37  lock.unlock();
38 }
39 
40 namespace LibThread {
41  template <typename T>
42  T *shared_alloc(size_t n) {
43  T *p = (T *) malloc(n * sizeof(T));
44  return p;
45  }
46  template <typename T>
47  T *shared_alloc0(size_t n) {
48  T *p = (T *) calloc(n, sizeof(T));
49  return p;
50  }
51  template <typename T>
52  void shared_free(T *p) {
53  free(p);
54  }
55 }
int p
Definition: cfModGcd.cc:4078
void wait()
Definition: thread.cc:23
void post()
Definition: thread.cc:33
STATIC_VAR jList * T
Definition: janet.cc:30
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7512
T * shared_alloc0(size_t n)
Definition: thread.cc:47
void shared_free(T *p)
Definition: thread.cc:52
T * shared_alloc(size_t n)
Definition: thread.cc:42
#define free
Definition: omAllocFunc.c:14
#define calloc
Definition: omAllocFunc.c:13
void * malloc(size_t size)
Definition: omalloc.c:85
int status int void size_t count
Definition: si_signals.h:59
void ThreadError(const char *message)
Definition: thread.cc:18
pthread_t no_thread
Definition: thread.cc:16