2013-05-30 03:16:33 -07:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 16:48:01 -08:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-09-19 17:29:54 -07:00
|
|
|
/*!
|
|
|
|
|
|
|
|
Task local data management
|
|
|
|
|
2013-07-12 01:38:44 -07:00
|
|
|
Allows storing arbitrary types inside task-local-storage (TLS), to be accessed
|
2013-07-14 01:43:31 -07:00
|
|
|
anywhere within a task, keyed by a global pointer parameterized over the type of
|
|
|
|
the TLS slot. Useful for dynamic variables, singletons, and interfacing with
|
|
|
|
foreign code with bad callback interfaces.
|
2012-09-19 17:29:54 -07:00
|
|
|
|
2013-09-12 23:26:06 -07:00
|
|
|
To declare a new key for storing local data of a particular type, use the
|
2013-12-15 16:26:09 +11:00
|
|
|
`local_data_key!` macro. This macro will expand to a `static` item appropriately
|
2013-09-12 23:26:06 -07:00
|
|
|
named and annotated. This name is then passed to the functions in this module to
|
|
|
|
modify/read the slot specified by the key.
|
2013-07-09 17:25:28 -07:00
|
|
|
|
2013-09-23 17:20:36 -07:00
|
|
|
```rust
|
2013-09-24 13:34:48 +09:00
|
|
|
local_data_key!(key_int: int)
|
|
|
|
local_data_key!(key_vector: ~[int])
|
2013-07-09 17:25:28 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
key_int.replace(Some(3));
|
|
|
|
assert_eq!(*key_int.get().unwrap(), 3);
|
2013-07-09 17:25:28 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
key_vector.replace(Some(~[4]));
|
|
|
|
assert_eq!(*key_vector.get().unwrap(), ~[4]);
|
2014-05-02 17:56:35 -07:00
|
|
|
```
|
2012-09-19 17:29:54 -07:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-09-12 23:26:06 -07:00
|
|
|
// Casting 'Arcane Sight' reveals an overwhelming aura of Transmutation
|
|
|
|
// magic.
|
|
|
|
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
use core::prelude::*;
|
|
|
|
|
|
|
|
use alloc::owned::Box;
|
|
|
|
use collections::vec::Vec;
|
|
|
|
use core::kinds::marker;
|
|
|
|
use core::mem;
|
|
|
|
use core::raw;
|
|
|
|
|
|
|
|
use local::Local;
|
|
|
|
use task::{Task, LocalStorage};
|
2012-09-19 17:29:54 -07:00
|
|
|
|
|
|
|
/**
|
2013-07-14 01:43:31 -07:00
|
|
|
* Indexes a task-local data slot. This pointer is used for comparison to
|
|
|
|
* differentiate keys from one another. The actual type `T` is not used anywhere
|
|
|
|
* as a member of this type, except that it is parameterized with it to define
|
|
|
|
* the type of each key's value.
|
2012-09-19 17:29:54 -07:00
|
|
|
*
|
2013-07-14 01:43:31 -07:00
|
|
|
* The value of each Key is of the singleton enum KeyValue. These also have the
|
|
|
|
* same name as `Key` and their purpose is to take up space in the programs data
|
|
|
|
* sections to ensure that each value of the `Key` type points to a unique
|
|
|
|
* location.
|
2012-09-19 17:29:54 -07:00
|
|
|
*/
|
2013-07-14 01:43:31 -07:00
|
|
|
pub type Key<T> = &'static KeyValue<T>;
|
2012-09-19 17:29:54 -07:00
|
|
|
|
2013-10-01 23:26:45 -07:00
|
|
|
#[allow(missing_doc)]
|
2013-07-14 01:43:31 -07:00
|
|
|
pub enum KeyValue<T> { Key }
|
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
#[doc(hidden)]
|
2013-08-10 20:06:39 -07:00
|
|
|
trait LocalData {}
|
|
|
|
impl<T: 'static> LocalData for T {}
|
2013-07-22 00:06:29 -04:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
// The task-local-map stores all TLS information for the currently running task.
|
|
|
|
// It is stored as an owned pointer into the runtime, and it's only allocated
|
|
|
|
// when TLS is used for the first time. This map must be very carefully
|
|
|
|
// constructed because it has many mutable loans unsoundly handed out on it to
|
|
|
|
// the various invocations of TLS requests.
|
|
|
|
//
|
|
|
|
// One of the most important operations is loaning a value via `get` to a
|
|
|
|
// caller. In doing so, the slot that the TLS entry is occupying cannot be
|
2013-09-23 21:28:33 -05:00
|
|
|
// invalidated because upon returning its loan state must be updated. Currently
|
2013-08-10 20:06:39 -07:00
|
|
|
// the TLS map is a vector, but this is possibly dangerous because the vector
|
|
|
|
// can be reallocated/moved when new values are pushed onto it.
|
|
|
|
//
|
|
|
|
// This problem currently isn't solved in a very elegant way. Inside the `get`
|
|
|
|
// function, it internally "invalidates" all references after the loan is
|
|
|
|
// finished and looks up into the vector again. In theory this will prevent
|
|
|
|
// pointers from being moved under our feet so long as LLVM doesn't go too crazy
|
|
|
|
// with the optimizations.
|
|
|
|
//
|
|
|
|
// n.b. If TLS is used heavily in future, this could be made more efficient with
|
|
|
|
// a proper map.
|
|
|
|
#[doc(hidden)]
|
2014-04-28 20:36:08 -07:00
|
|
|
pub type Map = Vec<Option<(*u8, TLSValue, uint)>>;
|
2014-05-05 18:56:44 -07:00
|
|
|
type TLSValue = Box<LocalData:Send>;
|
2013-08-10 20:06:39 -07:00
|
|
|
|
|
|
|
// Gets the map from the runtime. Lazily initialises if not done so already.
|
2014-06-04 10:54:35 -07:00
|
|
|
unsafe fn get_local_map() -> Option<&mut Map> {
|
|
|
|
if !Local::exists(None::<Task>) { return None }
|
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
let task: *mut Task = Local::unsafe_borrow();
|
|
|
|
match &mut (*task).storage {
|
|
|
|
// If the at_exit function is already set, then we just need to take
|
|
|
|
// a loan out on the TLS map stored inside
|
|
|
|
&LocalStorage(Some(ref mut map_ptr)) => {
|
2014-06-04 10:54:35 -07:00
|
|
|
return Some(map_ptr);
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
// If this is the first time we've accessed TLS, perform similar
|
|
|
|
// actions to the oldsched way of doing things.
|
|
|
|
&LocalStorage(ref mut slot) => {
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
*slot = Some(Vec::new());
|
2013-08-10 20:06:39 -07:00
|
|
|
match *slot {
|
2014-06-04 10:54:35 -07:00
|
|
|
Some(ref mut map_ptr) => { return Some(map_ptr) }
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
None => fail!("unreachable code"),
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-16 17:20:43 -07:00
|
|
|
}
|
2013-07-22 00:06:29 -04:00
|
|
|
|
2013-12-12 22:27:26 +01:00
|
|
|
fn key_to_key_value<T: 'static>(key: Key<T>) -> *u8 {
|
2014-04-28 20:36:08 -07:00
|
|
|
key as *KeyValue<T> as *u8
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
/// An RAII immutable reference to a task-local value.
|
2013-08-10 20:06:39 -07:00
|
|
|
///
|
2014-04-28 20:36:08 -07:00
|
|
|
/// The task-local data can be accessed through this value, and when this
|
|
|
|
/// structure is dropped it will return the borrow on the data.
|
|
|
|
pub struct Ref<T> {
|
2014-05-24 21:35:53 +10:00
|
|
|
// FIXME #12808: strange names to try to avoid interfering with
|
|
|
|
// field accesses of the contained type via Deref
|
|
|
|
_ptr: &'static T,
|
|
|
|
_key: Key<T>,
|
|
|
|
_index: uint,
|
|
|
|
_nosend: marker::NoSend,
|
2012-09-19 17:29:54 -07:00
|
|
|
}
|
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
impl<T: 'static> KeyValue<T> {
|
|
|
|
/// Replaces a value in task local storage.
|
|
|
|
///
|
|
|
|
/// If this key is already present in TLS, then the previous value is
|
|
|
|
/// replaced with the provided data, and then returned.
|
|
|
|
///
|
|
|
|
/// # Failure
|
|
|
|
///
|
|
|
|
/// This function will fail if this key is present in TLS and currently on
|
|
|
|
/// loan with the `get` method.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// local_data_key!(foo: int)
|
|
|
|
///
|
|
|
|
/// assert_eq!(foo.replace(Some(10)), None);
|
|
|
|
/// assert_eq!(foo.replace(Some(4)), Some(10));
|
|
|
|
/// assert_eq!(foo.replace(None), Some(4));
|
|
|
|
/// ```
|
|
|
|
pub fn replace(&'static self, data: Option<T>) -> Option<T> {
|
2014-06-04 10:54:35 -07:00
|
|
|
let map = match unsafe { get_local_map() } {
|
|
|
|
Some(map) => map,
|
|
|
|
None => fail!("must have a local task to insert into TLD"),
|
|
|
|
};
|
2014-04-28 20:36:08 -07:00
|
|
|
let keyval = key_to_key_value(self);
|
|
|
|
|
|
|
|
// When the task-local map is destroyed, all the data needs to be
|
|
|
|
// cleaned up. For this reason we can't do some clever tricks to store
|
|
|
|
// '~T' as a '*c_void' or something like that. To solve the problem, we
|
|
|
|
// cast everything to a trait (LocalData) which is then stored inside
|
|
|
|
// the map. Upon destruction of the map, all the objects will be
|
|
|
|
// destroyed and the traits have enough information about them to
|
|
|
|
// destroy themselves.
|
|
|
|
//
|
|
|
|
// Additionally, the type of the local data map must ascribe to Send, so
|
|
|
|
// we do the transmute here to add the Send bound back on. This doesn't
|
|
|
|
// actually matter because TLS will always own the data (until its moved
|
|
|
|
// out) and we're not actually sending it to other schedulers or
|
|
|
|
// anything.
|
|
|
|
let newval = data.map(|d| {
|
|
|
|
let d = box d as Box<LocalData>;
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
let d: Box<LocalData:Send> = unsafe { mem::transmute(d) };
|
2014-04-28 20:36:08 -07:00
|
|
|
(keyval, d, 0)
|
|
|
|
});
|
2012-09-19 17:29:54 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
let pos = match self.find(map) {
|
|
|
|
Some((i, _, &0)) => Some(i),
|
|
|
|
Some((_, _, _)) => fail!("TLS value cannot be replaced because it \
|
|
|
|
is already borrowed"),
|
|
|
|
None => map.iter().position(|entry| entry.is_none()),
|
|
|
|
};
|
|
|
|
|
|
|
|
match pos {
|
|
|
|
Some(i) => {
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
mem::replace(map.get_mut(i), newval).map(|(_, data, _)| {
|
2014-04-28 20:36:08 -07:00
|
|
|
// Move `data` into transmute to get out the memory that it
|
|
|
|
// owns, we must free it manually later.
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 10:34:51 -07:00
|
|
|
let t: raw::TraitObject = unsafe { mem::transmute(data) };
|
|
|
|
let alloc: Box<T> = unsafe { mem::transmute(t.data) };
|
2014-04-28 20:36:08 -07:00
|
|
|
|
|
|
|
// Now that we own `alloc`, we can just move out of it as we
|
|
|
|
// would with any other data.
|
|
|
|
*alloc
|
|
|
|
})
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
None => {
|
|
|
|
map.push(newval);
|
|
|
|
None
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2013-07-12 01:38:44 -07:00
|
|
|
}
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2012-09-19 17:29:54 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
/// Borrows a value from TLS.
|
|
|
|
///
|
|
|
|
/// If `None` is returned, then this key is not present in TLS. If `Some` is
|
|
|
|
/// returned, then the returned data is a smart pointer representing a new
|
|
|
|
/// loan on this TLS key. While on loan, this key cannot be altered via the
|
|
|
|
/// `replace` method.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// local_data_key!(key: int)
|
|
|
|
///
|
|
|
|
/// assert!(key.get().is_none());
|
|
|
|
///
|
|
|
|
/// key.replace(Some(3));
|
|
|
|
/// assert_eq!(*key.get().unwrap(), 3);
|
|
|
|
/// ```
|
|
|
|
pub fn get(&'static self) -> Option<Ref<T>> {
|
2014-06-04 10:54:35 -07:00
|
|
|
let map = match unsafe { get_local_map() } {
|
|
|
|
Some(map) => map,
|
|
|
|
None => return None,
|
|
|
|
};
|
2014-04-28 20:36:08 -07:00
|
|
|
|
|
|
|
self.find(map).map(|(pos, data, loan)| {
|
|
|
|
*loan += 1;
|
|
|
|
|
|
|
|
// data was created with `~T as ~LocalData`, so we extract
|
|
|
|
// pointer part of the trait, (as ~T), and then use
|
|
|
|
// compiler coercions to achieve a '&' pointer.
|
|
|
|
let ptr = unsafe {
|
|
|
|
let data = data as *Box<LocalData:Send> as *raw::TraitObject;
|
|
|
|
&mut *((*data).data as *mut T)
|
|
|
|
};
|
2014-05-24 21:35:53 +10:00
|
|
|
Ref { _ptr: ptr, _index: pos, _nosend: marker::NoSend, _key: self }
|
2014-04-28 20:36:08 -07:00
|
|
|
})
|
|
|
|
}
|
2012-09-19 17:29:54 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
fn find<'a>(&'static self,
|
|
|
|
map: &'a mut Map) -> Option<(uint, &'a TLSValue, &'a mut uint)>{
|
|
|
|
let key_value = key_to_key_value(self);
|
|
|
|
map.mut_iter().enumerate().filter_map(|(i, entry)| {
|
2013-08-10 20:06:39 -07:00
|
|
|
match *entry {
|
2014-04-28 20:36:08 -07:00
|
|
|
Some((k, ref data, ref mut loan)) if k == key_value => {
|
|
|
|
Some((i, data, loan))
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
_ => None
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
}).next()
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
}
|
2013-08-10 20:06:39 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
impl<T: 'static> Deref<T> for Ref<T> {
|
2014-05-24 21:35:53 +10:00
|
|
|
fn deref<'a>(&'a self) -> &'a T { self._ptr }
|
2012-09-19 17:29:54 -07:00
|
|
|
}
|
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
#[unsafe_destructor]
|
|
|
|
impl<T: 'static> Drop for Ref<T> {
|
|
|
|
fn drop(&mut self) {
|
2014-06-04 10:54:35 -07:00
|
|
|
let map = unsafe { get_local_map().unwrap() };
|
2014-04-28 20:36:08 -07:00
|
|
|
|
2014-05-24 21:35:53 +10:00
|
|
|
let (_, _, ref mut loan) = *map.get_mut(self._index).get_mut_ref();
|
2014-04-28 20:36:08 -07:00
|
|
|
*loan -= 1;
|
2012-09-19 17:29:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
use std::prelude::*;
|
2013-08-10 20:06:39 -07:00
|
|
|
use super::*;
|
std: Extract librustrt out of libstd
As part of the libstd facade efforts, this commit extracts the runtime interface
out of the standard library into a standalone crate, librustrt. This crate will
provide the following services:
* Definition of the rtio interface
* Definition of the Runtime interface
* Implementation of the Task structure
* Implementation of task-local-data
* Implementation of task failure via unwinding via libunwind
* Implementation of runtime initialization and shutdown
* Implementation of thread-local-storage for the local rust Task
Notably, this crate avoids the following services:
* Thread creation and destruction. The crate does not require the knowledge of
an OS threading system, and as a result it seemed best to leave out the
`rt::thread` module from librustrt. The librustrt module does depend on
mutexes, however.
* Implementation of backtraces. There is no inherent requirement for the runtime
to be able to generate backtraces. As will be discussed later, this
functionality continues to live in libstd rather than librustrt.
As usual, a number of architectural changes were required to make this crate
possible. Users of "stable" functionality will not be impacted by this change,
but users of the `std::rt` module will likely note the changes. A list of
architectural changes made is:
* The stdout/stderr handles no longer live directly inside of the `Task`
structure. This is a consequence of librustrt not knowing about `std::io`.
These two handles are now stored inside of task-local-data.
The handles were originally stored inside of the `Task` for perf reasons, and
TLD is not currently as fast as it could be. For comparison, 100k prints goes
from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
perf loss for the successful extraction of a librustrt crate.
* The `rtio` module was forced to duplicate more functionality of `std::io`. As
the module no longer depends on `std::io`, `rtio` now defines structures such
as socket addresses, addrinfo fiddly bits, etc. The primary change made was
that `rtio` now defines its own `IoError` type. This type is distinct from
`std::io::IoError` in that it does not have an enum for what error occurred,
but rather a platform-specific error code.
The native and green libraries will be updated in later commits for this
change, and the bulk of this effort was put behind updating the two libraries
for this change (with `rtio`).
* Printing a message on task failure (along with the backtrace) continues to
live in libstd, not in librustrt. This is a consequence of the above decision
to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
The unwinding API now supports registration of global callback functions which
will be invoked when a task fails, allowing for libstd to register a function
to print a message and a backtrace.
The API for registering a callback is experimental and unsafe, as the
ramifications of running code on unwinding is pretty hairy.
* The `std::unstable::mutex` module has moved to `std::rt::mutex`.
* The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
the type has been rewritten to not internally have an Arc and to have an RAII
guard structure when locking. Old code should stop using `Exclusive` in favor
of the primitives in `libsync`, but if necessary, old code should port to
`Arc<Exclusive<T>>`.
* The local heap has been stripped down to have fewer debugging options. None of
these were tested, and none of these have been used in a very long time.
[breaking-change]
2014-06-03 19:11:49 -07:00
|
|
|
use std::task;
|
2013-08-10 20:06:39 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_multitask() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static my_key: Key<String> = &Key;
|
2014-05-25 03:17:19 -07:00
|
|
|
my_key.replace(Some("parent data".to_string()));
|
2014-01-26 22:42:26 -05:00
|
|
|
task::spawn(proc() {
|
2013-08-10 20:06:39 -07:00
|
|
|
// TLS shouldn't carry over.
|
2014-04-28 20:36:08 -07:00
|
|
|
assert!(my_key.get().is_none());
|
2014-05-25 03:17:19 -07:00
|
|
|
my_key.replace(Some("child data".to_string()));
|
2014-04-28 20:36:08 -07:00
|
|
|
assert!(my_key.get().get_ref().as_slice() == "child data");
|
2013-08-10 20:06:39 -07:00
|
|
|
// should be cleaned up for us
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2014-04-28 20:36:08 -07:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
// Must work multiple times
|
2014-04-28 20:36:08 -07:00
|
|
|
assert!(my_key.get().unwrap().as_slice() == "parent data");
|
|
|
|
assert!(my_key.get().unwrap().as_slice() == "parent data");
|
|
|
|
assert!(my_key.get().unwrap().as_slice() == "parent data");
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_overwrite() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static my_key: Key<String> = &Key;
|
2014-05-25 03:17:19 -07:00
|
|
|
my_key.replace(Some("first data".to_string()));
|
|
|
|
my_key.replace(Some("next data".to_string())); // Shouldn't leak.
|
2014-04-28 20:36:08 -07:00
|
|
|
assert!(my_key.get().unwrap().as_slice() == "next data");
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_pop() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static my_key: Key<String> = &Key;
|
2014-05-25 03:17:19 -07:00
|
|
|
my_key.replace(Some("weasel".to_string()));
|
|
|
|
assert!(my_key.replace(None).unwrap() == "weasel".to_string());
|
2013-08-10 20:06:39 -07:00
|
|
|
// Pop must remove the data from the map.
|
2014-04-28 20:36:08 -07:00
|
|
|
assert!(my_key.replace(None).is_none());
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_crust_automorestack_memorial_bug() {
|
|
|
|
// This might result in a stack-canary clobber if the runtime fails to
|
|
|
|
// set sp_limit to 0 when calling the cleanup extern - it might
|
|
|
|
// automatically jump over to the rust stack, which causes next_c_sp
|
|
|
|
// to get recorded as something within a rust stack segment. Then a
|
|
|
|
// subsequent upcall (esp. for logging, think vsnprintf) would run on
|
|
|
|
// a stack smaller than 1 MB.
|
2014-05-22 16:57:53 -07:00
|
|
|
static my_key: Key<String> = &Key;
|
2014-01-26 22:42:26 -05:00
|
|
|
task::spawn(proc() {
|
2014-05-25 03:17:19 -07:00
|
|
|
my_key.replace(Some("hax".to_string()));
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_multiple_types() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static str_key: Key<String> = &Key;
|
2013-12-21 17:50:54 -08:00
|
|
|
static box_key: Key<@()> = &Key;
|
|
|
|
static int_key: Key<int> = &Key;
|
2014-01-26 22:42:26 -05:00
|
|
|
task::spawn(proc() {
|
2014-05-25 03:17:19 -07:00
|
|
|
str_key.replace(Some("string data".to_string()));
|
2014-04-28 20:36:08 -07:00
|
|
|
box_key.replace(Some(@()));
|
|
|
|
int_key.replace(Some(42));
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tls_overwrite_multiple_types() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static str_key: Key<String> = &Key;
|
2013-12-21 17:50:54 -08:00
|
|
|
static box_key: Key<@()> = &Key;
|
|
|
|
static int_key: Key<int> = &Key;
|
2014-01-26 22:42:26 -05:00
|
|
|
task::spawn(proc() {
|
2014-05-25 03:17:19 -07:00
|
|
|
str_key.replace(Some("string data".to_string()));
|
|
|
|
str_key.replace(Some("string data 2".to_string()));
|
2014-04-28 20:36:08 -07:00
|
|
|
box_key.replace(Some(@()));
|
|
|
|
box_key.replace(Some(@()));
|
|
|
|
int_key.replace(Some(42));
|
2013-08-10 20:06:39 -07:00
|
|
|
// This could cause a segfault if overwriting-destruction is done
|
|
|
|
// with the crazy polymorphic transmute rather than the provided
|
|
|
|
// finaliser.
|
2014-04-28 20:36:08 -07:00
|
|
|
int_key.replace(Some(31337));
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_fail]
|
|
|
|
fn test_tls_cleanup_on_failure() {
|
2014-05-22 16:57:53 -07:00
|
|
|
static str_key: Key<String> = &Key;
|
2013-12-21 17:50:54 -08:00
|
|
|
static box_key: Key<@()> = &Key;
|
|
|
|
static int_key: Key<int> = &Key;
|
2014-05-25 03:17:19 -07:00
|
|
|
str_key.replace(Some("parent data".to_string()));
|
2014-04-28 20:36:08 -07:00
|
|
|
box_key.replace(Some(@()));
|
2014-01-26 22:42:26 -05:00
|
|
|
task::spawn(proc() {
|
2014-05-25 03:17:19 -07:00
|
|
|
str_key.replace(Some("string data".to_string()));
|
2014-04-28 20:36:08 -07:00
|
|
|
box_key.replace(Some(@()));
|
|
|
|
int_key.replace(Some(42));
|
2013-10-21 13:08:31 -07:00
|
|
|
fail!();
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-08-10 20:06:39 -07:00
|
|
|
// Not quite nondeterministic.
|
2014-04-28 20:36:08 -07:00
|
|
|
int_key.replace(Some(31337));
|
2013-10-21 13:08:31 -07:00
|
|
|
fail!();
|
2012-09-19 17:29:54 -07:00
|
|
|
}
|
2013-05-07 13:53:25 -07:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
#[test]
|
|
|
|
fn test_static_pointer() {
|
2013-12-21 17:50:54 -08:00
|
|
|
static key: Key<&'static int> = &Key;
|
2013-08-10 20:06:39 -07:00
|
|
|
static VALUE: int = 0;
|
2014-04-28 20:36:08 -07:00
|
|
|
key.replace(Some(&VALUE));
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2013-07-11 00:19:23 -07:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
#[test]
|
|
|
|
fn test_owned() {
|
2014-05-05 18:56:44 -07:00
|
|
|
static key: Key<Box<int>> = &Key;
|
2014-04-28 20:36:08 -07:00
|
|
|
key.replace(Some(box 1));
|
|
|
|
|
|
|
|
{
|
|
|
|
let k1 = key.get().unwrap();
|
|
|
|
let k2 = key.get().unwrap();
|
|
|
|
let k3 = key.get().unwrap();
|
|
|
|
assert_eq!(**k1, 1);
|
|
|
|
assert_eq!(**k2, 1);
|
|
|
|
assert_eq!(**k3, 1);
|
|
|
|
}
|
|
|
|
key.replace(Some(box 2));
|
|
|
|
assert_eq!(**key.get().unwrap(), 2);
|
2013-07-16 17:20:43 -07:00
|
|
|
}
|
2013-07-12 01:38:44 -07:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
#[test]
|
|
|
|
fn test_same_key_type() {
|
|
|
|
static key1: Key<int> = &Key;
|
|
|
|
static key2: Key<int> = &Key;
|
|
|
|
static key3: Key<int> = &Key;
|
|
|
|
static key4: Key<int> = &Key;
|
|
|
|
static key5: Key<int> = &Key;
|
2014-04-28 20:36:08 -07:00
|
|
|
key1.replace(Some(1));
|
|
|
|
key2.replace(Some(2));
|
|
|
|
key3.replace(Some(3));
|
|
|
|
key4.replace(Some(4));
|
|
|
|
key5.replace(Some(5));
|
|
|
|
|
|
|
|
assert_eq!(*key1.get().unwrap(), 1);
|
|
|
|
assert_eq!(*key2.get().unwrap(), 2);
|
|
|
|
assert_eq!(*key3.get().unwrap(), 3);
|
|
|
|
assert_eq!(*key4.get().unwrap(), 4);
|
|
|
|
assert_eq!(*key5.get().unwrap(), 5);
|
2013-08-10 20:06:39 -07:00
|
|
|
}
|
2013-07-16 17:20:43 -07:00
|
|
|
|
2013-08-10 20:06:39 -07:00
|
|
|
#[test]
|
|
|
|
#[should_fail]
|
|
|
|
fn test_nested_get_set1() {
|
|
|
|
static key: Key<int> = &Key;
|
2014-04-28 20:36:08 -07:00
|
|
|
key.replace(Some(4));
|
2013-07-16 17:20:43 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
let _k = key.get();
|
|
|
|
key.replace(Some(4));
|
2013-07-16 17:20:43 -07:00
|
|
|
}
|
|
|
|
}
|