Merge 178671a7bd
into fea45b2d5b
This commit is contained in:
commit
b8f44af0a1
|
@ -6,14 +6,15 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <atomic>
|
||||||
#include "../../ui.h"
|
#include "../../ui.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
uiMultilineEntry *e;
|
uiMultilineEntry *e;
|
||||||
condition_variable cv;
|
condition_variable cv;
|
||||||
mutex m;
|
mutex m;
|
||||||
unique_lock<mutex> ourlock(m);
|
|
||||||
thread *timeThread;
|
thread *timeThread;
|
||||||
|
atomic<bool> running(true);
|
||||||
|
|
||||||
void sayTime(void *data)
|
void sayTime(void *data)
|
||||||
{
|
{
|
||||||
|
@ -25,8 +26,9 @@ void sayTime(void *data)
|
||||||
|
|
||||||
void threadproc(void)
|
void threadproc(void)
|
||||||
{
|
{
|
||||||
ourlock.lock();
|
unique_lock<mutex> ourlock(m);
|
||||||
while (cv.wait_for(ourlock, chrono::seconds(1)) == cv_status::timeout) {
|
while (running.load()) {
|
||||||
|
cv.wait_for(ourlock, chrono::seconds(1));
|
||||||
time_t t;
|
time_t t;
|
||||||
char *base;
|
char *base;
|
||||||
char *s;
|
char *s;
|
||||||
|
@ -41,6 +43,10 @@ void threadproc(void)
|
||||||
|
|
||||||
int onClosing(uiWindow *w, void *data)
|
int onClosing(uiWindow *w, void *data)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
unique_lock<mutex> l(m);
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
// C++ throws a hissy fit if you don't do this
|
// C++ throws a hissy fit if you don't do this
|
||||||
// we might as well, to ensure no uiQueueMain() gets in after uiQuit()
|
// we might as well, to ensure no uiQueueMain() gets in after uiQuit()
|
||||||
|
@ -81,8 +87,6 @@ int main(void)
|
||||||
|
|
||||||
uiBoxAppend(b, uiControl(e), 1);
|
uiBoxAppend(b, uiControl(e), 1);
|
||||||
|
|
||||||
// timeThread needs to lock ourlock itself - see http://stackoverflow.com/a/34121629/3408572
|
|
||||||
ourlock.unlock();
|
|
||||||
timeThread = new thread(threadproc);
|
timeThread = new thread(threadproc);
|
||||||
|
|
||||||
uiWindowOnClosing(w, onClosing, NULL);
|
uiWindowOnClosing(w, onClosing, NULL);
|
||||||
|
|
Loading…
Reference in New Issue