'Ensure the GIL is acquired.
The returned value must be consumed by gil_release().'

def gil_ensure(self):

    gilptrty = Type.pointer(self.gil_state)
    fnty = Type.function(Type.void(), [gilptrty])
    fn = self._get_function(fnty, 'numba_gil_ensure')
    gilptr = cgutils.alloca_once(self.builder, self.gil_state)
    self.builder.call(fn, [gilptr])
    return gilptr
