Honeycomb  0.1
Component-Model Framework
Thread.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2014 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 namespace honey
6 {
7 
8 class Mutex;
9 
10 namespace thread
11 {
12  namespace platform
13  {
14  struct LocalStore;
15  }
16 
17  namespace current { namespace platform
18  {
19  inline void yield() { pthread_yield_np(); }
20  inline void pause() {}
21  } }
22 }
23 
24 namespace platform
25 {
26 
27 class Thread
28 {
29  typedef thread::platform::LocalStore LocalStore;
30  friend struct thread::platform::LocalStore;
31 public:
32  Thread(bool external, int stackSize);
33  Thread(Thread&& rhs);
34  virtual ~Thread();
35 
36  Thread& operator=(Thread&& rhs);
37 
38  static Thread& current();
39 
40  void start();
41  void join();
42 
43  static const int priorityNormal = 0;
44  static const int priorityMin;
45  static const int priorityMax;
46  void setPriority(int priority);
47  int getPriority() const;
48 
49  typedef int ThreadId;
50  static const ThreadId threadIdInvalid = 0;
51  ThreadId threadId() const { return _id; }
52 
53  static int concurrency() { static int ret = concurrency_priv(); return ret; }
54 
55 private:
56  void finalize();
57 
58  static Thread* createExt();
59  static void* entry(void* arg);
60  static int concurrency_priv();
61 
62  pthread_t _handle;
63  ThreadId _id;
64  int _stackSize;
65  UniquePtr<honey::Mutex> _lock;
66 };
67 
68 } }
void yield()
Give up this thread's time slice to allow other threads to execute.
Definition: Thread.h:52
void pause()
Perform a no-op without giving up this thread's time slice. This no-op momentarily frees resources fo...
Definition: Thread.h:54
Global Honeycomb namespace.