added new strate of threading to ui
continuous-integration/drone/push Build encountered an error Details

opengl
yorick 3 years ago
parent 7e19fa34ed
commit 9bd3e81c78

@ -19,6 +19,7 @@ std::future<void> menudraw = std::async (ui::UiDrawer::drawMenu);
ui::UiDrawer::drawStartupSequence(); //show startup sequence while camera manager is starting
menudraw.get();
fobj.get();
cameraManager::runCapture();
SerialPortManager::init();
ui::UiController::exitCalled = false;
@ -26,13 +27,13 @@ ui::UiController::runIntro = false;
std::thread* t = new std::thread(ui::UiDrawer::runDrawUi);
Threadweaver::stick_this_thread_to_core(t,1);
Threadweaver::osUiDrawerThread = t;
Threadweaver::gfxPipelineThread = t;
while(!ui::UiController::exitCalled){
sleep(5);
}
t->join();
Threadweaver::gfxPipelineThread->join();
return 0;
}

Binary file not shown.

@ -3,6 +3,7 @@
std::vector<std::thread*> Threadweaver::captureThreads;
std::thread* Threadweaver::hardwareWatcherThread;
std::thread* Threadweaver::osUiDrawerThread;
std::thread* Threadweaver::gfxPipelineThread;
void Threadweaver::stick_this_thread_to_core(std::thread* t,int core_id){
unsigned num_cpus = std::thread::hardware_concurrency();

@ -9,6 +9,7 @@ class Threadweaver{
public:
static std::vector<std::thread*> captureThreads;
static std::thread* hardwareWatcherThread;
static std::thread* gfxPipelineThread;
static std::thread* osUiDrawerThread;
static void stick_this_thread_to_core(std::thread* t,int core_id);

@ -26,7 +26,9 @@ namespace ui {
//Defines a single ui window (by default two will be displayed)
class Ui{
public:
UMat drawBuffer;
UMat drawSurface; //Current frame
int id;
std::string myWindow;
void draw();
};
@ -47,9 +49,12 @@ namespace ui {
};
class UiManager{ //manager is static because we only ever need one
public:
static vector<mutex*> accessLocks;
static vector<Ui*> managedUIs;
static bool uiShouldRun;
static void init();
static void cleanup();
static void cleanup();
static void beginDrawRoutineForUi(Ui* u);
};
class UiController{
public:

@ -3,6 +3,10 @@
void ui::Ui::draw(){
if(drawSurface.empty())
return;
imshow(this->myWindow, this->drawSurface);
waitKey(1);
UiManager::accessLocks.at(this->id)->lock();
drawBuffer = drawSurface;
UiManager::accessLocks.at(this->id)->unlock();
imshow(this->myWindow, this->drawBuffer);
waitKey(17);
}

@ -37,8 +37,10 @@ namespace ui{
cv::hconcat(mats,finished);
DEBUG_LOG("concated mats")
UiManager::accessLocks.at(0)->lock();
UiManager::managedUIs[0]->drawSurface = finished; //write the final image to the psvr UI buffer
UiManager::managedUIs[0]->draw(); //send the image to the psvr
UiManager::accessLocks.at(0)->unlock();
}
void UiDrawer::drawStartupSequence(){

@ -2,9 +2,19 @@
namespace ui{
vector<Ui*> UiManager::managedUIs;
vector<mutex*> UiManager::accessLocks;
bool UiManager::uiShouldRun;
void UiManager::beginDrawRoutineForUi(Ui* u){
while(!ui::UiManager::uiShouldRun){}
while(ui::UiManager::uiShouldRun){
u->draw();
}
}
//initializes the ui manager, following default values
void UiManager::init(){
uiShouldRun = false;
waitKey(1);
for(int i=0; i<DEFAULT_UI_WINDOW_AMOUNT; i++){
Ui* newUI = new Ui();
@ -18,8 +28,16 @@ namespace ui{
cout << "window: " << newUI->myWindow << " created at " << DEFAULT_UI_OFFSET_X+i*960 << " , " << DEFAULT_UI_OFFSET_Y << endl;
newUI->id = i;
managedUIs.push_back(newUI); //add new ui in the ui map, mapped to the window's name
accessLocks.push_back(new mutex());
accessLocks.at(i)->unlock();
std::thread* t = new std::thread(ui::UiManager::beginDrawRoutineForUi,newUI);
Threadweaver::stick_this_thread_to_core(t,0);
Threadweaver::osUiDrawerThread = t; //TODO fix?
}
uiShouldRun = true;
}
void UiManager::cleanup(){

Loading…
Cancel
Save