Directly into the child thread
[Nsthread detachnewthreadselector: @selector (setupimageresampling) totarget:self Withobject:nil];
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_low, 0), ^{
[Nsthread sleepfortimeinterval:.5f];
while ([Device Isadjustingfocus] | |
[Device Isadjustingexposure] | |
[Device isadjustingwhitebalance]);
Dispatch_async (Dispatch_get_main_queue (), ^{
//
Remove focus view and focus Subview animated
//
[Camerafocusview stopanimation];
});
});
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_low, 0), ^{
[Nsthread Sleepfortimeinterval:timeinterval];
Dispatch_async (Dispatch_get_main_queue (), ^{
[Self Removeslidefromsuperview:yes
withduration:.5
Originy:[self Finalposition]
Completion:completion];
});
});
-------------------------
Create a new queue
dispatch_queue_t concurrentqueue =dispatch_get_global_queue (dispatch_queue_priority_default, 0);
Execute Concurrentqueue Queue
Dispatch_async (Concurrentqueue, ^{
__block UIImage *image = nil;
Dispatch_sync (Concurrentqueue, ^{
Assethelper.breverse = YES;
[Assethelper getgrouplist:^ (Nsarray *agroups) {
For (Alassetsgroup *group in agroups) {
NSString *groupname = [group Valueforproperty:alassetsgrouppropertyname];
if ([Album_name Isequaltostring:groupname]) {
flag = YES;
Break
}
nindex++;
}
if (flag) {
[Assethelper getphotolistofgroupbyindex:nindex result:^ (Nsarray *aphotos) {
if ([Aphotos count]>0) {
alasset* Assetphotos = [Aphotos objectatindex:0];
Image = [Assethelper getimagefromasset:assetphotos type:asset_photo_thumbnail];
}
}];
}
}];
});
Dispatch_sync (Dispatch_get_main_queue (), ^{
/* display pictures inside the main thread */
if (image = nil) {
CGRect photoframe = CGRectMake (8,6, _albumbutton.frame.size.width-16, _albumbutton.frame.size.height-16);
Uiimageview *imgview = [[Uiimageview alloc] initwithframe:photoframe];
Imgview.image = image;
[_albumbutton Addsubview:imgview];
} else {
NSLog (@ "Failed to take the last picture from the album. Nothing to display. ");
} });
});
-------------------------
void runonmainqueuewithoutdeadlocking (void (^block) (void))
{
if ([Nsthread Ismainthread])
{
Block ();
}
Else
{
Dispatch_sync (Dispatch_get_main_queue (), block);
}
}
void Runsynchronouslyonvideoprocessingqueue (void (^block) (void))
{
dispatch_queue_t videoprocessingqueue = [Gpuimagecontext sharedcontextqueue];
#if! Os_object_use_objc
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-wdeprecated-declarations"
if (dispatch_get_current_queue () = = Videoprocessingqueue)
#pragma clang diagnostic pop
#else
if (dispatch_get_specific ([Gpuimagecontext Contextkey]))
#endif
{
Block ();
}else
{
Dispatch_sync (videoprocessingqueue, block);
}
}
void Runasynchronouslyonvideoprocessingqueue (void (^block) (void))
{
dispatch_queue_t videoprocessingqueue = [Gpuimagecontext sharedcontextqueue];
#if! Os_object_use_objc
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-wdeprecated-declarations"
if (dispatch_get_current_queue () = = Videoprocessingqueue)
#pragma clang diagnostic pop
#else
if (dispatch_get_specific ([Gpuimagecontext Contextkey]))
#endif
{
Block ();
}else
{
Dispatch_async (videoprocessingqueue, block);
}
}
void Runsynchronouslyoncontextqueue (Gpuimagecontext *context, Void (^block) (void))
{
dispatch_queue_t Videoprocessingqueue = [Context Contextqueue];
#if! Os_object_use_objc
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-wdeprecated-declarations"
if (dispatch_get_current_queue () = = Videoprocessingqueue)
#pragma clang diagnostic pop
#else
if (dispatch_get_specific ([Gpuimagecontext Contextkey]))
#endif
{
Block ();
}else
{
Dispatch_sync (videoprocessingqueue, block);
}
}
void Runasynchronouslyoncontextqueue (Gpuimagecontext *context, Void (^block) (void))
{
dispatch_queue_t Videoprocessingqueue = [Context Contextqueue];
#if! Os_object_use_objc
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-wdeprecated-declarations"
if (dispatch_get_current_queue () = = Videoprocessingqueue)
#pragma clang diagnostic pop
#else
if (dispatch_get_specific ([Gpuimagecontext Contextkey]))
#endif
{
Block ();
}else
{
Dispatch_async (videoprocessingqueue, block);
}
}
void Reportavailablememoryforgpuimage (NSString *tag)
{
if (!tag)
Tag = @ "Default";
struct Task_basic_info info;
mach_msg_type_number_t size = sizeof (info);
kern_return_t Kerr = Task_info (Mach_task_self (),
Task_basic_info,
(task_info_t) &info,
&size);
if (Kerr = = kern_success) {
NSLog (@ "%@-Memory used:%u", tag, (unsigned int) info.resident_size); In bytes
} else {
NSLog (@ "%@-Error:%s", tag, mach_error_string (Kerr));
}
}
IOS UI thread and non-UI thread code collection