I will try to post my idea of how to solve this shoretly I hope.

Anywhay in my idea you have numerical property which tels you which sprite you need to use for that tile. Since you are afecting this number by changing seperate bits of this numerical variable (each bit represents each side and each corner) there will be no need to use any logical system for constantly figuring out which sides/corners of your current sprite are neighboring to other wall sprite for instance. Since the system uses 8 bit integer (byte) for determining autotile you have 256 posible options for each cell.

Now I'm currently testing different aproaches for changing seperate bits of this numerical variable to see which is best and safest. I'll try to make it thread safe so it can be easily used in multithreading applications.

I hope I will be able to write you full solution example this weekend.