📄 osutils.cxx
字号:
/* * osutils.cxx * * Operating System utilities. * * Portable Windows Library * * Copyright (c) 1993-1998 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: osutils.cxx,v $ * Revision 1.233 2005/08/30 06:36:39 csoutheren * Added ability to rotate output logs on a daily basis * * Revision 1.232 2005/03/19 02:52:55 csoutheren * Fix warnings from gcc 4.1-20050313 shapshot * * Revision 1.231 2005/01/31 08:05:40 csoutheren * More patches for MacOSX, thanks to Hannes Friederich * * Revision 1.230 2005/01/26 05:37:59 csoutheren * Added ability to remove config file support * * Revision 1.229 2005/01/04 07:44:03 csoutheren * More changes to implement the new configuration methodology, and also to * attack the global static problem * * Revision 1.228 2004/08/16 06:40:59 csoutheren * Added adapters template to make device plugins available via the abstract factory interface * * Revision 1.227 2004/06/30 12:17:06 rjongbloed * Rewrite of plug in system to use single global variable for all factories to avoid all sorts * of issues with startup orders and Windows DLL multiple instances. * * Revision 1.226 2004/06/03 13:30:58 csoutheren * Renamed INSTANTIATE_FACTORY to avoid potential namespace collisions * Added documentaton on new PINSTANTIATE_FACTORY macro * Added generic form of PINSTANTIATE_FACTORY * * Revision 1.225 2004/06/03 12:47:59 csoutheren * Decomposed PFactory declarations to hopefully avoid problems with Windows DLLs * * Revision 1.224 2004/06/01 05:22:44 csoutheren * Restored memory check functionality * * Revision 1.223 2004/05/23 12:34:38 rjongbloed * Fixed PProcess startup up execution to after PProcess instance is created * so does not crash if using startup technique to initialise tracing. * * Revision 1.222 2004/05/21 00:28:39 csoutheren * Moved PProcessStartup creation to PProcess::Initialise * Added PreShutdown function and called it from ~PProcess to handle PProcessStartup removal * * Revision 1.221 2004/05/18 21:49:25 csoutheren * Added ability to display trace output from program startup via environment * variable or by application creating a PProcessStartup descendant * * Revision 1.220 2004/05/18 12:43:31 csoutheren * Fixed compile problem on MSVC 6 * * Revision 1.219 2004/05/18 06:01:06 csoutheren * Deferred plugin loading until after main has executed by using abstract factory classes * * Revision 1.218 2004/05/18 02:32:09 csoutheren * Fixed linking problems with PGenericFactory classes * * Revision 1.217 2004/05/13 15:05:43 csoutheren * Added <vector.h> * * Revision 1.216 2004/05/13 14:54:57 csoutheren * Implement PProcess startup and shutdown handling using abstract factory classes * * Revision 1.215 2004/04/24 06:27:56 rjongbloed * Fixed GCC 3.4.0 warnings about PAssertNULL and improved recoverability on * NULL pointer usage in various bits of code. * * Revision 1.214 2004/04/12 07:33:46 csoutheren * Temporarily disabled removal of empty TRACE output on Linux * * Revision 1.213 2004/04/03 08:22:21 csoutheren * Remove pseudo-RTTI and replaced with real RTTI * * Revision 1.212 2004/04/03 06:54:29 rjongbloed * Many and various changes to support new Visual C++ 2003 * * Revision 1.211 2004/03/22 10:15:27 rjongbloed * Added classes similar to PWaitAndSignal to automatically unlock a PReadWriteMutex * when goes out of scope. * * Revision 1.210 2004/03/20 09:08:15 rjongbloed * Changed interaction between PTrace and PSystemLog so that the tracing code does * not need to know about the system log, thus reducing the code footprint for most apps. * * Revision 1.209 2003/11/13 21:42:32 csoutheren * Fixed problem with thread name display under Windows thanks to Ted Szoczei * * Revision 1.208 2003/11/08 01:42:19 rjongbloed * Added thread names to DevStudio display, thanks Ted Szoczei * * Revision 1.207 2003/09/17 09:02:14 csoutheren * Removed memory leak detection code * * Revision 1.206 2003/09/17 01:18:03 csoutheren * Removed recursive include file system and removed all references * to deprecated coooperative threading support * * Revision 1.205 2003/07/24 22:01:42 dereksmithies * Add fixes from Peter Nixon for fixing install problems. Thanks. * * Revision 1.204 2003/03/27 07:27:44 robertj * Added function to get a bunch of arguments as a string array. * * Revision 1.203 2003/01/24 10:21:06 robertj * Fixed issues in RTEMS support, thanks Vladimir Nesic * * Revision 1.202 2002/12/18 05:31:31 robertj * Moved PTimeInterval::GetInterval() to common code. * * Revision 1.201 2002/12/11 03:23:27 robertj * Fixed deadlock in read/write mutex, at price of not having seemless upgrading * of read lock to write lock. There is now a window in which some other * thread may gain write lock from the thread that was trying to upgrade. * * Revision 1.200 2002/12/10 02:39:07 robertj * Avoid odd trace output to stderr before trace file is set. * * Revision 1.199 2002/10/09 00:46:19 robertj * Changed PThread::Create() so does not return PThread pointer if the thread * has been created auto-delete, the pointer is extremely dangerous to use * as it could be deleted at any time, so to remove temptation ... * * Revision 1.198 2002/10/08 03:35:15 robertj * Fixed BSD warning * * Revision 1.197 2002/10/04 08:21:26 robertj * Changed read/write mutex so can be called by same thread without deadlock. * * Revision 1.196 2002/07/30 02:55:09 craigs * Added program start time to PProcess * * Revision 1.195 2002/06/27 06:38:58 robertj * Changes to remove memory leak display for things that aren't memory leaks. * * Revision 1.194 2002/06/15 02:16:36 robertj * Fixed bug (from rev 1.190) so can now use PTimer::Reset() after the timer * had previously expired (resetTiem was being zeroed), thanks Ted Szoczei * * Revision 1.193 2002/06/05 12:29:15 craigs * Changes for gcc 3.1 * * Revision 1.192 2002/06/04 00:25:31 robertj * Fixed incorrectly initialised trace indent, thanks Artis Kugevics * * Revision 1.191 2002/05/31 04:10:44 robertj * Fixed missing mutex in PTrace::SetStream, thanks Federico Pinna * * Revision 1.190 2002/05/28 13:05:26 robertj * Fixed PTimer::SetInterval so it restarts timer as per operator=() * * Revision 1.189 2002/05/22 00:42:03 craigs * Added GMTTime flag to tracing options * * Revision 1.188 2002/05/01 03:45:09 robertj * Added initialisation of PreadWriteMutex and changed slightly to agree * with the text book definition of a semaphore for one of the mutexes. * * Revision 1.187 2002/04/30 06:21:38 robertj * Fixed PReadWriteMutex class to implement text book algorithm! * * Revision 1.186 2002/04/30 03:39:21 robertj * Changed PTimer::Stop() so does not return until timer is REALLY stopped, in * particular when a possibly executing OnTimeout() function has completed. * * Revision 1.185 2002/04/24 01:19:07 robertj * Added milliseconds to PTRACE output timestamp * * Revision 1.184 2002/04/24 01:10:28 robertj * Fixed problem with PTRACE_BLOCK indent level being correct across threads. * * Revision 1.183 2002/04/19 00:43:17 craigs * Fixed problem with file modes * * Revision 1.182 2002/04/19 00:20:31 craigs * Added option to append to log file rather than create anew each time * * Revision 1.181 2002/02/14 05:14:51 robertj * Fixed possible deadlock if a timer is deleted (however indirectly) in the * OnTimeout of another timer. * * Revision 1.180 2002/02/11 04:07:00 robertj * Fixed possibly race condition in PTRACE of first message. Consequence is * that cannot PTRACE until have PProcess, ie before main() is executed. * * Revision 1.179 2002/01/31 08:14:16 robertj * Put back code taken out by GCC 3.0 patch. It really SHOULD be there! * * Revision 1.178 2002/01/26 23:57:45 craigs * Changed for GCC 3.0 compatibility, thanks to manty@manty.net * * Revision 1.177 2002/01/26 15:04:44 yurik * Fixed trace stream to a file * * Revision 1.176 2001/12/18 23:22:54 robertj * Fixed problem for if excecutable is "renamed" using unix exec() and the * argv0 does not point to executable file. * * Revision 1.175 2001/12/15 04:49:17 robertj * Added stream I/O functions for argument list. * * Revision 1.174 2001/12/14 00:42:56 robertj * Fixed unix compatibility with trace of threads not created by pwlib. * * Revision 1.173 2001/12/13 09:21:43 robertj * Changed trace so shows thread id if current thread not created by PWLib. * * Revision 1.172 2001/11/30 04:19:26 robertj * Fixed correct setting of option bits in PTrace::Initialise() * Added date and time to first message in PTrace::Initialise() * * Revision 1.171 2001/11/14 06:06:26 robertj * Added functions on PTimer to get reset value and restart timer to it. * * Revision 1.170 2001/10/15 00:48:02 robertj * Fixed warning on later MSVC compilers. * * Revision 1.169 2001/09/03 08:08:31 robertj * Added tab so get extra "column" in trace output. * * Revision 1.168 2001/08/20 06:56:47 robertj * Fixed memory leak report which isn't a memory leak. * * Revision 1.167 2001/07/20 04:14:19 robertj * Removed GNU warning. * * Revision 1.166 2001/05/29 02:50:56 robertj * Fixed GNU compatibility * * Revision 1.165 2001/05/29 00:49:18 robertj * Added ability to put in a printf %x in thread name to get thread object * address into user settable thread name. * * Revision 1.164 2001/05/03 06:26:22 robertj * Fixed strange problem that occassionally crashes on exit. Mutex cannot be * destroyed before program exit. * * Revision 1.163 2001/04/27 01:05:26 yurik * Exit crash removal try * * Revision 1.162 2001/04/15 03:39:24 yurik * Removed shutdown flag. Use IsTerminated() instead * * Revision 1.161 2001/04/14 04:53:01 yurik * Got rid of init_seg pragma and added process shutdown flag * * Revision 1.160 2001/03/23 20:28:54 yurik * Got rid of pragma warning for WinCE port * * Revision 1.159 2001/03/09 05:50:48 robertj * Added ability to set default PConfig file or path to find it. * * Revision 1.158 2001/03/02 22:29:08 yurik * New pragma for WinCE related port which enables (de)construction of library static objects be before applications' * Eliminated nasty access violation stemmed from using static PMutex object in PTrace code. Thanks to Yuriy Gorvitovskiy. * * Revision 1.157 2001/02/22 22:31:44 robertj * Changed PProcess version display to show build number even if zero. * * Revision 1.156 2001/02/22 08:16:42 robertj * Added standard trace file setup subroutine. * * Revision 1.155 2001/02/19 03:44:20 robertj * Changed "pl" in version number string to a simple ".", Now like 1.1.19 * * Revision 1.154 2001/01/28 00:53:00 yurik * WinCE port-related - streams refined * * Revision 1.153 2001/01/25 07:14:39 robertj * Fixed spurios memory leak message. Usual static global problem. * * Revision 1.152 2001/01/24 18:27:44 yurik * Added if !#defined WinCE when asm code used. Asm can't be used under WCE * * Revision 1.151 2001/01/02 07:47:44 robertj * Fixed very narrow race condition in timers (destroyed while in OnTimeout()). * * Revision 1.150 2000/12/21 12:37:03 craigs * Fixed deadlock problem with creating PTimer inside OnTimeout * * Revision 1.149 2000/11/28 12:55:37 robertj * Added static function to create a new thread class and automatically * run a function on another class in the context of that thread. * * Revision 1.148 2000/10/20 05:31:32 robertj * Added function to change auto delete flag on a thread. * * Revision 1.147 2000/08/31 01:12:36 robertj * Fixed problem with no new lines in trace output to stderr. * * Revision 1.146 2000/08/30 05:56:07 robertj * Fixed free running timers broken by previous change. * * Revision 1.145 2000/08/30 03:17:00 robertj * Improved multithreaded reliability of the timers under stress. * * Revision 1.144 2000/06/26 11:17:20 robertj * Nucleus++ port (incomplete). * * Revision 1.143 2000/06/26 09:27:16 robertj * Added ability to get at the PTraceStream without timestamps etc, use UINT_MAX trace level. * * Revision 1.142 2000/06/02 01:38:07 craigs * Fixed typos * * Revision 1.141 2000/06/02 01:35:56 craigs * Added more guards for NULL PStrings in PConfigArg handling * * Revision 1.140 2000/05/25 14:45:07 robertj * Fixed detection of real argument over configured value. * * Revision 1.139 2000/05/25 13:47:51 robertj * Fixed warning with GNU. * * Revision 1.138 2000/05/25 11:05:55 robertj * Added PConfigArgs class so can save program arguments to config files. * * Revision 1.137 2000/05/05 10:08:29 robertj * Fixed some GNU compiler warnings * * Revision 1.136 2000/04/28 06:58:50 robertj * Fixed bug introduced when added Ashley Untts fix, forgot to take out old code! * * Revision 1.135 2000/04/27 04:19:27 robertj * Fixed bug in restarting free running timers, thanks Ashley Unitt. * * Revision 1.134 2000/04/03 18:42:40 robertj * Added function to determine if PProcess instance is initialised. * * Revision 1.133 2000/03/29 20:12:00 robertj * Fixed GNU C++ warning * * Revision 1.132 2000/03/29 01:55:52 robertj * Fixed infinite recursion on PProcess::Current() = NULL assertion. * * Revision 1.131 2000/03/02 05:43:12 robertj * Fixed handling of NULL pointer on current thread in PTRACE output. * * Revision 1.130 2000/02/29 12:26:14 robertj * Added named threads to tracing, thanks to Dave Harvey * * Revision 1.129 2000/02/17 11:34:28 robertj * Changed PTRACE output to help line up text after filename output. * * Revision 1.128 2000/01/06 14:09:42 robertj * Fixed problems with starting up timers,losing up to 10 seconds * * Revision 1.127 1999/10/19 09:21:30 robertj * Added functions to get current trace options and level. * * Revision 1.126 1999/10/14 08:08:27 robertj * Fixed problem, assuring millisecond accuracy in timestamp of trace output. * * Revision 1.125 1999/09/14 13:02:52 robertj * Fixed PTRACE to PSYSTEMLOG conversion problem under Unix. * * Revision 1.124 1999/09/13 13:15:07 robertj * Changed PTRACE so will output to system log in PServiceProcess applications. * * Revision 1.123 1999/08/22 12:54:35 robertj * Fixed warnings about inlines on older GNU compiler * * Revision 1.122 1999/06/23 14:19:46 robertj * Fixed core dump problem with SIGINT/SIGTERM terminating process. * * Revision 1.121 1999/06/14 07:59:38 robertj * Enhanced tracing again to add options to trace output (timestamps etc). * * Revision 1.120 1999/04/26 08:06:51 robertj * Added missing function in cooperative threading. * * Revision 1.119 1999/03/01 13:51:30 craigs * Fixed ugly little bug in the cooperative multithreading that meant that threads blocked * on timers didn't always get rescheduled. * * Revision 1.118 1999/02/23 10:13:31 robertj * Changed trace to only diplay filename and not whole path. * * Revision 1.117 1999/02/23 07:11:27 robertj * Improved trace facility adding trace levels and #define to remove all trace code. * * Revision 1.116 1998/11/30 12:45:54 robertj * Fissioned into pchannel.cxx and pconfig.cxx * * Revision 1.115 1998/11/24 01:17:33 robertj * Type discrepency between declaration and definition for PFile::SetPosition * * Revision 1.114 1998/11/06 02:37:53 robertj * Fixed the fix for semaphore timeout race condition. * * Revision 1.113 1998/11/03 10:52:19 robertj * Fixed bug in semaphores with timeout saying timed out when really signalled. * * Revision 1.112 1998/11/03 03:44:05 robertj * Fixed missng strings on multiple parameters of same letter. * * Revision 1.111 1998/11/02 10:13:01 robertj * Removed GNU warning. * * Revision 1.110 1998/11/01 04:56:53 robertj * Added BOOl return value to Parse() to indicate there are parameters available. * * Revision 1.109 1998/10/31 14:02:20 robertj * Removed StartImmediate capability as causes race condition in preemptive version. * * Revision 1.108 1998/10/31 12:47:10 robertj * Added conditional mutex and read/write mutex thread synchronisation objects. * * Revision 1.107 1998/10/30 12:24:15 robertj * Added ability to get all key values as a dictionary. * Fixed warnings in GNU C. * * Revision 1.106 1998/10/30 11:22:15 robertj * Added constructors that take strings as well as const char *'s. * * Revision 1.105 1998/10/30 05:25:09 robertj * Allow user to shift past some arguments before parsing for the first time. * * Revision 1.104 1998/10/29 05:35:17 robertj * Fixed porblem with GetCount() == 0 if do not call Parse() function. * * Revision 1.103 1998/10/28 03:26:43 robertj * Added multi character arguments (-abc style) and options precede parameters mode. * * Revision 1.102 1998/10/28 00:59:49 robertj * New improved argument parsing. * * Revision 1.101 1998/10/19 00:19:59 robertj * Moved error and trace stream functions to common code. * * Revision 1.100 1998/10/18 14:28:45 robertj * Renamed argv/argc to eliminate accidental usage. * * Revision 1.99 1998/10/13 14:06:28 robertj * Complete rewrite of memory leak detection code. * * Revision 1.98 1998/09/24 07:23:54 robertj * Moved structured fiel into separate module so don't need silly implementation file for GNU C. * * Revision 1.97 1998/09/23 06:22:24 robertj * Added open source copyright license. * * Revision 1.96 1998/06/13 15:11:56 robertj * Added stack check in Yield(). * Added immediate schedule of semaphore timeout thread. * * Revision 1.95 1998/05/30 13:28:18 robertj * Changed memory check code so global statics are not included in leak check. * Fixed deadlock in cooperative threading. * Added PSyncPointAck class. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -