Honeycomb  0.1
Component-Model Framework
Thread.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 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 platform { class Thread; }
11 
12 namespace thread
13 {
14  namespace platform
15  {
17  struct LocalStore
18  {
19  typedef honey::platform::Thread Thread;
20 
22  static bool init();
24  static LocalStore& create(Thread& thread);
26  static void destroy();
28  static LocalStore& inst();
29 
30  Thread* thread;
31 
32  static pthread_key_t _key;
33  };
34  }
35 
36  namespace current { namespace platform
37  {
38  inline void yield() { pthread_yield_np(); }
39  inline void pause() {}
40  } }
41 }
42 
43 namespace platform
44 {
45 
46 class Thread
47 {
48  typedef thread::platform::LocalStore LocalStore;
49  friend struct thread::platform::LocalStore;
50 public:
51  Thread(bool external, int stackSize);
52  Thread(Thread&& rhs);
53  virtual ~Thread();
54 
55  Thread& operator=(Thread&& rhs);
56 
57  static Thread& current();
58 
59  void start();
60  void join();
61 
62  static int priorityNormal();
63  static int priorityMin();
64  static int priorityMax();
65  void setPriority(int priority);
66  int getPriority() const;
67 
68  typedef int ThreadId;
69  static const ThreadId threadIdInvalid = 0;
70  ThreadId threadId() const { return _id; }
71 
72  static int concurrency() { static int ret = concurrency_priv(); return ret; }
73 
74 private:
75  void finalize();
76 
77  static Thread* createExt();
78  static void* entry(void* arg);
79  static int concurrency_priv();
80 
81  pthread_t _handle;
82  ThreadId _id;
83  int _stackSize;
84  UniquePtr<honey::Mutex> _lock;
85 };
86 
87 } }
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
std::enable_if< std::is_default_constructible< Com >::value &&!std::is_abstract< Com >::value, Component & >::type create()
Called by registry to create a component. May be specialized for a component type.
Definition: Component.h:75
Global Honeycomb namespace.