Files
hikari_no_yume fa6a5e4010 Move all TestApp definitions of Apple stuff to one file
Change-Id: I8875a0896b2205e25f50cebf71c49c0a20c7fb9c
2025-10-15 22:12:48 +02:00

53 lines
1.1 KiB
Objective-C

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//
// SyncTester.m
// TestApp
//
#include <unistd.h>
#import "SyncTester.h"
#import "system_headers.h"
@implementation SyncTester : NSObject {
}
- (SyncTester *)init {
self = [super init];
self.counter = 0;
self.test_ok = false;
return self;
}
- (BOOL)holdAndCheckCounter {
@synchronized(self) {
self.counter = 0;
for (int i = 0; i < 10; i++) {
usleep(1000);
}
return self.counter == 0;
}
}
- (void)tryModifyCounter {
@synchronized(self) {
self.counter = 1;
}
}
- (void)recursiveSyncEnterWithCount:(int)count {
if (count <= 0) {
self.counter++;
return;
}
@synchronized(self) {
[self recursiveSyncEnterWithCount:(count - 1)];
[self recursiveSyncEnterWithCount:(count - 1)];
}
}
- (void)recursiveSyncEnter {
self.counter = 0;
[self recursiveSyncEnterWithCount:4];
self.test_ok = self.counter == 16;
}
@end