Loading...
Searching...
No Matches
thread.cc
Go to the documentation of this file.
#include "threadconf.h"
#include <list>
#include <vector>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include "thread.h"
#include "singthreads.h"
using namespace std;
pthread_t no_thread;
void ThreadError(const char *message) {
fprintf(stderr, "FATAL ERROR: %s\n", message);
abort(); // should not happen
}
void Semaphore::wait() {
lock.lock();
waiting++;
while (count == 0)
cond.wait();
waiting--;
count--;
lock.unlock();
}
void Semaphore::post() {
lock.lock();
if (count++ == 0 && waiting)
cond.signal();
lock.unlock();
}
namespace LibThread {
template <typename T>
T *shared_alloc(size_t n) {
T *p = (T *) malloc(n * sizeof(T));
return p;
}
template <typename T>
T *shared_alloc0(size_t n) {
T *p = (T *) calloc(n, sizeof(T));
return p;
}
template <typename T>
void shared_free(T *p) {
free(p);
}
}
p
int p
Definition cfModGcd.cc:4086
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 *olddeg, int *reduc, kStrategy strat, int red_result)
Definition kutil.cc:7463
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