Commits

Cliff Biffle committed f7f2adb

KVDepthRecorder is now thread-safe and forces the file to exist before writing.

  • Participants
  • Parent commits 0f04e8d

Comments (0)

Files changed (1)

KVDepthRecorder.m

 @synthesize fileHandle;
 
 - (void) open: (NSString *) path {
-  fileHandle = [NSFileHandle fileHandleForWritingAtPath: path];
+  @synchronized (self) {
+    [[NSFileManager defaultManager] createFileAtPath: path contents: nil attributes: nil];
+    fileHandle = [NSFileHandle fileHandleForWritingAtPath: path];
+  }
 }
 
 - (void) close {
-  NSFileHandle *h = fileHandle;
-  fileHandle = nil;
-  [h closeFile];
+  @synchronized (self) {
+    NSFileHandle *h = fileHandle;
+    fileHandle = nil;
+    [h closeFile];
+  }
 }
 
 - (void) setLatestDepthSamples: (NSData *) data {
-  [fileHandle writeData: data];
-  [fileHandle synchronizeFile];
+  @synchronized (self) {
+    [fileHandle writeData: data];
+  }
 }
 
 - (NSData *) latestDepthSamples {