#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include<toku_portability.h>
#include<toku_pthread.h>
#include<stdbool.h>
#include<stdint.h>
//TODO: update comment, this is from rwlock.h
namespacetoku{
classfrwlock{
public:
voidinit(toku_mutex_t*constmutex);
voiddeinit(void);
inlinevoidwrite_lock(boolexpensive);
inlinebooltry_write_lock(boolexpensive);
inlinevoidwrite_unlock(void);
// returns true if acquiring a write lock will be expensive
inlineboolwrite_lock_is_expensive(void);
inlinevoidread_lock(void);
inlinebooltry_read_lock(void);
inlinevoidread_unlock(void);
// returns true if acquiring a read lock will be expensive
inlineboolread_lock_is_expensive(void);
inlineuint32_tusers(void)const;
inlineuint32_tblocked_users(void)const;
inlineuint32_twriters(void)const;
inlineuint32_tblocked_writers(void)const;
inlineuint32_treaders(void)const;
inlineuint32_tblocked_readers(void)const;
private:
structqueue_item{
toku_cond_t*cond;
structqueue_item*next;
};
inlineboolqueue_is_empty(void)const;
inlinevoidenq_item(queue_item*constitem);
inlinetoku_cond_t*deq_item(void);
inlinevoidmaybe_signal_or_broadcast_next(void);
inlinevoidmaybe_signal_next_writer(void);
toku_mutex_t*m_mutex;
uint32_tm_num_readers;
uint32_tm_num_writers;
uint32_tm_num_want_write;
uint32_tm_num_want_read;
uint32_tm_num_signaled_readers;
// number of writers waiting that are expensive
// MUST be < m_num_want_write
uint32_tm_num_expensive_want_write;
// bool that states if the current writer is expensive
// if there is no current writer, then is false
boolm_current_writer_expensive;
// bool that states if waiting for a read
// is expensive
// if there are currently no waiting readers, then set to false