vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
Instance Methods | Protected Attributes
VVThreadLoop Class Reference

Simple class for spawning a thread which executes at a specified interval- simpler and easier to work with than NSThread/NSTimer in multi-threaded programming environments. More...

#import <VVThreadLoop.h>

Inherits NSObject.

Inherited by RenderThread.

Instance Methods

(id) - initWithTimeInterval:target:selector:
 Returns an initialized VVThreadLoop which will call method "s" on target "t" every time it executes. Returns nil if passed a nil target or selector, or if the target doesn't respond to the selector.
 
(id) - initWithTimeInterval:
 Returns an initialized VVThreadLoop which will call "threadProc" on itself every time it executes, so you should override "threadProc" in your subclass.
 
(void) - start
 Spawns a thread and starts executing. If the thread has already been spawned and is executing, doesn't do anything.
 
(void) - pause
 Pauses/resumes execution. The thread will still be running at the configured interval- that's what differentiates pause/resume from start/stop- but the target/selector won't be getting called.
 
(void) - stop
 Stops execution by setting a "bail" flag, and returns immediately. IMPORTANT: may return while the thread loop is still executing!
 
(void) - stopAndWaitUntilDone
 Stops execution and doesn't return until the thread's done executing and has been closed.
 
(double) - interval
 The interval between executions, in seconds.
 
(void) - setInterval:
 Set the interval between executions, in seconds.
 
(BOOL) - running
 Whether or not the thread loop is running.
 

Protected Attributes

id targetObj
 NOT retained! If there's no valid target obj/sel pair, the instance sill simply call "threadProc" on itself, so you can just override that method.
 

Detailed Description

Simple class for spawning a thread which executes at a specified interval- simpler and easier to work with than NSThread/NSTimer in multi-threaded programming environments.

When started, an instance of this class will spawn a thread and repeatedly execute a method on that thread. If it was passed a target and selector on creation, the selector will be called on the target every time the thread executes. If it's more convenient to subclass VVThreadLoop and work with your custom subclass, leave the target/selector nil and VVThreadLoop will call "threadProc" on itself- just override this method (it's empty anyway) in your subclass and do whatever you want in there.

You can change the execution interval, and VVThreadLoop also examines how long it takes to execute your code and adjusts in an attempt to ensure that the interval is accurate (sleep-time is interval-duration minus proc-execution-duration)


The documentation for this class was generated from the following files: