My Project
singthreads.h
Go to the documentation of this file.
1#ifndef _SINGULAR_LIBTHREAD
2#define _SINGULAR_LIBTHREAD
3
4#include <cstdlib>
5#include <new>
6#include <string>
7#include <vector>
8
9namespace LibThread {
10
11class ThreadState;
12typedef void *(*ThreadFunc)(ThreadState *, void *);
13
14ThreadState *createThread(ThreadFunc body, void **arg, const char **error);
15void *joinThread(ThreadState *thread);
16
17template <typename T>
18T *shared_alloc(std::size_t n);
19template <typename T>
20T *shared_alloc0(std::size_t n);
21template <typename T>
23
24#ifdef USE_SHARED_ALLOCATOR
25
26template <class T>
27struct SharedAllocator {
28 typedef T value_type;
29 SharedAllocator() {
30 // do nothing
31 }
32 template <class U> SharedAllocator(const SharedAllocator<U>&) noexcept {
33 // do nothing
34 }
35 T *allocate(std::size_t n) {
36 T *p = shared_alloc0<T>(n);
37 if (p) return p;
38 throw std::bad_alloc();
39 }
40 void deallocate(T *p, std::size_t n) noexcept {
42 }
43};
44
45typedef std::basic_string<char, std::char_traits<char>, SharedAllocator<char> >
46 SharedString;
47
48template <typename T>
49class SharedVector : public std::vector<T, SharedAllocator<T> > {
50public:
51 SharedVector() : std::vector<T, SharedAllocator<T>>() { }
52 SharedVector(std::size_t n, const T& value = T()) : std::vector<T, SharedAllocator<T> >(n, value) { }
53 SharedVector(SharedVector &other) : std::vector<T, SharedAllocator<T> >(&other) { }
54};
55
56#endif
57
58}
59
60#endif // _SINGULAR_LIBTHREAD
int p
Definition: cfModGcd.cc:4078
void error(const char *fmt,...)
Definition: emacs.cc:55
STATIC_VAR jList * T
Definition: janet.cc:30
T * shared_alloc0(std::size_t n)
ThreadState * createThread(void *(*thread_func)(ThreadState *, void *), void *arg)
Definition: shared.cc:1469
void * joinThread(ThreadState *ts)
Definition: shared.cc:1474
T * shared_alloc(std::size_t n)
T shared_free(T *p)
Definition: thread.cc:52
void *(* ThreadFunc)(ThreadState *, void *)
Definition: singthreads.h:12