0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-30 02:32:43 +01:00

ircd:Ⓜ️ Add nothrow stack to complement head(room).

This commit is contained in:
Jason Volk 2018-02-19 19:37:09 -08:00
parent 0f9fe4a712
commit 329b1dc514
2 changed files with 43 additions and 7 deletions

View file

@ -28,9 +28,12 @@ namespace ircd::m
bool exists(const id::room &); bool exists(const id::room &);
// [GET] Current Event suite (non-locking) (one) // [GET] Current Event suite (non-locking) (one)
id::event::buf head(const id::room &, int64_t &); // gives depth id::event::buf head(std::nothrow_t, const id::room &, int64_t &);
id::event::buf head(const id::room &, uint64_t &);
id::event::buf head(std::nothrow_t, const id::room &);
id::event::buf head(const id::room &); id::event::buf head(const id::room &);
int64_t depth(const id::room &); int64_t depth(std::nothrow_t, const id::room &);
uint64_t depth(const id::room &);
// [SET] Lowest-level // [SET] Lowest-level
event::id::buf commit(const room &, json::iov &event, const json::iov &content); event::id::buf commit(const room &, json::iov &event, const json::iov &content);

View file

@ -241,9 +241,9 @@ ircd::m::commit(const room &room,
}; };
int64_t depth; int64_t depth;
const auto prev_event_id const m::event::id::buf prev_event_id
{ {
head(room.room_id, depth) head(std::nothrow, room.room_id, depth)
}; };
//TODO: LCOCK //TODO: LCOCK
@ -279,23 +279,56 @@ ircd::m::commit(const room &room,
return m::vm::commit(event, contents); return m::vm::commit(event, contents);
} }
int64_t uint64_t
ircd::m::depth(const id::room &room_id) ircd::m::depth(const id::room &room_id)
{ {
int64_t depth; uint64_t depth;
head(room_id, depth); head(room_id, depth);
return depth; return depth;
} }
int64_t
ircd::m::depth(std::nothrow_t,
const id::room &room_id)
{
int64_t depth;
head(std::nothrow, room_id, depth);
return depth;
}
ircd::m::id::event::buf ircd::m::id::event::buf
ircd::m::head(const id::room &room_id) ircd::m::head(const id::room &room_id)
{ {
int64_t depth; uint64_t depth;
return head(room_id, depth); return head(room_id, depth);
} }
ircd::m::id::event::buf
ircd::m::head(std::nothrow_t,
const id::room &room_id)
{
int64_t depth;
return head(std::nothrow, room_id, depth);
}
ircd::m::id::event::buf ircd::m::id::event::buf
ircd::m::head(const id::room &room_id, ircd::m::head(const id::room &room_id,
uint64_t &depth)
{
const auto ret
{
head(std::nothrow, room_id, reinterpret_cast<int64_t &>(depth))
};
if(depth == -1)
throw m::NOT_FOUND{};
return ret;
}
ircd::m::id::event::buf
ircd::m::head(std::nothrow_t,
const id::room &room_id,
int64_t &depth) int64_t &depth)
{ {
const auto it const auto it