[project @ 2003-11-06 19:41:41 by bursa]

Mask null polls and use PollIdle when appropriate.

svn path=/import/netsurf/; revision=406
This commit is contained in:
James Bursa 2003-11-06 19:41:41 +00:00
parent 33759f1e7b
commit b212e59a20
8 changed files with 78 additions and 45 deletions

View File

@ -35,6 +35,8 @@
#include "netsurf/utils/utils.h"
bool fetch_active; /**< Fetches in progress, please call fetch_poll(). */
/** Information for a single fetch. */
struct fetch {
CURL * curl_handle; /**< cURL handle if being fetched, or 0. */
@ -209,6 +211,7 @@ struct fetch * fetch_start(char *url, char *referer,
if (fetch_list != 0)
fetch_list->prev = fetch;
fetch_list = fetch;
fetch_active = true;
/* create the curl easy handle */
fetch->curl_handle = curl_easy_init();
@ -468,6 +471,9 @@ void fetch_poll(void)
}
curl_msg = curl_multi_info_read(curl_multi, &queue);
}
if (!fetch_list)
fetch_active = false;
}

View File

@ -20,6 +20,8 @@ struct content;
struct fetch;
struct form_successful_control;
extern bool fetch_active;
void fetch_init(void);
struct fetch * fetch_start(char *url, char *referer,
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),

View File

@ -15,6 +15,7 @@ typedef enum { SAFE, UNSAFE } gui_safety;
struct gui_window;
typedef struct gui_window gui_window;
#include <stdbool.h>
#include "netsurf/desktop/browser.h"
struct gui_message
@ -51,7 +52,7 @@ void gui_download_window_error(gui_window *g, const char *error);
void gui_init(int argc, char** argv);
void gui_multitask(void);
void gui_poll(void);
void gui_poll(bool active);
gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s);

View File

@ -6,6 +6,8 @@
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
*/
#include <stdbool.h>
#include <stdlib.h>
#include "netsurf/desktop/options.h"
#include "netsurf/desktop/netsurf.h"
#include "netsurf/desktop/browser.h"
@ -13,21 +15,35 @@
#include "netsurf/content/cache.h"
#include "netsurf/content/fetch.h"
#include "netsurf/utils/log.h"
#include <stdlib.h>
int netsurf_quit = 0;
bool netsurf_quit = false;
static void netsurf_init(int argc, char** argv);
static void netsurf_poll(void);
static void netsurf_exit(void);
void netsurf_poll(void)
/**
* Gui NetSurf main().
*/
int main(int argc, char** argv)
{
gui_poll();
fetch_poll();
netsurf_init(argc, argv);
while (!netsurf_quit)
netsurf_poll();
netsurf_exit();
return EXIT_SUCCESS;
}
/**
* Initialise components used by gui NetSurf.
*/
void netsurf_init(int argc, char** argv)
{
stdout = stderr;
@ -41,24 +57,23 @@ void netsurf_init(int argc, char** argv)
}
/**
* Poll components which require it.
*/
void netsurf_poll(void)
{
gui_poll(fetch_active);
fetch_poll();
}
/**
* Clean up components used by gui NetSurf.
*/
void netsurf_exit(void)
{
cache_quit();
fetch_quit();
}
int main(int argc, char** argv)
{
netsurf_init(argc, argv);
while (netsurf_quit == 0)
netsurf_poll();
LOG(("Netsurf quit!"));
netsurf_exit();
return 0;
}

View File

@ -8,9 +8,9 @@
#ifndef _NETSURF_DESKTOP_NETSURF_H_
#define _NETSURF_DESKTOP_NETSURF_H_
extern int netsurf_quit;
#include <stdbool.h>
void netsurf_poll(void);
extern bool netsurf_quit;
#endif

View File

