Utilities.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 
40 #ifndef Included_Utilities
41 #define Included_Utilities
42 
43 #include <rexx.h>
44 #include <sys/types.h>
45 #include <stdarg.h>
46 
47 #ifdef __REXX64__
48 #define CONCURRENCY_TRACE "%16.16x %16.16x %16.16x %5.5hu%c "
49 #else
50 #define CONCURRENCY_TRACE "%8.8x %8.8x %8.8x %5.5hu%c "
51 #endif
52 
53 #define CONCURRENCY_BUFFER_SIZE 100 // Must be enough to support CONCURRENCY_TRACE
54 
55 
56 // For concurrency trace
57 class RexxActivity;
58 class RexxActivation;
61 {
66  unsigned short reserveCount;
67  char lock;
68 };
69 
70 // Can't include RexxActivation.hpp to call the function GetConcurrencyInfos
71 // A pointer to this function will be passed during the initialization of the interpreter.
72 typedef void (*ConcurrencyInfosCollector) (struct ConcurrencyInfos &concurrencyInfos);
73 
74 
75 class Utilities
76 {
77 public:
78  static int strCaselessCompare(const char *opt1, const char *opt2);
79  static int memicmp(const void *opt1, const void *opt2, size_t len);
80  static void strupper(char *str);
81  static void strlower(char *str);
82  static const char *strnchr(const char *, size_t n, char ch);
83  static const char *locateCharacter(const char *s, const char *set, size_t l);
84  static int vsnprintf(char *buffer, size_t count, const char *format, va_list args);
85  static int snprintf(char *buffer, size_t count, const char *format, ...);
86  static wholenumber_t currentThreadId(); // Could be in SysThread.hpp, but for the moment, it's here...
87  static void traceConcurrency(bool);
88  static bool traceConcurrency();
89  static void traceParsing(bool);
90  static bool traceParsing();
91 
92  // For concurrency trace
94  static void GetConcurrencyInfos(struct ConcurrencyInfos &concurrencyInfos);
95 };
96 
97 #endif
98 
void(* ConcurrencyInfosCollector)(struct ConcurrencyInfos &concurrencyInfos)
Definition: Utilities.hpp:72
static void SetConcurrencyInfosCollector(ConcurrencyInfosCollector)
Definition: Utilities.cpp:55
static const char * locateCharacter(const char *s, const char *set, size_t l)
Definition: Utilities.cpp:72
static void GetConcurrencyInfos(struct ConcurrencyInfos &concurrencyInfos)
Definition: Utilities.cpp:61
static const char * strnchr(const char *, size_t n, char ch)
Definition: Utilities.cpp:192
static void strupper(char *str)
Definition: Utilities.cpp:152
static wholenumber_t currentThreadId()
static bool traceConcurrency()
static void strlower(char *str)
Definition: Utilities.cpp:171
static bool traceParsing()
static int strCaselessCompare(const char *opt1, const char *opt2)
Definition: Utilities.cpp:102
static int memicmp(const void *opt1, const void *opt2, size_t len)
Definition: Utilities.cpp:127
static int vsnprintf(char *buffer, size_t count, const char *format, va_list args)
static int snprintf(char *buffer, size_t count, const char *format,...)
ssize_t wholenumber_t
Definition: rexx.h:230
RexxVariableDictionary * variableDictionary
Definition: Utilities.hpp:65
RexxActivation * activation
Definition: Utilities.hpp:64
unsigned short reserveCount
Definition: Utilities.hpp:66
RexxActivity * activity
Definition: Utilities.hpp:63
wholenumber_t threadId
Definition: Utilities.hpp:62