00001 // Copyright (C) 2001 Petter Urkedal (petter.urkedal@matfys.lth.se) 00002 // 00003 // This file is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This file is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software library without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to 00021 // produce an executable, this file does not by itself cause the 00022 // resulting executable to be covered by the GNU General Public 00023 // License. This exception does not however invalidate any other 00024 // reasons why the executable file might be covered by the GNU General 00025 // Public License. 00026 // 00027 // $Id: threadfwd.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $ 00028 00029 00030 #ifndef MORE_CF_THREADFWD_H 00031 #define MORE_CF_THREADFWD_H 00032 00033 #include <more/bits/config.h> 00034 #ifndef MORE_CF_DISABLE_THREADS 00035 # define MORE_CF_WITH_THREADS 1 00036 #endif 00037 00038 namespace more { 00039 namespace cf { 00040 00041 ///\if bits 00042 namespace bits { 00043 // This variable is only modified when there only one thread. 00044 extern bool other_threads; 00045 } 00046 ///\endif 00047 00048 /** True iff the caller is the only thread. This provides a quick 00049 check whether mutex locking is needed. */ 00050 inline bool there_are_only_threads() { return bits::other_threads; } 00051 00052 /** Report that there is one more fereign thread running. By 00053 foreign thread is meant one that is not created by libmore. 00054 This function must be called _before_ the thread is started. If 00055 you run foreign threads and don't want to bother, just call 00056 notify_foreign_thread() once at startup. If you don't need to 00057 access the libmore objects from these foreign threads, you don't 00058 need to call this function at all. */ 00059 void notify_foreign_thread(); 00060 00061 /** Report that there is one less foreign (not created by libmore) 00062 thread running. This must be called _after_ the thread is stopped. */ 00063 void unnotify_foreign_thread(); 00064 00065 }} 00066 #endif