Muvicado HD
Loading...
Searching...
No Matches
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...

#include <VVThreadLoop.h>

Inheritance diagram for VVThreadLoop:
Collaboration diagram for VVThreadLoop:

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) - generalInit
(void) - start
 Spawns a thread and starts executing. If the thread has already been spawned and is executing, doesn't do anything.
(void) - threadCallback
(void) - threadProc
(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.
(float) - 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

float interval
BOOL running
BOOL bail
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.
SEL targetSel

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)

Definition at line 26 of file VVThreadLoop.h.

Method Documentation

◆ generalInit

- (void) generalInit
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithTimeInterval:

- (id) initWithTimeInterval: (float) i

Returns an initialized VVThreadLoop which will call "threadProc" on itself every time it executes, so you should override "threadProc" in your subclass.

◆ initWithTimeInterval:target:selector:

- (id) initWithTimeInterval: (float) i
target: (id) t
selector: (SEL) s 

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.

◆ interval

- (float) interval

The interval between executions, in seconds.

◆ running

- (BOOL) running

Whether or not the thread loop is running.

◆ setInterval:

- (void) setInterval: (float) i

Set the interval between executions, in seconds.

◆ start

- (void) start

Spawns a thread and starts executing. If the thread has already been spawned and is executing, doesn't do anything.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop

- (void) stop

Stops execution by setting a "bail" flag, and returns immediately. IMPORTANT: may return while the thread loop is still executing!

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopAndWaitUntilDone

- (void) stopAndWaitUntilDone

Stops execution and doesn't return until the thread's done executing and has been closed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ threadCallback

- (void) threadCallback
Here is the call graph for this function:
Here is the caller graph for this function:

◆ threadProc

- (void) threadProc
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ bail

- (BOOL) bail
protected

Definition at line 29 of file VVThreadLoop.h.

◆ interval

- (float) interval
protected

Definition at line 27 of file VVThreadLoop.h.

◆ running

- (BOOL) running
protected

Definition at line 28 of file VVThreadLoop.h.

◆ targetObj

- (id) targetObj
protected

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.

Definition at line 31 of file VVThreadLoop.h.

◆ targetSel

- (SEL) targetSel
protected

Definition at line 32 of file VVThreadLoop.h.


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