This is the first step in turning the worker mechanism and everything around it into a set of C++ classes. In this change, the original C API is still present, but in subsequent changes that will be removed.