@ -112,6 +112,7 @@ wimp_t task_handle;
wimp_i ro_gui_iconbar_i;
gui_window* over_window = NULL;
bool gui_reformat_pending = false;
int ro_x_units(unsigned long browser_units)
{
@ -470,6 +471,7 @@ void ro_gui_window_open(gui_window* g, wimp_open* open)
g->data.browser.bw->current_content->height);
g->data.browser.old_width = width;
g->data.browser.reformat_pending = true;
gui_reformat_pending = true;
}
}
wimp_open_window(open);
@ -990,7 +992,7 @@ void gui_multitask(void)
break;
case message_QUIT :
netsurf_quit = 1;
netsurf_quit = true;
break;
default:
@ -1072,7 +1074,7 @@ void ro_gui_keypress(wimp_key* key)
return;
}
void gui_poll(void)
void gui_poll(bool active)
{
wimp_event_no event;
wimp_block block;
@ -1083,7 +1085,15 @@ void gui_poll(void)
{
if (ro_gui_poll_queued_blocks == NULL)
{
event = wimp_poll(wimp_MASK_LOSE | wimp_MASK_GAIN, &block, 0);
const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN;
if (active) {
event = wimp_poll(mask, &block, 0);
} else if (over_window || gui_reformat_pending) {
os_t t = os_read_monotonic_time();
event = wimp_poll_idle(mask, &block, t + 10, 0);
} else {
event = wimp_poll(wimp_MASK_NULL | mask, &block, 0);
}
finished = 1;
}
else
@ -1108,12 +1118,15 @@ void gui_poll(void)
wimp_get_pointer_info(&pointer);
ro_gui_window_mouse_at(&pointer);
}
for (g = window_list; g; g = g->next) {
if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) {
content_reformat(g->data.browser.bw->current_content,
browser_x_units(g->data.browser.old_width), 1000);
g->data.browser.reformat_pending = false;
if (gui_reformat_pending) {
for (g = window_list; g; g = g->next) {
if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) {
content_reformat(g->data.browser.bw->current_content,
browser_x_units(g->data.browser.old_width), 1000);
g->data.browser.reformat_pending = false;
}
}
gui_reformat_pending = false;
}
break;
@ -1156,15 +1169,11 @@ void gui_poll(void)
break;
case wimp_POINTER_LEAVING_WINDOW :
g = ro_lookup_gui_from_w(block.leaving.w);
if (g == over_window)
over_window = NULL;
over_window = NULL;
break;
case wimp_POINTER_ENTERING_WINDOW :
g = ro_lookup_gui_from_w(block.entering.w);
if (g != NULL)
over_window = g;
over_window = ro_lookup_gui_from_w(block.entering.w);
break;
case wimp_MOUSE_CLICK :
@ -1261,7 +1270,7 @@ void gui_poll(void)
break;
case message_QUIT :
netsurf_quit = 1;
netsurf_quit = true;
break;
}
break;

View File

@ -173,7 +173,7 @@ void ro_gui_menu_selection(wimp_selection *selection)
ro_gui_open_help_page();
break;
case 3: /* Quit */
netsurf_quit = 1;
netsurf_quit = true;
break;
}

View File

@ -211,7 +211,7 @@ void plugin_add_instance(struct content *c, struct browser_window *bw,
otherwise we'll be stuck in this loop forever
*/
while(temp->poll == 0)
gui_poll();
gui_poll(true);
if(temp->plugin != 0 && temp->reply != 0) {
@ -256,7 +256,7 @@ void plugin_add_instance(struct content *c, struct browser_window *bw,
otherwise we'll be stuck in this loop forever
*/
while(temp->poll == 0)
gui_poll();
gui_poll(true);
if(temp->plugin != 0 && temp->reply != 0) {
@ -370,7 +370,7 @@ void plugin_remove_instance(struct content *c, struct browser_window *bw,
otherwise we'll be stuck in this loop forever
*/
while (temp == 0)
gui_poll();
gui_poll(true);
if (temp->reply != 0){
@ -789,7 +789,7 @@ void plugin_create_stream(struct browser_window *bw, struct object_params *param
otherwise we'll be stuck in this loop forever
*/
while(temp->poll == 0)
gui_poll();
gui_poll(true);
pmsn = (plugin_message_stream_new*)&temp->reply->m->data;
params->browser_stream = params->browser;
@ -851,7 +851,7 @@ void plugin_write_stream(struct browser_window *bw, struct object_params *params
otherwise we'll be stuck in this loop forever
*/
while(temp->poll == 0)
gui_poll();
gui_poll(true);
pmswt = (plugin_message_stream_written*)&temp->reply->m->data;
if(pmswt->length > 0) {