Skip to content

Add mockable time source - #61

Merged
altonen merged 2 commits into
masterfrom
time
Jan 11, 2022
Merged

Add mockable time source#61
altonen merged 2 commits into
masterfrom
time

Conversation

@altonen

@altonen altonen commented Jan 10, 2022

Copy link
Copy Markdown
Contributor

This PR provides three different example implementations for custom time source:

  • lazy_static! implementation that all systems use and time is queried and modified using common::primitives::time::get()/set()
  • Arc<RwLock<Time>> object that is created in main.rs and then passed on as reference to subsystems
  • Owned Time object where subsystems modify each other's time by issuing a system command (how that's exactly done is TBD and probably outside the scope of this PR)

Let me know what you think. When we've decided on something, I'll convert this to a proper PR.

@altonen

altonen commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

I prefer the lazy_static! way of querying and modifying the time

@altonen
altonen requested a review from royster57 January 10, 2022 11:52
@TheQuantumPhysicist

Copy link
Copy Markdown
Contributor

No RwLock please. Even if we're accepting lazy static, we should just use an atomic i64, where zero means not set, and other values is set. RwLock is a huge performance hit.

@altonen

altonen commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

I'm not 100% sure but I think either an RwLock or a Mutex is required for the first two cases because we want to have a shared mutable state. I'll check if it can be done with an atomic but I doubt it.

@altonen

altonen commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

I was wrong. If we don't use the Time construct as a wrapper for time but use AtomicI64 directly, we can get rid of the locks and still have global mutable state. I added a new example that implements the atomic way of dealing with time for lazy_static!

Comment thread common/src/primitives/atomic.rs Outdated
@altonen
altonen marked this pull request as ready for review January 11, 2022 05:15
@altonen
altonen requested a review from erubboli as a code owner January 11, 2022 05:15
@altonen altonen changed the title Add time source prototypes Add mockable time source Jan 11, 2022
Comment thread common/src/primitives/time.rs Outdated
Additionally, convert P2P to use i64 instead of u64 for the timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants