Loading...
Searching...
No Matches
singthreads.h
Go to the documentation of this file.
#ifndef _SINGULAR_LIBTHREAD
#define _SINGULAR_LIBTHREAD
#include <cstdlib>
#include <new>
#include <string>
#include <vector>
namespace LibThread {
class ThreadState;
typedef void *(*ThreadFunc)(ThreadState *, void *);
ThreadState *createThread(ThreadFunc body, void **arg, const char **error);
void *joinThread(ThreadState *thread);
template <typename T>
T *shared_alloc(std::size_t n);
template <typename T>
T *shared_alloc0(std::size_t n);
template <typename T>
T shared_free(T *p);
#ifdef USE_SHARED_ALLOCATOR
template <class T>
struct SharedAllocator {
typedef T value_type;
SharedAllocator() {
// do nothing
}
template <class U> SharedAllocator(const SharedAllocator<U>&) noexcept {
// do nothing
}
T *allocate(std::size_t n) {
T *p = shared_alloc0<T>(n);
if (p) return p;
throw std::bad_alloc();
}
void deallocate(T *p, std::size_t n) noexcept {
shared_free(p);
}
};
typedef std::basic_string<char, std::char_traits<char>, SharedAllocator<char> >
SharedString;
template <typename T>
class SharedVector : public std::vector<T, SharedAllocator<T> > {
public:
SharedVector() : std::vector<T, SharedAllocator<T>>() { }
SharedVector(std::size_t n, const T& value = T()) : std::vector<T, SharedAllocator<T> >(n, value) { }
SharedVector(SharedVector &other) : std::vector<T, SharedAllocator<T> >(&other) { }
};
#endif
}
#endif // _SINGULAR_LIBTHREAD
p
int p
Definition cfModGcd.cc:4086
LibThread::ThreadState
Definition shared.cc:1331
T
STATIC_VAR jList * T
Definition janet.cc:30
error
#define error(a)
Definition mpr_numeric.cc:966
LibThread
Definition bytebuf.h:8
LibThread::shared_alloc0
T * shared_alloc0(std::size_t n)
LibThread::createThread
ThreadState * createThread(void *(*thread_func)(ThreadState *, void *), void *arg)
Definition shared.cc:1464
LibThread::joinThread
void * joinThread(ThreadState *ts)
Definition shared.cc:1469
LibThread::shared_alloc
T * shared_alloc(std::size_t n)
LibThread::shared_free
T shared_free(T *p)
Definition thread.cc:52
LibThread::ThreadFunc
void *(* ThreadFunc)(ThreadState *, void *)
Definition singthreads.h:12