Permalink
Browse files

Use the 'with' syntax with the libclangLock.

This removes the .acquire() and .release(), and avoid potential lockups
if the code wasn't guarded by try catch.
  • Loading branch information...
Rip-Rip committed Jan 30, 2013
1 parent 3b91672 commit 3968e650d4c3b37b6af31debe8086fd7a5aa4ca1
Showing with 12 additions and 16 deletions.
  1. +12 −16 plugin/libclang.py
View
@@ -320,10 +320,9 @@ def updateCurrentDiagnostics():
timer = CodeCompleteTimer(debug, vim.current.buffer.name, -1, -1, params)
with workingDir(params['cwd']):
libclangLock.acquire()
getCurrentTranslationUnit(params['args'], getCurrentFile(),
vim.current.buffer.name, timer, update = True)
libclangLock.release()
with libclangLock:
getCurrentTranslationUnit(params['args'], getCurrentFile(),
vim.current.buffer.name, timer, update = True)
timer.finish()
def getCurrentCompletionResults(line, column, args, currentFile, fileName,
@@ -401,24 +400,21 @@ def __init__(self, line, column, currentFile, fileName, params, timer):
def run(self):
with workingDir(self.cwd):
try:
libclangLock.acquire()
with libclangLock:
if self.line == -1:
# Warm up the caches. For this it is sufficient to get the current
# translation unit. No need to retrieve completion results.
# This short pause is necessary to allow vim to initialize itself.
# Otherwise we would get: E293: block was not locked
# The user does not see any delay, as we just pause a background thread.
# Warm up the caches. For this it is sufficient to get the
# current translation unit. No need to retrieve completion
# results. This short pause is necessary to allow vim to
# initialize itself. Otherwise we would get: E293: block was
# not locked The user does not see any delay, as we just pause
# a background thread.
time.sleep(0.1)
getCurrentTranslationUnit(self.args, self.currentFile, self.fileName,
self.timer)
else:
self.result = getCurrentCompletionResults(self.line, self.column,
self.args, self.currentFile,
self.fileName, self.timer)
except Exception:
pass
libclangLock.release()
self.args, self.currentFile,
self.fileName, self.timer)
def WarmupCache():
params = getCompileParams(vim.current.buffer.name)

0 comments on commit 3968e65

Please sign in to comment.