worker_id type changed to uuid

Fixes #6631
`worker_id` is now generate as uuid and saved as string.
This commit is contained in:
Kunal Mohan 2019-12-08 18:24:44 +05:30
parent 03a47c803c
commit 5c56e661ca
No known key found for this signature in database
GPG key ID: 2B475A4524237BAC
5 changed files with 11 additions and 10 deletions

View file

@ -307,7 +307,7 @@ fn run_server(
let worker = WorkerActor {
name: actors.new_name("worker"),
console: console.name(),
id: id,
id: id.clone(),
};
actor_workers.insert((pipeline, id), worker.name.clone());
actors.register(Box::new(worker));

View file

@ -25,6 +25,7 @@ use msg::constellation_msg::PipelineId;
use servo_url::ServoUrl;
use std::net::TcpStream;
use time::{self, Duration, Tm};
//use uuid::Uuid;
// Information would be attached to NewGlobal to be received and show in devtools.
// Extend these fields if we need more information.
@ -356,5 +357,5 @@ impl PreciseTime {
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
pub struct WorkerId(pub u32);
#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
pub struct WorkerId(pub String);

View file

@ -110,7 +110,7 @@ time = "0.1.12"
unicode-segmentation = "1.1.0"
url = "2.0"
utf-8 = "0.7"
uuid = {version = "0.8", features = ["v4"]}
uuid = {version = "0.8", features = ["v4", "serde"]}
xml5ever = "0.16"
webdriver = "0.40"
webgpu = {path = "../webgpu"}

View file

@ -80,6 +80,7 @@ use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use time::{get_time, Timespec};
use uuid::Uuid;
#[derive(JSTraceable)]
pub struct AutoCloseWorker(Arc<AtomicBool>);
@ -94,7 +95,7 @@ impl Drop for AutoCloseWorker {
pub struct GlobalScope {
eventtarget: EventTarget,
crypto: MutNullableDom<Crypto>,
next_worker_id: Cell<WorkerId>,
next_worker_id: WorkerId,
/// The message-port router id for this global, if it is managing ports.
message_port_state: DomRefCell<MessagePortState>,
@ -347,7 +348,7 @@ impl GlobalScope {
message_port_state: DomRefCell::new(MessagePortState::UnManaged),
eventtarget: EventTarget::new_inherited(),
crypto: Default::default(),
next_worker_id: Cell::new(WorkerId(0)),
next_worker_id: WorkerId(Uuid::new_v4().to_string()),
pipeline_id,
devtools_wants_updates: Default::default(),
console_timers: DomRefCell::new(Default::default()),
@ -928,9 +929,7 @@ impl GlobalScope {
/// Get next worker id.
pub fn get_next_worker_id(&self) -> WorkerId {
let worker_id = self.next_worker_id.get();
let WorkerId(id_num) = worker_id;
self.next_worker_id.set(WorkerId(id_num + 1));
let worker_id = self.next_worker_id.clone();
worker_id
}

View file

@ -98,8 +98,9 @@ impl ServiceWorkerManager {
title: title,
url: scope_things.script_url.clone(),
};
let worker_id = scope_things.worker_id.clone();
let _ = chan.send(ScriptToDevtoolsControlMsg::NewGlobal(
(scope_things.init.pipeline_id, Some(scope_things.worker_id)),
(scope_things.init.pipeline_id, Some(worker_id)),
devtools_sender,
page_info,
));