2017-10-05 22:09:58 +00:00
|
|
|
//
|
|
|
|
// CSBestEffortUpdater.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 16/06/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2017-10-05 22:09:58 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "CSBestEffortUpdater.h"
|
|
|
|
|
|
|
|
#include "BestEffortUpdater.hpp"
|
|
|
|
|
|
|
|
struct UpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate {
|
|
|
|
__weak id<CSBestEffortUpdaterDelegate> delegate;
|
|
|
|
NSLock *delegateLock;
|
|
|
|
|
2018-03-22 02:18:13 +00:00
|
|
|
void update(Concurrency::BestEffortUpdater *updater, Time::Seconds cycles, bool did_skip_previous_update) {
|
2017-10-05 22:09:58 +00:00
|
|
|
[delegateLock lock];
|
2018-02-19 21:48:03 +00:00
|
|
|
__weak id<CSBestEffortUpdaterDelegate> delegateCopy = delegate;
|
2017-10-05 22:09:58 +00:00
|
|
|
[delegateLock unlock];
|
2018-02-19 21:48:03 +00:00
|
|
|
|
2018-03-22 02:18:13 +00:00
|
|
|
[delegateCopy bestEffortUpdater:nil runForInterval:(NSTimeInterval)cycles didSkipPreviousUpdate:did_skip_previous_update];
|
2017-10-05 22:09:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@implementation CSBestEffortUpdater {
|
|
|
|
Concurrency::BestEffortUpdater _updater;
|
|
|
|
UpdaterDelegate _updaterDelegate;
|
|
|
|
NSLock *_delegateLock;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
self = [super init];
|
|
|
|
if(self) {
|
|
|
|
_delegateLock = [[NSLock alloc] init];
|
|
|
|
_updaterDelegate.delegateLock = _delegateLock;
|
|
|
|
_updater.set_delegate(&_updaterDelegate);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-02-20 00:54:18 +00:00
|
|
|
//- (void)dealloc {
|
|
|
|
// _updater.flush();
|
|
|
|
//}
|
2017-10-05 22:09:58 +00:00
|
|
|
|
|
|
|
- (void)update {
|
|
|
|
_updater.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)flush {
|
|
|
|
_updater.flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDelegate:(id<CSBestEffortUpdaterDelegate>)delegate {
|
|
|
|
[_delegateLock lock];
|
|
|
|
_updaterDelegate.delegate = delegate;
|
|
|
|
[_delegateLock unlock];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id<CSBestEffortUpdaterDelegate>)delegate {
|
|
|
|
id<CSBestEffortUpdaterDelegate> delegate;
|
|
|
|
|
|
|
|
[_delegateLock lock];
|
|
|
|
delegate = _updaterDelegate.delegate;
|
|
|
|
[_delegateLock unlock];
|
|
|
|
|
|
|
|
return delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|