blob: 31d83b5e776a1cdeb7999faa5d95cb74942c3c38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "MCMainThread.h"
#import <Foundation/Foundation.h>
using namespace mailcore;
@interface LEPPPMainThreadCaller : NSObject {
void (* _function)(void *);
void * _context;
}
@property (nonatomic, assign) void (* function)(void *);
@property (nonatomic, assign) void * context;
- (void) call;
@end
@implementation LEPPPMainThreadCaller
@synthesize function = _function;
@synthesize context = _context;
- (void) call
{
_function(_context);
}
@end
void mailcore::callOnMainThread(void (* function)(void *), void * context)
{
LEPPPMainThreadCaller * caller;
caller = [[LEPPPMainThreadCaller alloc] init];
[caller setFunction:function];
[caller setContext:context];
[caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
[caller release];
}
void mailcore::callOnMainThreadAndWait(void (* function)(void *), void * context)
{
LEPPPMainThreadCaller * caller;
caller = [[LEPPPMainThreadCaller alloc] init];
[caller setFunction:function];
[caller setContext:context];
[caller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:YES];
[caller release];
}
void mailcore::callAfterDelay(void (* function)(void *), void * context, double time)
{
LEPPPMainThreadCaller * caller;
caller = [[LEPPPMainThreadCaller alloc] init];
[caller setFunction:function];
[caller setContext:context];
[caller performSelector:@selector(call) withObject:nil afterDelay:time];
[caller release];
}
|