waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

excl.py (1535B)


      1 #! /usr/bin/env python
      2 # encoding: utf-8
      3 # Thomas Nagy, 2011-2015 (ita)
      4 
      5 """
      6 Prevents link tasks from executing in parallel. This can be used to
      7 improve the linker execution, which may use a lot of memory.
      8 
      9 The variable 'MAX' represents the tasks able to run
     10 concurrently (just one by default). The variable 'count'
     11 is the amount of tasks of one kind being executed.
     12 
     13 Different constraints can be enforced by changing the scope
     14 of some variables. Remember that:
     15 
     16 * the counter could be set on the class level
     17 * the MAX amount of concurrent tasks can be more than 1
     18 """
     19 
     20 from waflib.Utils import threading
     21 from waflib import Task
     22 lock = threading.Lock()
     23 count = 0
     24 MAX = 1
     25 
     26 def make_exclusive(cls):
     27 
     28 	old_runnable_status = cls.runnable_status
     29 	def runnable_status(self):
     30 		global count, lock, MAX
     31 		ret = Task.ASK_LATER
     32 		if count >= MAX:
     33 			return ret
     34 
     35 		self.m1_excl = getattr(self, 'm1_excl', 0) + 1
     36 		ret = old_runnable_status(self)
     37 		self.m1_excl -= 1
     38 
     39 		if ret == Task.RUN_ME and not self.m1_excl:
     40 			lock.acquire()
     41 			count += 1
     42 			lock.release()
     43 		return ret
     44 	cls.runnable_status = runnable_status
     45 
     46 	old_run = cls.run
     47 	def run(self):
     48 		global count, lock
     49 		try:
     50 			self.m2_excl = getattr(self, 'm2_excl', 0) + 1
     51 			ret = old_run(self)
     52 		finally:
     53 			self.m2_excl -= 1
     54 			if not self.m2_excl:
     55 				lock.acquire()
     56 				count -= 1
     57 				lock.release()
     58 		return ret
     59 	cls.run = run
     60 
     61 for x in 'cprogram cxxprogram cshlib cxxshlib cstlib cxxstlib fcprogram fcshlib fcstlib'.split():
     62 	if x in Task.classes:
     63 		make_exclusive(Task.classes[x])
     64