Ai
4 Star 2 Fork 0

Gitee 极速下载/emojicode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/emojicode/emojicode
克隆/下载
Thread.cpp 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
thbwd 提交于 2018-11-02 17:12 +08:00 . Rename 💈 to 🧵 (#110)
//
// Created by Theo Weidmann on 17.03.18.
//
#include "../runtime/Runtime.h"
#include <mutex>
#include <thread>
namespace s {
class Thread : public runtime::Object<Thread> {
public:
std::thread thread;
};
class Mutex : public runtime::Object<Mutex> {
public:
std::mutex mutex;
};
extern "C" Thread* sThreadNew(runtime::Callable<void> callable) {
auto thread = Thread::init();
callable.retain();
thread->retain();
thread->thread = std::thread([thread, callable]() {
callable();
callable.release();
thread->release();
});
return thread;
}
extern "C" void sThreadJoin(Thread *thread) {
thread->thread.join();
}
extern "C" void sThreadDestruct(Thread *thread) {
thread->~Thread();
}
extern "C" void sThreadDelay(runtime::ClassInfo *, runtime::Integer mcs) {
std::this_thread::sleep_for(std::chrono::microseconds(mcs));
}
extern "C" Mutex* sMutexNew() {
return Mutex::init();
}
extern "C" void sMutexLock(Mutex *mutex) {
mutex->mutex.lock();
}
extern "C" void sMutexTryLock(Mutex *mutex) {
mutex->mutex.try_lock();
}
extern "C" void sMutexUnlock(Mutex *mutex) {
mutex->mutex.unlock();
}
extern "C" void sMutexDestruct(Mutex *mutex) {
mutex->~Mutex();
}
} // namespace s
SET_INFO_FOR(s::Thread, s, 1f9f5)
SET_INFO_FOR(s::Mutex, s, 1f510)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/emojicode.git
git@gitee.com:mirrors/emojicode.git
mirrors
emojicode
emojicode
master

搜索帮助