RetroArch
thread_group.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2017 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SPIRV_CROSS_THREAD_GROUP_HPP
18 #define SPIRV_CROSS_THREAD_GROUP_HPP
19 
20 #include <condition_variable>
21 #include <mutex>
22 #include <thread>
23 
24 namespace spirv_cross
25 {
26 template <typename T, unsigned Size>
28 {
29 public:
30  ThreadGroup(T *impl)
31  {
32  for (unsigned i = 0; i < Size; i++)
33  workers[i].start(&impl[i]);
34  }
35 
36  void run()
37  {
38  for (auto &worker : workers)
39  worker.run();
40  }
41 
42  void wait()
43  {
44  for (auto &worker : workers)
45  worker.wait();
46  }
47 
48 private:
49  struct Thread
50  {
51  enum State
52  {
56  };
58 
59  void start(T *impl)
60  {
61  worker = std::thread([impl, this] {
62  for (;;)
63  {
64  {
65  std::unique_lock<std::mutex> l{ lock };
66  cond.wait(l, [this] { return state != Idle; });
67  if (state == Dying)
68  break;
69  }
70 
71  impl->main();
72 
73  std::lock_guard<std::mutex> l{ lock };
74  state = Idle;
75  cond.notify_one();
76  }
77  });
78  }
79 
80  void wait()
81  {
82  std::unique_lock<std::mutex> l{ lock };
83  cond.wait(l, [this] { return state == Idle; });
84  }
85 
86  void run()
87  {
88  std::lock_guard<std::mutex> l{ lock };
89  state = Running;
90  cond.notify_one();
91  }
92 
94  {
95  if (worker.joinable())
96  {
97  {
98  std::lock_guard<std::mutex> l{ lock };
99  state = Dying;
100  cond.notify_one();
101  }
102  worker.join();
103  }
104  }
105  std::thread worker;
106  std::condition_variable cond;
108  };
109  Thread workers[Size];
110 };
111 }
112 
113 #endif
void wait()
Definition: thread_group.hpp:80
Unknown compiler Device disconnected from port File already exists Saving to backup buffer Got connection Port Mapping Successful No arguments supplied and no menu displaying help Waiting for client You have joined as player u Player *s has left the game *s has joined with input devices *s The netplay peer is running an old version of RetroArch Cannot connect A netplay peer is running a different core Cannot connect This core does not support inter architecture netplay between these systems Enter netplay server Incorrect password A netplay client has disconnected You do not have permission to play The input devices requested are not available Netplay peer s paused Give hardware rendered cores their own private context Avoids having to assume hardware state changes inbetween frames Adjusts menu screen appearance settings Improves performance at the cost of latency and more video stuttering Use only if you cannot obtain full speed otherwise Autodetect Capabilities Connecting to port Password Username Accounts List Endpoint Achievements Resume Achievements Hardcore Mode Scan Content Import content Ask Block Frames Audio Driver Audio Enable Turbo Deadzone Audio Maximum Timing Skew Audio Output Dynamic Audio Rate Control Audio Audio Volume WASAPI Exclusive Mode WASAPI Shared Buffer Length Load Override Files Automatically Load Shader Presets Automatically Confirm Quit Scroll Up Toggle Keyboard Basic menu controls Info Scroll Up Toggle Keyboard Don t overwrite SaveRAM on loading savestate Buildbot Assets URL Allow Camera Cheat Start Search For New Cheat Code Cheat File Load Cheat Load Cheat Save Cheat File As Description Leaderboards Locked Locked Test Unofficial Achievements Unlocked Verbose Mode Close Content Load Configuration Save Configuration on Exit Database History List Size Quick Menu Downloads Core Counters Core Information Categories Core name Permissions System manufacturer Controls Install or Restore a Core Core installation succesful Core Automatically extract downloaded archive Core Updater CPU CPU Cursor Custom Ratio Database Selection Start directory< Default > Directory not found Disk Cycle Tray Status Disk Index Don t care Download a Core DPI Override Enable Driver Check for Missing Firmware Before Loading Dynamic Backgrounds Menu entry hover color False Favorites Include Memory Details Sync to Exact Content Frame Throttle Load Content Specific Core Options Automatically Save Game options file Audio Video Troubleshooting Basic Menu Controls Loading Content What Is A Core History Image Information All Users Control Menu Left analog Left analog Left Analog Y Left analog Right Analog X Right analog Right Analog Y Right analog Gun Trigger Gun Aux A Gun Aux C Gun Select Gun D pad Down Gun D pad Right Analog Stick Deadzone Bind All Bind Timeout Hide Unbound Core Input Descriptors Device Index Mouse Index Duty Cycle Keyboard Gamepad Mapping Enable B Down D pad L3 L Left D pad R3 R Right D pad Start button X Y Mouse Mouse Mouse Wheel Down Wheel Right Max Users Cheat index Cheat toggle Disk next Enable hotkeys Fast forward toggle FPS toggle Grab mouse toggle Desktop menu toggle Menu toggle Audio mute toggle On screen keyboard toggle Pause toggle Reset game Cheat Details Save state Next shader Slow motion hold Savestate slot Volume Display Overlay Show Inputs On Overlay Poll Type Behavior Late Prefer Front Touch Remap Binds Enable Input Touch Enable Turbo Period Latency Input Autoconfig Services Dutch Esperanto German Japanese Polish Russian Vietnamese Greek Core Core Logging Level Load Archive Load Content Allow Location Logging Main Menu Menu Color Theme Blue Grey Green Red Footer Opacity Menu Driver Settings Horizontal Animation Background Missing Mouse Support Music Navigation Wrap Around Netplay Netplay Check Frames Input Latency Frames Range Disconnect from netplay host Connect to netplay host Stop netplay host Scan local network Username Publicly Announce Netplay Disallow Non Slave Mode Clients Analog Input Sharing Average Share Vote No preference Netplay Stateless Mode Netplay Spectator Enable Netplay NAT Traversal Network Command Port Network Gamepad Network None No achievements to display No cores available No core options available No history available No items No networks found No playlists No settings found OFF Online Onscreen Display Adjust Bezels and Onscreen controls Adjust the Onscreen Notifications Optional Autoload Preferred Overlay Overlay Opacity Overlay Scale Use PAL60 Mode Pause when menu activated Performance Counters Playlist Touch Support Present MIDI Analog supported CERO Rating CRC32 Developer Edge Magazine Rating ELSPA Rating ESRB Rating Franchise MD5 Origin Publisher Releasedate Year Serial Start Content Reboot Recording Output Custom Record Config Record Driver Enable Recording Save Recordings in Output Dir Load Remap File Save Content Directory Remap File Delete Core Remap File Delete Game Content Directory Remap File Restart Resume RetroKeyboard RetroPad w Analog Rewind Enable Auto Apply Cheats During Game Load Rewind Buffer Size(MB)" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_REWIND_BUFFER_SIZE_STEP
Definition: thread_group.hpp:27
#define T(x)
GLuint start
Definition: glext.h:6292
static sys_sem mutex
Definition: memp.c:120
std::condition_variable cond
Definition: thread_group.hpp:106
State
Definition: thread_group.hpp:51
bool l
Definition: connect_wiiupro.c:37
Definition: barrier.hpp:23
void start(T *impl)
Definition: thread_group.hpp:59
Thread workers[Size]
Definition: thread_group.hpp:109
void wait()
Definition: thread_group.hpp:42
void run()
Definition: thread_group.hpp:86
std::mutex lock
Definition: thread_group.hpp:107
State state
Definition: thread_group.hpp:57
Definition: thread_group.hpp:54
void run()
Definition: thread_group.hpp:36
~Thread()
Definition: thread_group.hpp:93
ThreadGroup(T *impl)
Definition: thread_group.hpp:30
std::thread worker
Definition: thread_group.hpp:105
Definition: thread_group.hpp:49
Definition: thread_group.hpp:53
Definition: thread_group.hpp:55