Skip to content

Commit

Permalink
[qt4-simulator] fix segv in simulator
Browse files Browse the repository at this point in the history
by adding mutex for the event queues so that multithreading
does not corrupt non-thread-safe qt queue code.

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information
hxw committed Dec 10, 2009
1 parent aa0d5dd commit e54a6b0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions host-tools/qt4-simulator/src/WikiDisplay.cpp
Expand Up @@ -40,13 +40,17 @@ WikiDisplay::WikiDisplay(QWidget *parent)
keyEventQueue = new QQueue<QKeyEvent>;
mouseEventQueue = new QQueue<QMouseEvent>;
waitCondition = new QWaitCondition();
keyQueueMutex = new QMutex();
mouseQueueMutex = new QMutex();
}

WikiDisplay::~WikiDisplay()
{
delete framebuffer;
delete keyEventQueue;
delete waitCondition;
delete keyQueueMutex;
delete mouseQueueMutex;
}

void
Expand All @@ -57,21 +61,27 @@ WikiDisplay::keyPressEvent(QKeyEvent *event)
&& event->key() != Qt::Key_Down && event->key() != Qt::Key_Up)
return;

keyQueueMutex->lock();
keyEventQueue->enqueue(*event);
keyQueueMutex->unlock();
waitCondition->wakeAll();
}

void
WikiDisplay::mousePressEvent(QMouseEvent *event)
{
mouseQueueMutex->lock();
mouseEventQueue->enqueue(*event);
mouseQueueMutex->unlock();
waitCondition->wakeAll();
}

void
WikiDisplay::mouseReleaseEvent(QMouseEvent *event)
{
mouseQueueMutex->lock();
mouseEventQueue->enqueue(*event);
mouseQueueMutex->unlock();
waitCondition->wakeAll();
}

Expand Down
5 changes: 5 additions & 0 deletions host-tools/qt4-simulator/src/WikiDisplay.h
Expand Up @@ -24,6 +24,7 @@
#include <QEvent>
#include <QKeyEvent>
#include <QQueue>
#include <QMutex>
#include <QWaitCondition>

class WikiDisplay : public QWidget
Expand All @@ -37,8 +38,12 @@ Q_OBJECT
QWaitCondition *waitCondition;
QQueue<QKeyEvent> *keyEventQueue;
QQueue<QMouseEvent> *mouseEventQueue;
QMutex *keyQueueMutex;
QMutex *mouseQueueMutex;

private:
QByteArray *framebuffer;

protected:
void keyPressEvent(QKeyEvent *event);
void mousePressEvent(QMouseEvent *event);
Expand Down
4 changes: 4 additions & 0 deletions host-tools/qt4-simulator/src/WikilibThread.cpp
Expand Up @@ -55,7 +55,9 @@ void wl_input_wait(struct wl_input_event *ev, int sleep)
}

if (!display->keyEventQueue->isEmpty()) {
display->keyQueueMutex->lock();
QKeyEvent keyEvent = display->keyEventQueue->dequeue();
display->keyQueueMutex->unlock();
ev->type = WL_INPUT_EV_TYPE_KEYBOARD;
ev->key_event.keycode = keyEvent.key();
if (!keyEvent.text().isEmpty()) {
Expand Down Expand Up @@ -83,7 +85,9 @@ void wl_input_wait(struct wl_input_event *ev, int sleep)
}

if (!display->mouseEventQueue->isEmpty()) {
display->mouseQueueMutex->lock();
QMouseEvent mouseEvent = display->mouseEventQueue->dequeue();
display->mouseQueueMutex->unlock();
ev->type = WL_INPUT_EV_TYPE_TOUCH;
ev->touch_event.x = mouseEvent.x();
ev->touch_event.y = mouseEvent.y();
Expand Down
9 changes: 8 additions & 1 deletion wiki-app/lcd_buf_draw.c
Expand Up @@ -206,6 +206,13 @@ void init_lcd_draw_buf()
}
pcfFonts[i].fd = fd;
}
#if !defined(INCLUDED_FROM_KERNEL)
else
{
printf("Missing font: '%s'\n", pcfFonts[i].file);
exit(1);
}
#endif
}

}
Expand Down Expand Up @@ -620,7 +627,7 @@ void repaint_framebuffer(unsigned char *buf,int pos, int b_repaint_invert_link)

void buf_draw_horizontal_line(unsigned long start_x, unsigned long end_x)
{
int i;
unsigned long i;
long h_line_y;


Expand Down
2 changes: 1 addition & 1 deletion wiki-app/restricted.c
Expand Up @@ -603,7 +603,7 @@ int get_password_string_len(void)
return password_str_len;
}

void draw_restricted_mark(char *screen_buf)
void draw_restricted_mark(uint8_t *screen_buf)
{
int x, y;

Expand Down
4 changes: 3 additions & 1 deletion wiki-app/restricted.h
Expand Up @@ -21,6 +21,8 @@
#define MAX_PASSWORD_LEN 9
#define RESTRICTED_MARK_LINK 9999999

#include <inttypes.h>

void set_password(void);
void get_password(void);
void check_password(void);
Expand All @@ -30,7 +32,7 @@ int password_remove_char(void);
int clear_password_string(void);
int get_password_string_len(void);
void handle_password_key(char keycode);
void draw_restricted_mark(char *screen_buf);
void draw_restricted_mark(uint8_t *screen_buf);
void filter_option(void);
int init_article_filter(void);

Expand Down

0 comments on commit e54a6b0

Please sign in to comment.