56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
# You are free to use and/or change this code for
|
|
# your own needs.
|
|
|
|
# Original code (c)2018 Jan Lerking
|
|
# Program to convert C-header (*.h) files to nasm include files (*.inc),
|
|
# for direct usage in assembly programming using nasm/yasm.
|
|
|
|
import multiprocessing
|
|
from queue import Queue
|
|
from threading import Thread
|
|
import threading
|
|
from h2inc_globals import filelist, cnt
|
|
from h2inc_fp import process_file
|
|
|
|
num_cores = multiprocessing.cpu_count()
|
|
|
|
class Worker(Thread):
|
|
def __init__(self, queue):
|
|
Thread.__init__(self)
|
|
self.queue = queue
|
|
|
|
def go(self):
|
|
print("The worker has started doing some work (counting from 0 to 9)")
|
|
#for i in range(self.filecnt):
|
|
#proportion = (float(i+1))/self.filecnt
|
|
#self.queue.put((proportion, "working...", i))
|
|
#time.sleep(0.01)
|
|
#process_file(filelist[i])
|
|
#self.queue.put((1.0, "finished"))
|
|
#print("The worker has finished.")
|
|
while True:
|
|
cfile = self.queue.get()
|
|
process_file(cfile)
|
|
self.queue.task_done()
|
|
|
|
def start_workers():
|
|
print("Creating shared Queue")
|
|
queue = Queue()
|
|
|
|
print("Number of cores:", num_cores)
|
|
|
|
for n in range(num_cores):
|
|
print("Creating Worker", n)
|
|
|
|
worker = Worker(queue)
|
|
worker.deamon = True
|
|
worker.start()
|
|
|
|
for cfile in filelist:
|
|
print("Queueing {}".format(cfile))
|
|
queue.put(cfile)
|
|
|
|
queue.join()
|
|
return
|
|
|