⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unix_thread.cpp

📁 彩信浏览器
💻 CPP
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA/*  * @$Id: unix_thread.cpp,v 1.13 2007/02/12 14:15:03 jackjansen Exp $  */#include "ambulant/lib/unix/unix_thread.h"#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <cassert>#undef terminateusing namespace ambulant;lib::unix::thread::thread():	m_exit_requested(false),    m_exit_done(false),	m_running(false),	m_started(false){}lib::unix::thread::~thread(){	if (m_running || (m_started && !m_exit_done))		stop();}bool lib::unix::thread::start(){	if (m_started) return false;	    assert(!m_running);    assert(!m_exit_requested);    assert(!m_exit_done);	m_started = true;	if (pthread_create(&m_thread, NULL, &thread::threadproc, this) < 0 ) {		perror("pthread_create");		abort();		//m_starting = false;	}	return true;}voidlib::unix::thread::stop(){    assert(!m_exit_done);	m_exit_requested = true;	/* TODO: wake thread up */	pthread_join(m_thread, NULL);	m_exit_done = true;}	boollib::unix::thread::terminate(){	// No idea what to do here...	abort();	return false;}	boollib::unix::thread::exit_requested() const{	return m_exit_requested; }boollib::unix::thread::is_running() const{	return m_running;}	voidlib::unix::thread::signal_exit_thread(){	// Don't know how to do this, yet.	abort();}void *lib::unix::thread::threadproc(void *pParam){	thread* p = static_cast<thread*>(pParam);	assert(p->m_started);	assert(!p->m_running);	assert(!p->m_exit_done);	p->m_running = true;	if (!p->m_exit_requested) (void)p->run();	p->m_running = false;	pthread_exit(NULL);	return NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -