Loading src/backend.cpp +5 −19 Original line number Diff line number Diff line Loading @@ -146,33 +146,19 @@ static thread_local authdb::AuthBackend::LockMode _guard_locked_mode; authdb::AuthBackend::Guard::Guard(AuthBackend &backend, LockMode mode) : _Backend(backend), _Mode(mode), _Owns(false), _Upgraded(false){ if(_guard_locked_backend == &backend){ if(mode == Exclusive && _guard_locked_mode == Shared){ _Backend.unlock_shared(); _Backend.lock(); _guard_locked_mode = Exclusive; _Upgraded = true; } // Since we always acquire Exclusive lock now, // nested locks on the same backend are a no-op. } else { if(_Mode == Exclusive) _Backend.lock(); else _Backend.lock_shared(); _guard_locked_backend = &backend; _guard_locked_mode = mode; _guard_locked_mode = Exclusive; _Owns = true; } } authdb::AuthBackend::Guard::~Guard(){ if(_Upgraded){ _Backend.unlock(); _Backend.lock_shared(); _guard_locked_mode = Shared; } else if(_Owns){ if(_Mode == Exclusive) if(_Owns){ _Backend.unlock(); else _Backend.unlock_shared(); _guard_locked_backend = nullptr; } } Loading src/backends/file.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -191,6 +191,8 @@ void authdb::File::read(unsigned char* src, size_t srcsize){ int rd=::read(_FileDes,src+pos,srcsize); if(rd<0){ throw AuthBackendError("could not read file!"); }else if(rd==0){ throw AuthBackendError("unexpected end of file!"); } pos+=rd; srcsize-=rd; Loading Loading @@ -232,6 +234,8 @@ void authdb::File::write(const unsigned char* dest, size_t destsize){ int wr = ::write(_FileDes,dest+pos,destsize); if(wr<0){ throw AuthBackendError("could not write file!"); }else if(wr==0){ throw AuthBackendError("write failed: no bytes written"); } pos+=wr; destsize-=wr; Loading Loading
src/backend.cpp +5 −19 Original line number Diff line number Diff line Loading @@ -146,33 +146,19 @@ static thread_local authdb::AuthBackend::LockMode _guard_locked_mode; authdb::AuthBackend::Guard::Guard(AuthBackend &backend, LockMode mode) : _Backend(backend), _Mode(mode), _Owns(false), _Upgraded(false){ if(_guard_locked_backend == &backend){ if(mode == Exclusive && _guard_locked_mode == Shared){ _Backend.unlock_shared(); _Backend.lock(); _guard_locked_mode = Exclusive; _Upgraded = true; } // Since we always acquire Exclusive lock now, // nested locks on the same backend are a no-op. } else { if(_Mode == Exclusive) _Backend.lock(); else _Backend.lock_shared(); _guard_locked_backend = &backend; _guard_locked_mode = mode; _guard_locked_mode = Exclusive; _Owns = true; } } authdb::AuthBackend::Guard::~Guard(){ if(_Upgraded){ _Backend.unlock(); _Backend.lock_shared(); _guard_locked_mode = Shared; } else if(_Owns){ if(_Mode == Exclusive) if(_Owns){ _Backend.unlock(); else _Backend.unlock_shared(); _guard_locked_backend = nullptr; } } Loading
src/backends/file.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -191,6 +191,8 @@ void authdb::File::read(unsigned char* src, size_t srcsize){ int rd=::read(_FileDes,src+pos,srcsize); if(rd<0){ throw AuthBackendError("could not read file!"); }else if(rd==0){ throw AuthBackendError("unexpected end of file!"); } pos+=rd; srcsize-=rd; Loading Loading @@ -232,6 +234,8 @@ void authdb::File::write(const unsigned char* dest, size_t destsize){ int wr = ::write(_FileDes,dest+pos,destsize); if(wr<0){ throw AuthBackendError("could not write file!"); }else if(wr==0){ throw AuthBackendError("write failed: no bytes written"); } pos+=wr; destsize-=wr; Loading