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
14using namespace std;
15
16pthread_t no_thread;
17
18void 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
40namespace 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.h:88
void signal()
Definition: thread.h:97
void lock()
Definition: thread.h:46
void unlock()
Definition: thread.h:57
ConditionVariable cond
Definition: thread.h:114
Lock lock
Definition: thread.h:113
unsigned waiting
Definition: thread.h:116
void wait()
Definition: thread.cc:23
void post()
Definition: thread.cc:33
unsigned count
Definition: thread.h:115
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(std::size_t n)
T * shared_alloc(std::size_t n)
T shared_free(T *p)
Definition: thread.cc:52
#define free
Definition: omAllocFunc.c:14
#define calloc
Definition: omAllocFunc.c:13
void * malloc(size_t size)
Definition: omalloc.c:85
void ThreadError(const char *message)
Definition: thread.cc:18
pthread_t no_thread
Definition: thread.cc:16