Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Coding style

Rick Zhou edited this page Oct 25, 2017 · 12 revisions

targeting GCC 4.9, use only C++11 feature, not 14 or 17 features

  • auto keyword is an exception, it's well supported in gcc 4.9

use google style to format the code , already defined in .clang-format file

use smart pointer, avoid doing things in destructor

  • doing this allows us to port the code to other GC based language easily
  • define destructor only when having compiling issue with undefined type (forward-declared only). in this case, define destructor in cc file and use empty function body

carefully design data structure with ref_ type so they can never be accessed in multi-thread

  • the ref_ type is based on boost:intrusive_ptr
  • ref_ type is a smart pointer that's designed for performance but not thread safety
  • anything touching one ref_ must run in same strand, unless:
    • when object is created in one strand/thread and send to other strand at once, the original strand completely forget about the instance
    • in unit test, when knowing at a certain time all code are idle and nothing will read/write the ref_
Clone this wiki locally