1 |
nigel |
1.1 |
// |
2 |
|
|
// NNThread.h -Not Nextstep Thread? |
3 |
|
|
// Nigel's Nice Thread? |
4 |
|
|
// |
5 |
nigel |
1.2 |
// Revision 1.2, Tuesday May 25 2004 |
6 |
nigel |
1.1 |
// |
7 |
|
|
// Created by Nigel Pearson on Tue Nov 28 2000. |
8 |
|
|
// Public Domain. No rights reserved. |
9 |
|
|
// |
10 |
|
|
|
11 |
|
|
// Define what flavour of threading to use: |
12 |
|
|
#define USE_NSTHREAD |
13 |
|
|
//#define USE_PTHREAD |
14 |
|
|
|
15 |
|
|
#import <Cocoa/Cocoa.h> |
16 |
|
|
|
17 |
|
|
#import <mach/mach.h> |
18 |
|
|
#import <mach/kern_return.h> |
19 |
|
|
|
20 |
|
|
#ifdef USE_PTHREAD |
21 |
|
|
#include <pthread.h> |
22 |
|
|
|
23 |
|
|
struct pthreadArgs // This duplicates most of the stuff in the NNThread object |
24 |
|
|
{ |
25 |
|
|
id *object; |
26 |
|
|
SEL *sel; |
27 |
|
|
|
28 |
|
|
NSAutoreleasePool *pool; |
29 |
|
|
BOOL allocPool, |
30 |
|
|
*completed; |
31 |
|
|
}; |
32 |
|
|
#endif |
33 |
|
|
|
34 |
|
|
@interface NNThread : NSObject |
35 |
|
|
{ |
36 |
|
|
id object; |
37 |
|
|
SEL sel; |
38 |
|
|
thread_t machThread; |
39 |
|
|
#ifdef USE_PTHREAD |
40 |
|
|
pthread_t pThread; |
41 |
|
|
struct pthreadArgs pthreadArgs; |
42 |
|
|
#endif |
43 |
|
|
NSAutoreleasePool *pool; |
44 |
|
|
BOOL allocPool, |
45 |
|
|
completed, |
46 |
|
|
suspended; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
- (NNThread *) initWithAutoReleasePool; |
50 |
|
|
- (NNThread *) initSuspended: (BOOL) startSuspended |
51 |
|
|
withAutoreleasePool: (BOOL) allocatePool; |
52 |
|
|
|
53 |
|
|
- (void) perform: (SEL)action of: (id)receiver; |
54 |
|
|
- (void) resume; |
55 |
|
|
- (BOOL) start; |
56 |
|
|
- (void) suspend; |
57 |
|
|
- (void) terminate; |
58 |
|
|
|
59 |
|
|
@end |
60 |
|
|
|
61 |
|
|
typedef enum _NNTimeUnits |
62 |
|
|
{ |
63 |
|
|
NNnanoSeconds = 1, |
64 |
|
|
NNmicroSeconds = 2, |
65 |
|
|
NNmilliSeconds = 3, |
66 |
|
|
NNseconds = 4 |
67 |
|
|
} |
68 |
|
|
NNTimeUnits; |
69 |
|
|
|
70 |
|
|
#import <sys/time.h> |
71 |
|
|
|
72 |
|
|
@interface NNTimer : NNThread |
73 |
|
|
{ |
74 |
|
|
struct timespec delay; |
75 |
|
|
BOOL repeating; |
76 |
|
|
id timerObject; |
77 |
|
|
SEL timerSel; |
78 |
|
|
} |
79 |
|
|
|
80 |
nigel |
1.2 |
- (NNTimer *) initWithAutoRelPool; |
81 |
|
|
|
82 |
nigel |
1.1 |
- (void) changeIntervalTo: (int)number units: (NNTimeUnits)units; |
83 |
|
|
- (void) invalidate; |
84 |
|
|
|
85 |
|
|
- (void) perform: (SEL)action of: (id)receiver |
86 |
|
|
after: (int)number units: (NNTimeUnits)units; |
87 |
|
|
|
88 |
|
|
- (void) repeat: (SEL)action of: (id)receiver |
89 |
|
|
every: (int)number units: (NNTimeUnits)units; |
90 |
|
|
|
91 |
|
|
@end |