mstorsjo added a comment.

In https://reviews.llvm.org/D38704#892479, @zturner wrote:

> I'm a little nervous about re-inventing a poor man's version of a reader 
> writer lock.  Can we not just copy LLVM's?


I had a closer look at this, and noticed the following:

- The LLVM RWMutex class on windows tries to load the SRW functions 
dynamically, and falls back on a normal critical section otherwise. This init 
procedure doesn't seem to be threadsafe though, but as long as the first 
RWMutex object is initialized before any extra threads are started, we should 
be fine. For libunwind, it would probably be done in a constructor on CRT 
startup.
- Importing this implementation verbatim would require including one header, 3 
implementation files, and probably some CMake hookups.
- Until the LLVM relicensing is done, afaik we can't include code verbatim from 
LLVM into the runtime libs, or did I get this wrong?

If you prefer, it's pretty trivial to do a smaller but similar implementation 
for libunwind though. If we add a new RWMutex class instead of using the 
pthread API (and implementing the windows version behind that API), we can have 
separate unlock methods for read and write mode, getting rid of the ugly 
`lockedForWrite` variable I currently have. And one could have it either just 
use SRW, or try loading SRW dynamically if that's preferred (if one wants to 
spend extra effort on libunwind on pre-vista).

What do you think @zturner?


https://reviews.llvm.org/D38704



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to