Skip to content

Commit

Permalink
@synchronized的代替方法 同步锁
Browse files Browse the repository at this point in the history
@synchronized的代替方法 同步锁
  • Loading branch information
Hyosung committed Sep 18, 2014
1 parent 47de331 commit a638da7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ACCommon_Swift/Swift/ACMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ func fImageURLString(text: NSString!) -> NSString {
return "http://app.zontenapp.com.cn/"
}

/**
@synchronized的代替方法 同步锁一

:param: lock 将要锁的对象
:param: closure 要执行的操作
*/
func synced(lock: AnyObject!, closure: () -> ()) {
objc_sync_enter(lock)
closure()
objc_sync_exit(lock)
}

//func synce(closure: () -> ()) {
// let lockQueue = dispatch_queue_create("com.test.LockQueue", nil)
// dispatch_sync(lockQueue, closure)
//}

let kScreenSize : CGSize = UIScreen.mainScreen().bounds.size
let kScreenWidth : CGFloat = CGRectGetWidth(UIScreen.mainScreen().bounds)
let kScreenHeight: CGFloat = CGRectGetHeight(UIScreen.mainScreen().bounds)
Expand Down

0 comments on commit a638da7

Please sign in to comment.