source: git/Singular/dyn_modules/systhreads/thread.cc @ c1ce47

fieker-DuValspielwiese
Last change on this file since c1ce47 was c1ce47, checked in by Reimer Behrends <behrends@…>, 5 years ago
Fixed systhreads build with ppcc.
  • Property mode set to 100644
File size: 935 bytes
Line 
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
23void Semaphore::wait() {
24  lock.lock();
25  waiting++;
26  while (count == 0)
27    cond.wait();
28  waiting--;
29  count--;
30  lock.unlock();
31}
32
33void Semaphore::post() {
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}
Note: See TracBrowser for help on using the repository browser.