8000 代码规范 · Issue #11 · holdyounger/ScopeBlog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
代码规范 #11
Open
Open
@holdyounger

Description

@holdyounger

代码规范

TrustClient 相关

1) win api使用宏控制

#ifdef Q_OS_WIN
	#include <Windows.h>
#endif

内存相关

函数段

  1. 申请内存
void *zallloc(size_t len) {
    void *p = malloc(len);
    if(p) {
        memset(p, 0, len);
    }
    
    return p;
}

常用的宏

#define safe_free(p) {\
	free(p);\
	p = NULL;\
}\

线程的资源竞争

  1. 链表、边界资源、临界区域的操作一定要<mark style="background-color:red">加锁</mark>
std::mutex mtx; // 保护counter

mtx.lock();

// 要进行的资源操作
todo();

mtx.unlock();

blog link 代码规范

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0