My Project
Loading...
Searching...
No Matches
Singular
dyn_modules
systhreads
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
23
void
Semaphore::wait
() {
24
lock
.
lock
();
25
waiting
++;
26
while
(
count
== 0)
27
cond
.
wait
();
28
waiting
--;
29
count
--;
30
lock
.
unlock
();
31
}
32
33
void
Semaphore::post
() {
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
}
p
int p
Definition:
cfModGcd.cc:4078
ConditionVariable::wait
void wait()
Definition:
thread.h:88
ConditionVariable::signal
void signal()
Definition:
thread.h:97
Lock::lock
void lock()
Definition:
thread.h:46
Lock::unlock
void unlock()
Definition:
thread.h:57
Semaphore::cond
ConditionVariable cond
Definition:
thread.h:114
Semaphore::lock
Lock lock
Definition:
thread.h:113
Semaphore::waiting
unsigned waiting
Definition:
thread.h:116
Semaphore::wait
void wait()
Definition:
thread.cc:23
Semaphore::post
void post()
Definition:
thread.cc:33
Semaphore::count
unsigned count
Definition:
thread.h:115
T
STATIC_VAR jList * T
Definition:
janet.cc:30
message
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition:
kutil.cc:7512
LibThread
Definition:
bytebuf.h:8
LibThread::shared_alloc0
T * shared_alloc0(std::size_t n)
LibThread::shared_alloc
T * shared_alloc(std::size_t n)
LibThread::shared_free
T shared_free(T *p)
Definition:
thread.cc:52
free
#define free
Definition:
omAllocFunc.c:14
calloc
#define calloc
Definition:
omAllocFunc.c:13
malloc
#define malloc
Definition:
omAllocFunc.c:12
singthreads.h
ThreadError
void ThreadError(const char *message)
Definition:
thread.cc:18
no_thread
pthread_t no_thread
Definition:
thread.cc:16
thread.h
threadconf.h
Generated on Mon Feb 27 2023 10:53:50 for My Project by
doxygen 1.9.5
for
Singular