Commit b0b02620 authored by gejun's avatar gejun

Patch svn r35084 & remove namespace baidu

Change-Id: Iaae684ff476283a237925fde0477cd75fe36be0d
parent 6d90ab2d
......@@ -16,14 +16,26 @@
namespace base {
// NOTE: This version requires storage in ctor rather than allocating it,
// which is different from DP version.
// Example:
// [Create a on-stack small queue]
// char storage[64];
// base::BoundedQueue<int> q(storage, sizeof(storage), base::NOT_OWN_STORAGE);
// q.push(1);
// q.push(2);
// ...
// [Initialize a class-member queue]
// class Foo {
// ...
// BoundQueue<int> _queue;
// };
// int Foo::init() {
// BoundedQueue<int> tmp(capacity);
// if (!tmp.initialized()) {
// LOG(ERROR) << "Fail to create _queue";
// return -1;
// }
// tmp.swap(_queue);
// }
enum StorageOwnership { OWNS_STORAGE, NOT_OWN_STORAGE };
......@@ -31,16 +43,28 @@ template <typename T>
class BoundedQueue {
public:
// You have to pass the memory for storing items at creation.
// The queue contains at most size / sizeof(T) items.
BoundedQueue(void* spaces, size_t size, StorageOwnership ownership)
// The queue contains at most memsize/sizeof(T) items.
BoundedQueue(void* mem, size_t memsize, StorageOwnership ownership)
: _count(0)
, _cap(size / sizeof(T))
, _cap(memsize / sizeof(T))
, _start(0)
, _ownership(ownership)
, _items(spaces) {
, _items(mem) {
DCHECK(_items);
};
// Construct a queue with the given capacity.
// The malloc() may fail sliently, call initialized() to test validity
// of the queue.
explicit BoundedQueue(size_t capacity)
: _count(0)
, _cap(capacity)
, _start(0)
, _ownership(OWNS_STORAGE)
, _items(malloc(capacity * sizeof(T))) {
DCHECK(_items);
};
BoundedQueue()
: _count(0)
, _cap(0)
......
......@@ -464,7 +464,7 @@ _T* find_lowered_cstr(FlatMap<std::string, _T, _Hash, _Equal, _Sparse>& m,
return m.seek(*tls_stringmap_temp.get_lowered_string(key, length));
}
} // namespace baidu
} // namespace base
#include "base/containers/flat_map_inl.h"
......
......@@ -367,17 +367,6 @@ static int id_create_ranged_impl(
} // namespace bthread
namespace baidu {
namespace bthread {
void id_status(bthread_id_t id, std::ostream& os) {
::bthread::id_status(id, os);
}
void id_pool_status(std::ostream& os) {
::bthread::id_pool_status(os);
}
}
}
extern "C" {
int bthread_id_create(
......
......@@ -917,13 +917,3 @@ void print_task(std::ostream& os, bthread_t tid) {
}
} // namespace bthread
namespace baidu {
namespace bthread {
void print_task(std::ostream& os, bthread_t tid) {
::bthread::print_task(os, tid);
}
extern BAIDU_THREAD_LOCAL void* tls_unique_user_ptr
__attribute__ ((alias ("_ZN7bthread19tls_unique_user_ptrE")));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment