Moved uiQueueMain() to common/init.c to avoid having multiple initialized variables; the per-OS versions are now uiprivSysQueueMain(). Also more TODOs.
This commit is contained in:
parent
b0e890ca1d
commit
9daef443b2
|
@ -5,6 +5,8 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "uipriv.h"
|
#include "uipriv.h"
|
||||||
|
|
||||||
|
// TODO rename this file to main.c
|
||||||
|
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
bool uiInit(void *options, uiInitError *err)
|
bool uiInit(void *options, uiInitError *err)
|
||||||
|
@ -47,6 +49,15 @@ bool uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiQueueMain(void (*f)(void *data), void *data)
|
||||||
|
{
|
||||||
|
if (!initialized) {
|
||||||
|
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uiprivSysQueueMain(f, data);
|
||||||
|
}
|
||||||
|
|
||||||
bool uiprivCheckInitializedAndThreadImpl(const char *func)
|
bool uiprivCheckInitializedAndThreadImpl(const char *func)
|
||||||
{
|
{
|
||||||
// While it does seem risky to not lock this, if this changes during the execution of this function it means only that it was changed from a different thread, and since it can only change from false to true, an error will be reported anyway.
|
// While it does seem risky to not lock this, if this changes during the execution of this function it means only that it was changed from a different thread, and since it can only change from false to true, an error will be reported anyway.
|
||||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
||||||
// init.c
|
// init.c
|
||||||
extern bool uiprivSysInit(void *options, uiInitError *err);
|
extern bool uiprivSysInit(void *options, uiInitError *err);
|
||||||
extern bool uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
extern bool uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
||||||
|
extern void uiprivSysQueueMain(void (*f)(void *data), void *data);
|
||||||
extern bool uiprivCheckInitializedAndThreadImpl(const char *func);
|
extern bool uiprivCheckInitializedAndThreadImpl(const char *func);
|
||||||
#define uiprivCheckInitializedAndThread() uiprivCheckInitializedAndThreadImpl(uiprivFunc)
|
#define uiprivCheckInitializedAndThread() uiprivCheckInitializedAndThreadImpl(uiprivFunc)
|
||||||
extern bool uiprivSysCheckThread(void);
|
extern bool uiprivSysCheckThread(void);
|
||||||
|
|
|
@ -37,12 +37,12 @@ static uiprivApplicationDelegate *uiprivAppDelegate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static pthread_t mainThread;
|
static pthread_t mainThread;
|
||||||
static BOOL initialized = NO; // TODO deduplicate this from common/init.c
|
|
||||||
|
|
||||||
bool uiprivSysInit(void *options, uiInitError *err)
|
bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
{
|
{
|
||||||
uiprivApp = [uiprivApplication sharedApplication];
|
uiprivApp = [uiprivApplication sharedApplication];
|
||||||
if (![NSApp isKindOfClass:[uiprivApplication class]])
|
if (![NSApp isKindOfClass:[uiprivApplication class]])
|
||||||
|
// TODO verify if Info.plist (both in a proper .app bundle and embedded into a standalone binary) can override this and, if so, add that tidbit to this message
|
||||||
return uiprivInitReturnErrorf(err, "NSApp is not of type uiprivApplication; was likely already initialized beforehand");
|
return uiprivInitReturnErrorf(err, "NSApp is not of type uiprivApplication; was likely already initialized beforehand");
|
||||||
|
|
||||||
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
|
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
|
||||||
|
@ -53,7 +53,6 @@ bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
[uiprivApp setDelegate:uiprivAppDelegate];
|
[uiprivApp setDelegate:uiprivAppDelegate];
|
||||||
|
|
||||||
mainThread = pthread_self();
|
mainThread = pthread_self();
|
||||||
initialized = YES;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,12 +87,8 @@ void uiQuit(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Central Dispatch for this
|
// thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Central Dispatch for this
|
||||||
void uiQueueMain(void (*f)(void *data), void *data)
|
void uiprivSysQueueMain(void (*f)(void *data), void *data)
|
||||||
{
|
{
|
||||||
if (!initialized) {
|
|
||||||
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// dispatch_get_main_queue() is a serial queue so it will not execute multiple uiQueueMain() functions concurrently
|
// dispatch_get_main_queue() is a serial queue so it will not execute multiple uiQueueMain() functions concurrently
|
||||||
// the signature of f matches dispatch_function_t
|
// the signature of f matches dispatch_function_t
|
||||||
dispatch_async_f(dispatch_get_main_queue(), data, f);
|
dispatch_async_f(dispatch_get_main_queue(), data, f);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
static pthread_t mainThread;
|
static pthread_t mainThread;
|
||||||
static gboolean initialized = FALSE; // TODO deduplicate this from common/init.c
|
|
||||||
|
|
||||||
bool uiprivSysInit(void *options, uiInitError *err)
|
bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +13,6 @@ bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mainThread = pthread_self();
|
mainThread = pthread_self();
|
||||||
initialized = TRUE;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,14 +44,10 @@ static gboolean doqueued(gpointer data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiQueueMain(void (*f)(void *data), void *data)
|
void uiprivSysQueueMain(void (*f)(void *data), void *data)
|
||||||
{
|
{
|
||||||
struct queued *q;
|
struct queued *q;
|
||||||
|
|
||||||
if (!initialized) {
|
|
||||||
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
q = g_new0(struct queued, 1);
|
q = g_new0(struct queued, 1);
|
||||||
q->f = f;
|
q->f = f;
|
||||||
q->data = data;
|
q->data = data;
|
||||||
|
|
|
@ -45,7 +45,6 @@ static inline void setHInstance(void)
|
||||||
#define uiprivInitReturnHRESULT(err, msg, hr) uiprivInitReturnErrorf(err, "%s: 0x%08I32X", msg, hr)
|
#define uiprivInitReturnHRESULT(err, msg, hr) uiprivInitReturnErrorf(err, "%s: 0x%08I32X", msg, hr)
|
||||||
|
|
||||||
static DWORD mainThread;
|
static DWORD mainThread;
|
||||||
static BOOL initialized = FALSE; // TODO deduplicate this from common/init.c
|
|
||||||
|
|
||||||
bool uiprivSysInit(void *options, uiInitError *err)
|
bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +91,6 @@ bool uiprivSysInit(void *options, uiInitError *err)
|
||||||
// LONGTERM turn off COM exception handling
|
// LONGTERM turn off COM exception handling
|
||||||
*/
|
*/
|
||||||
mainThread = GetCurrentThreadId();
|
mainThread = GetCurrentThreadId();
|
||||||
initialized = TRUE;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,14 +122,10 @@ void uiQuit(void)
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiQueueMain(void (*f)(void *data), void *data)
|
void uiprivSysQueueMain(void (*f)(void *data), void *data)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
if (!initialized) {
|
|
||||||
uiprivProgrammerError(uiprivProgrammerErrorNotInitialized, uiprivFunc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hr = uiprivHrPostMessageW(uiprivUtilWindow, uiprivUtilWindowMsgQueueMain, (WPARAM) f, (LPARAM) data);
|
hr = uiprivHrPostMessageW(uiprivUtilWindow, uiprivUtilWindowMsgQueueMain, (WPARAM) f, (LPARAM) data);
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
// TODO handle error
|
// TODO handle error
|
||||||
|
|
Loading…
Reference in New Issue