xserver: Branch 'xorg-server-1.4-apple' - 4 commits
Jeremy Huddleston
jeremyhu at kemper.freedesktop.org
Wed Jun 4 12:19:36 PDT 2008
hw/xquartz/darwinEvents.c | 55 ++++++++++++++++++++++------------
hw/xquartz/mach-startup/bundle-main.c | 51 ++++++++++---------------------
2 files changed, 53 insertions(+), 53 deletions(-)
New commits:
commit 7812a8bdf9fab651ea5c07b852b2999547ec628d
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date: Wed Jun 4 12:19:28 2008 -0700
XQuartz: Removed async debugging sleep
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 1e79cd3..151aaa0 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -101,8 +101,10 @@ static inline void darwinEvents_lock(void) {
* when darwinEvents == NULL
*
* TODO: Cleanup this race more elegantly.
+ *
+ * For some reason, xinitrc doesn't run until after this anyways... =/
+ * sleep(2);
*/
- sleep(2);
}
}
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 1c32518..d7b6c37 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -160,9 +160,7 @@ static void accept_fd_handoff(int connected_fd) {
if(launchd_fd == -1)
fprintf(stderr, "Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd);
- fprintf(stderr, "Received new DISPLAY fd (1): %d\n", launchd_fd);
- sleep(10);
- fprintf(stderr, "Received new DISPLAY fd (2): %d\n", launchd_fd);
+ fprintf(stderr, "Received new DISPLAY fd: %d\n", launchd_fd);
DarwinListenOnOpenFD(launchd_fd);
}
@@ -354,6 +352,9 @@ int main(int argc, char **argv, char **envp) {
/* Could open the display, start the launcher */
XCloseDisplay(display);
+ /* TODO: Clean up this race better... givint xinitrc time to run. */
+ sleep(2);
+
return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
}
}
commit ff1c443cadf11d12a7d939e51194f6105153870e
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date: Wed Jun 4 12:01:19 2008 -0700
XQuartz: use a condition variable to signal when darwinEvents is ready rather than polling
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 0ecb064..1e79cd3 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -80,21 +80,36 @@ void QuartzModeEQInit(void);
static int old_flags = 0; // last known modifier state
static xEvent *darwinEvents = NULL;
-static pthread_mutex_t darwinEvents_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER;
static inline void darwinEvents_lock(void) {
int err;
- if((err = pthread_mutex_lock(&darwinEvents_mutex))) {
- ErrorF("%s:%s:%d: Failed to lock darwinEvents_mutex: %d\n",
+ if((err = pthread_mutex_lock(&mieq_lock))) {
+ ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n",
__FILE__, __FUNCTION__, __LINE__, err);
spewCallStack();
}
+ if(darwinEvents == NULL) {
+ pthread_cond_wait(&mieq_ready_cond, &mieq_lock);
+
+ /* We want to give xinit time to finish running xinitrc before we accept
+ * the launchd socket connection.
+ *
+ * Yes, we lock then immediately unlock because the lock does a cond_wait
+ * when darwinEvents == NULL
+ *
+ * TODO: Cleanup this race more elegantly.
+ */
+ sleep(2);
+ }
}
static inline void darwinEvents_unlock(void) {
int err;
- if((err = pthread_mutex_unlock(&darwinEvents_mutex))) {
- ErrorF("%s:%s:%d: Failed to unlock darwinEvents_mutex: %d\n",
+ if((err = pthread_mutex_unlock(&mieq_lock))) {
+ ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n",
__FILE__, __FUNCTION__, __LINE__, err);
spewCallStack();
}
@@ -333,11 +348,17 @@ Bool DarwinEQInit(void) {
QuartzModeEQInit();
- if (!darwinEvents)
+ if (!darwinEvents) {
darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
- if (!darwinEvents)
- FatalError("Couldn't allocate event buffer\n");
-
+
+ if (!darwinEvents)
+ FatalError("Couldn't allocate event buffer\n");
+
+ darwinEvents_lock();
+ pthread_cond_broadcast(&mieq_ready_cond);
+ darwinEvents_unlock();
+ }
+
return TRUE;
}
@@ -453,7 +474,6 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
POINTER_ABSOLUTE, 0, dev==darwinTablet?5:2, valuators);
for(i=0; i<num_events; i++) mieqEnqueue (dev, &darwinEvents[i]);
DarwinPokeEQ();
-
} darwinEvents_unlock();
}
@@ -578,13 +598,8 @@ void DarwinSendDDXEvent(int type, int argc, ...) {
va_end (args);
}
- /* If we're called from something other than the X server thread, we need
- * to wait for the X server to setup darwinEvents.
- */
- while(darwinEvents == NULL) {
- usleep(250000);
- }
-
- mieqEnqueue(darwinPointer, &xe);
- DarwinPokeEQ();
+ darwinEvents_lock(); {
+ mieqEnqueue(darwinPointer, &xe);
+ DarwinPokeEQ();
+ } darwinEvents_unlock();
}
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 9a50668..1c32518 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -412,11 +412,6 @@ int main(int argc, char **argv, char **envp) {
}
#else
void *add_launchd_display_thread(void *data) {
- /* TODO: Really fix this race... we want xinitrc to finish before connections
- * are accepted on the launchd socket.
- */
- sleep(2);
-
/* Start listening on the launchd fd */
int launchd_fd = launchd_display_fd();
if(launchd_fd != -1) {
commit c3558bb8cd889e5b957190e9f5d23afad1e17b72
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date: Wed Jun 4 11:35:24 2008 -0700
XQuartz: Don't forget to destroy the mutex and cond after we're done with them
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 67c338f..9a50668 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -203,15 +203,15 @@ static void socket_handoff_thread(void *arg) {
fprintf(stderr, "Failed to create socket: %s - %s\n", filename, strerror(errno));
data->retval = EXIT_FAILURE;
- pthread_mutex_unlock(&data->lock);
pthread_cond_broadcast(&data->cond);
+ pthread_mutex_unlock(&data->lock);
return;
}
/* Let the dispatch thread now tell the caller that we're ready */
data->retval = EXIT_SUCCESS;
- pthread_mutex_unlock(&data->lock);
pthread_cond_broadcast(&data->cond);
+ pthread_mutex_unlock(&data->lock);
if(connect(handoff_fd, servaddr, servaddr_len) < 0) {
fprintf(stderr, "Failed to connect to socket: %s - %s\n", filename, strerror(errno));
@@ -227,6 +227,7 @@ static void socket_handoff_thread(void *arg) {
kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
handoff_data_t handoff_data;
+ /* Initialize our data */
pthread_mutex_init(&handoff_data.lock, NULL);
pthread_cond_init(&handoff_data.cond, NULL);
strlcpy(handoff_data.socket_filename, socket_filename, STRING_T_SIZE);
@@ -234,9 +235,15 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
pthread_mutex_lock(&handoff_data.lock);
create_thread(socket_handoff_thread, &handoff_data);
-
+
+ /* Wait for our return value */
pthread_cond_wait(&handoff_data.cond, &handoff_data.lock);
+ pthread_mutex_unlock(&handoff_data.lock);
+ /* Cleanup */
+ pthread_cond_destroy(&handoff_data.cond);
+ pthread_mutex_destroy(&handoff_data.lock);
+
return handoff_data.retval;
}
commit dd0f8a0f59593d7831fe09a2a086fcd57c84910e
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date: Wed Jun 4 11:18:52 2008 -0700
XQuartz: Fork for trigger
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 943ec54..67c338f 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -79,12 +79,6 @@ static pthread_t create_thread(void *func, void *arg) {
}
#ifdef NEW_LAUNCH_METHOD
-struct arg {
- int argc;
- char **argv;
- char **envp;
-};
-
/*** Mach-O IPC Stuffs ***/
union MaxMsgSize {
@@ -368,12 +362,6 @@ int main(int argc, char **argv, char **envp) {
}
#ifdef NEW_LAUNCH_METHOD
-static void startup_trigger_thread(void *arg) {
- struct arg args = *((struct arg *)arg);
- free(arg);
- startup_trigger(args.argc, args.argv, args.envp);
-}
-
/*** Main ***/
int main(int argc, char **argv, char **envp) {
Bool listenOnly = FALSE;
@@ -400,21 +388,13 @@ int main(int argc, char **argv, char **envp) {
* thread handle it.
*/
if(!listenOnly) {
- struct arg *args = (struct arg*)malloc(sizeof(struct arg));
- if(!args) {
- fprintf(stderr, "Memory allocation error.\n");
- return EXIT_FAILURE;
+ if(fork() == 0) {
+ return startup_trigger(argc, argv, envp);
}
-
- args->argc = argc;
- args->argv = argv;
- args->envp = envp;
-
- create_thread(startup_trigger_thread, args);
}
/* Main event loop */
- fprintf(stderr, "Statrup coming...\n");
+ fprintf(stderr, "Waiting for startup parameters via Mach IPC.\n");
kr = mach_msg_server(mach_startup_server, mxmsgsz, mp, 0);
if (kr != KERN_SUCCESS) {
fprintf(stderr, "org.x.X11(mp): %s\n", mach_error_string(kr));
More information about the xorg-commit
mailing list