public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
More fixes for Windows. Also changed hash function in libmquark.c.
oleg dashevskii (author)
Sat Mar 01 23:08:22 -0800 2008
commit  8267a97b10968b88617a28b438824ef52ffd1ba8
tree    2ca2a8626f0ca34fc7bec8a5040b62cd07543c7c
parent  5bbea88091dbaa29322f4b10f24301796fa03b17
...
12
13
14
15
16
17
 
 
 
 
 
 
 
 
18
19
...
12
13
14
 
 
 
15
16
17
18
19
20
21
22
23
24
0
@@ -12,8 +12,13 @@ if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86)
0
   set(CMAKE_SYSTEM_PROCESSOR i386)
0
 endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86)
0
 
0
-if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
0
- set(CMAKE_SYSTEM_NAME mswin32)
0
-endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
0
+if(WIN32)
0
+ if(MINGW)
0
+ set(CMAKE_SYSTEM_NAME mingw32)
0
+ else(MINGW)
0
+ set(CMAKE_SYSTEM_NAME mswin32)
0
+ endif(MINGW)
0
+ # TODO: cygwin?
0
+endif(WIN32)
0
 
0
 add_subdirectory(shotgun)
...
70
71
72
73
 
 
 
74
75
76
...
70
71
72
 
73
74
75
76
77
78
0
@@ -70,7 +70,9 @@ message(STATUS "This is a ${WORDSIZE}-bit system")
0
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
0
                ${CMAKE_CURRENT_BINARY_DIR}/config.h)
0
 
0
-add_definitions(-fPIC)
0
+if(NOT MINGW)
0
+ add_definitions(-fPIC)
0
+endif(NOT MINGW)
0
 
0
 # external stuff
0
 
...
41
42
43
44
 
45
46
47
...
41
42
43
 
44
45
46
47
0
@@ -41,7 +41,7 @@
0
 #include <stdlib.h>
0
 #include <assert.h>
0
 
0
-#ifndef WIN32
0
+#if !defined(WIN32) || defined(__MINGW32__)
0
 # include <sys/time.h>
0
 #endif
0
 
...
1
 
 
 
 
 
 
2
3
4
...
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
 
16
17
18
 
19
20
21
22
23
24
25
 
 
 
 
 
 
26
 
27
28
29
30
31
32
33
34
35
...
46
47
48
49
 
50
51
52
53
54
55
 
56
57
58
59
60
61
62
 
63
64
65
66
67
 
68
69
70
71
72
73
74
 
75
76
77
78
79
80
 
81
82
83
84
85
86
 
87
88
89
90
91
 
92
93
94
...
96
97
98
99
 
100
101
102
 
103
104
105
106
 
107
108
...
 
1
2
3
4
5
6
7
8
9
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
56
57
 
 
 
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
 
71
72
73
...
84
85
86
 
87
88
89
90
91
92
 
93
94
95
96
97
98
99
 
100
101
102
103
104
 
105
106
107
108
109
110
111
 
112
113
114
115
116
117
 
118
119
120
121
122
123
 
124
125
126
127
128
 
129
130
131
132
...
134
135
136
 
137
138
139
 
140
141
142
143
 
144
145
146
0
@@ -1,4 +1,9 @@
0
-#include <pthread.h>
0
+#ifdef _WIN32
0
+# include <windows.h>
0
+#else
0
+# include <pthread.h>
0
+#endif
0
+
0
 #include <string.h>
0
 #include <stdbool.h>
0
 #include <stdint.h>
0
@@ -9,27 +14,60 @@
0
 
0
 static struct hashtable *quark_string_hash = NULL; /* const char * -> int */
0
 static ptr_array quark_string_index = NULL;
0
+
0
+#ifdef _WIN32
0
+static CRITICAL_SECTION quark_static_cs;
0
+static bool cs_initialized = false;
0
+
0
+static void mutex_lock()
0
+{
0
+ if (!cs_initialized) {
0
+ InitializeCriticalSection(&quark_static_cs);
0
+
0
+ cs_initialized = true;
0
+ }
0
+
0
+ EnterCriticalSection(&quark_static_cs);
0
+}
0
+
0
+static void mutex_unlock()
0
+{
0
+ LeaveCriticalSection(&quark_static_cs);
0
+}
0
+#else
0
 static pthread_mutex_t quark_static_lock = PTHREAD_MUTEX_INITIALIZER;
0
 
0
+static void mutex_lock()
0
+{
0
+ pthread_mutex_lock(&quark_static_lock);
0
+}
0
+
0
+static void mutex_unlock()
0
+{
0
+ pthread_mutex_unlock(&quark_static_lock);
0
+}
0
+#endif
0
+
0
 enum {QUARK_NOT_FOUND = ~0L};
0
 
0
+/* djb2 hash function */
0
 static unsigned int string_hash(const void *val)
0
 {
0
- unsigned int retval = 0;
0
+ unsigned int hash = 5381;
0
   const char *str = (const char *)val;
0
- while (*str)
0
- {
0
- retval += 5* (*str);
0
- str++;
0
- }
0
- return retval;
0
+ int c;
0
+
0
+ while (c = *str++)
0
+ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
0
+
0
+ return hash;
0
 }
0
+
0
 static int string_eq(const void* a1, const void* a2)
0
 {
0
   return strcmp((const char*) a1, (const char*) a2) == 0;
0
 }
0
 
0
-
0
 /* assumes static lock is held */
0
 static inline bool quark_init_if_needed()
0
 {
0
@@ -46,49 +84,49 @@ static inline bool quark_init_if_needed()
0
 quark quark_from_string(const char *string)
0
 {
0
   if (string == NULL) return 0;
0
- pthread_mutex_lock(&quark_static_lock);
0
+ mutex_lock();
0
   if (!quark_init_if_needed())
0
   {
0
     uintptr_t value = (uintptr_t)hashtable_search(quark_string_hash, string);
0
     if (value != 0)
0
     {
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
       return value;
0
     }
0
   }
0
   string = strdup(string);
0
   if (!ptr_array_append(quark_string_index, string))
0
   {
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
     return QUARK_NOT_FOUND;
0
   }
0
   size_t index = ptr_array_length(quark_string_index) - 1;
0
   hashtable_insert(quark_string_hash, (char*) string, (void*) index);
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
   return index;
0
 }
0
 
0
 quark quark_from_static_string(const char *string)
0
 {
0
   if (string == NULL) return 0;
0
- pthread_mutex_lock(&quark_static_lock);
0
+ mutex_lock();
0
   if (!quark_init_if_needed())
0
   {
0
     uintptr_t value = (uintptr_t)hashtable_search(quark_string_hash, string);
0
     if (value != 0)
0
     {
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
       return value;
0
     }
0
   }
0
   if (!ptr_array_append(quark_string_index, string))
0
   {
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
     return QUARK_NOT_FOUND;
0
   }
0
   size_t index = ptr_array_length(quark_string_index) - 1;
0
   hashtable_insert(quark_string_hash, (char *)string, (void*) index);
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
   return index;
0
 }
0
 
0
@@ -96,13 +134,13 @@ const char * quark_to_string(quark q)
0
 {
0
   const char *retval;
0
   if (q == 0) return NULL;
0
- pthread_mutex_lock(&quark_static_lock);
0
+ mutex_lock();
0
   if (quark_init_if_needed() || q >= ptr_array_length(quark_string_index))
0
   {
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
     return NULL;
0
   }
0
   retval = ptr_array_get_index(quark_string_index, q);
0
- pthread_mutex_unlock(&quark_static_lock);
0
+ mutex_unlock();
0
   return retval;
0
 }

Comments

    No one has commented yet.