Browse code

More dox fixes, change errno value. Up version. Fix compile on linux

Nat! authored on 08-03-2016 15:34:46
Showing 8 changed files
... ...
@@ -117,25 +117,25 @@ for 'abafree', that is smart enough to solve the ABA problem when freeing memory
117 117
 
118 118
 ## Dependencies
119 119
 
120
-* mulle_allocator
121
-* mulle_thread
122
-* mulle_aba (for testing)
120
+* [mulle-thread](//www.mulle-kybernetik.com/repositories/mulle-thread)
121
+* [mulle-allocator](//www.mulle-kybernetik.com/repositories/mulle-allocator)
122
+* [mulle-aba](//www.mulle-kybernetik.com/repositories/mulle-aba) (for testing)
123
+* [mulle-bootstrap](//www.mulle-kybernetik.com/repositories/mulle-bootstrap) (optional)
124
+* xcodebuild for OS X
125
+* cmake 3.0 for other Unixes
126
+
123 127
 
124 128
 ## How to build on OS X
125 129
 
126
-Get the newest version of `mulle-bootstrap`
130
+Get the newest version of `mulle-bootstrap` (at least 0.19)
127 131
 
128 132
 ```
129 133
 brew tap mulle-kybernetik/software
130 134
 brew install mulle-bootstrap
131 135
 ```
132 136
 
133
-Download this repository
137
+Download and build this repository, with dependent libraries:
134 138
 
135 139
 ```
136
-git clone https://www.mulle-kybernetik.com/repositories/mulle-concurrent
137
-
138
-# download and build dependencies
139
-cd mulle-concurrent
140
-mulle-bootstrap
140
+mulle-bootstrap clone https://www.mulle-kybernetik.com/repositories/mulle-concurrent
141 141
 ```
... ...
@@ -1,3 +1,8 @@
1
+# v0.3
2
+
3
+* change init error code to EINVAL, because that's what the other code uses.
4
+* fix some gcc compile problems
5
+
1 6
 # v0.2
2 7
 
3 8
 * Adapt to changes in `mulle_allocator` and `mulle_aba`
4 9
new file mode 100755
... ...
@@ -0,0 +1,32 @@
1
+#! /bin/sh
2
+
3
+mulle-bootstrap build "$@"
4
+
5
+#
6
+# fucking Xcode stupidity if we build with -scheme
7
+# stuff gets dumped into "build/Products/Release"
8
+# w/o -scheme stuff gets dumped into "build/Release"
9
+#
10
+MAKE=`which "make"`
11
+CMAKE=`which "cmake"`
12
+
13
+#
14
+# Just build stuff, let user install manually
15
+#
16
+if [ "`uname`"  = "Darwin" ]
17
+then
18
+   xcodebuild -configuration Debug -scheme Libraries -project mulle-concurrent.xcodeproj
19
+   xcodebuild -configuration Release -scheme Libraries -project mulle-concurrent.xcodeproj
20
+else
21
+   if [ ! -z "${CMAKE}" ]
22
+   then
23
+      mkdir -p build 2> /dev/null
24
+      cd build || exit 1
25
+      cmake ..
26
+
27
+      if [ ! -z "${MAKE}" ]
28
+      then
29
+         make
30
+      fi
31
+   fi
32
+fi
... ...
@@ -109,6 +109,7 @@
109 109
 
110 110
 /* Begin PBXFileReference section */
111 111
 		411A28C11BCD446E00D39FF7 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
112
+		414A61D41C8F1B2E0011AA7E /* build.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
112 113
 		417C02651BD8404E005A3751 /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
113 114
 		417C02681BD8404E005A3751 /* Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
114 115
 		417C026A1BD8404E005A3751 /* StaticLibraryIOS.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = StaticLibraryIOS.xcconfig; sourceTree = "<group>"; };
... ...
@@ -181,6 +182,7 @@
181 182
 		414785231ABAF290002DBAE4 = {
182 183
 			isa = PBXGroup;
183 184
 			children = (
185
+				414A61D41C8F1B2E0011AA7E /* build.sh */,
184 186
 				41CAEB091C8DB97F003C2C7B /* README.md */,
185 187
 				41D04AB71C8DD69000CC8F11 /* RELEASENOTES.md */,
186 188
 				411A28C11BCD446E00D39FF7 /* CMakeLists.txt */,
... ...
@@ -501,7 +503,7 @@
501 503
 			isa = XCBuildConfiguration;
502 504
 			baseConfigurationReference = 417C02651BD8404E005A3751 /* Debug.xcconfig */;
503 505
 			buildSettings = {
504
-				CURRENT_PROJECT_VERSION = 0.2;
506
+				CURRENT_PROJECT_VERSION = 0.3;
505 507
 			};
506 508
 			name = Debug;
507 509
 		};
... ...
@@ -509,7 +511,7 @@
509 511
 			isa = XCBuildConfiguration;
510 512
 			baseConfigurationReference = 417C02681BD8404E005A3751 /* Release.xcconfig */;
511 513
 			buildSettings = {
512
-				CURRENT_PROJECT_VERSION = 0.2;
514
+				CURRENT_PROJECT_VERSION = 0.3;
513 515
 			};
514 516
 			name = Release;
515 517
 		};
... ...
@@ -93,7 +93,7 @@ static struct _mulle_concurrent_hashmapstorage *
93 93
       while( q <= sentinel)
94 94
       {
95 95
          q->hash  = MULLE_CONCURRENT_NO_HASH;
96
-         q->value = MULLE_CONCURRENT_NO_POINTER;
96
+         _mulle_atomic_pointer_nonatomic_write( &q->value, MULLE_CONCURRENT_NO_POINTER);
97 97
          ++q;
98 98
       }
99 99
    }
... ...
@@ -354,24 +354,25 @@ int  _mulle_concurrent_hashmap_init( struct mulle_concurrent_hashmap *map,
354 354
                                      unsigned int size,
355 355
                                      struct mulle_allocator *allocator)
356 356
 {
357
+   struct _mulle_concurrent_hashmapstorage   *storage;
358
+   
357 359
    if( ! allocator)
358 360
       allocator = &mulle_default_allocator;
359 361
    
360 362
    assert( allocator->abafree && allocator->abafree != (void *) abort);
361 363
    if( ! allocator->abafree || allocator->abafree == (void *) abort)
362 364
    {
363
-      errno = ENXIO;
365
+      errno = EINVAL;
364 366
       return( -1);
365 367
    }
366 368
 
367
-   // use a smart mode allocator that supports ABA free. Preferably use
368
-   // mulle_aba_as_allocator()
369
-   
370
-   map->allocator    = allocator;
371
-   map->storage      = _mulle_concurrent_alloc_hashmapstorage( size, allocator);
372
-   map->next_storage = map->storage;
369
+   map->allocator = allocator;
370
+   storage        = _mulle_concurrent_alloc_hashmapstorage( size, allocator);
371
+
372
+   _mulle_atomic_pointer_nonatomic_write( &map->storage, storage);
373
+   _mulle_atomic_pointer_nonatomic_write( &map->next_storage, storage);
373 374
    
374
-   if( ! map->storage)
375
+   if( ! storage)
375 376
       return( -1);
376 377
    return( 0);
377 378
 }
... ...
@@ -382,10 +383,16 @@ int  _mulle_concurrent_hashmap_init( struct mulle_concurrent_hashmap *map,
382 383
 //
383 384
 void  _mulle_concurrent_hashmap_done( struct mulle_concurrent_hashmap *map)
384 385
 {
386
+   struct _mulle_concurrent_hashmapstorage   *storage;
387
+   struct _mulle_concurrent_hashmapstorage   *next_storage;
385 388
    // ABA!
386
-   _mulle_allocator_abafree( map->allocator, map->storage);
387
-   if( map->storage != map->next_storage)
388
-      _mulle_allocator_abafree( map->allocator, map->next_storage);
389
+
390
+   storage      = _mulle_atomic_pointer_nonatomic_read( &map->storage);
391
+   next_storage = _mulle_atomic_pointer_nonatomic_read( &map->next_storage);
392
+
393
+   _mulle_allocator_abafree( map->allocator, storage);
394
+   if( storage != next_storage)
395
+      _mulle_allocator_abafree( map->allocator, next_storage);
389 396
 }
390 397
 
391 398
 
... ...
@@ -428,7 +435,7 @@ static int  _mulle_concurrent_hashmap_migrate_storage( struct mulle_concurrent_h
428 435
    previous = __mulle_atomic_pointer_compare_and_swap( &map->storage, q, p);
429 436
 
430 437
    // ok, if we succeed free old, if we fail alloced is
431
-   // already gone. this must be an ABA free (use mulle_aba as allocator)
438
+   // already gone. this must be an ABA free 
432 439
    if( previous == p)
433 440
       _mulle_allocator_abafree( map->allocator, previous); // ABA!!
434 441
    
... ...
@@ -35,12 +35,14 @@
35 35
 #define mulle_concurrent_h__
36 36
 
37 37
 
38
-#define MULLE_CONCURRENT_VERSION  ((0 << 20) | (2 << 8) | 0)
38
+#define MULLE_CONCURRENT_VERSION  ((0 << 20) | (3 << 8) | 0)
39 39
 
40 40
 
41
+#include "mulle_concurrent_types.h"
41 42
 #include "mulle_concurrent_hashmap.h"
42 43
 #include "mulle_concurrent_pointerarray.h"
43 44
 
45
+
44 46
 #if MULLE_ALLOCATOR_VERSION < ((1 << 20) | (0 << 8) | 0)
45 47
 # error "mulle_allocator is too old"
46 48
 #endif
... ...
@@ -172,6 +172,8 @@ int  _mulle_concurrent_pointerarray_init( struct mulle_concurrent_pointerarray *
172 172
                                           unsigned int size,
173 173
                                           struct mulle_allocator *allocator)
174 174
 {
175
+   struct _mulle_concurrent_pointerarraystorage   *storage;
176
+   
175 177
    if( ! allocator)
176 178
       allocator = &mulle_default_allocator;
177 179
 
... ...
@@ -179,15 +181,17 @@ int  _mulle_concurrent_pointerarray_init( struct mulle_concurrent_pointerarray *
179 181
    
180 182
    if( ! allocator->abafree || allocator->abafree == (void *) abort)
181 183
    {
182
-      errno = ENXIO;
184
+      errno = EINVAL;
183 185
       return( -1);
184 186
    }
185 187
    
186
-   array->allocator    = allocator;
187
-   array->storage      = _mulle_concurrent_alloc_pointerarraystorage( size, allocator);
188
-   array->next_storage = array->storage;
188
+   array->allocator = allocator;
189
+   storage          = _mulle_concurrent_alloc_pointerarraystorage( size, allocator);
190
+   
191
+   _mulle_atomic_pointer_nonatomic_write( &array->storage, storage);
192
+   _mulle_atomic_pointer_nonatomic_write( &array->next_storage, storage);
189 193
    
190
-   if( ! array->storage)
194
+   if( ! storage)
191 195
       return( -1);
192 196
    return( 0);
193 197
 }
... ...
@@ -198,9 +202,15 @@ int  _mulle_concurrent_pointerarray_init( struct mulle_concurrent_pointerarray *
198 202
 //
199 203
 void  _mulle_concurrent_pointerarray_done( struct mulle_concurrent_pointerarray *array)
200 204
 {
201
-   _mulle_allocator_abafree( array->allocator, array->storage);
202
-   if( array->storage != array->next_storage)
203
-      _mulle_allocator_abafree( array->allocator, array->next_storage);
205
+   struct _mulle_concurrent_pointerarraystorage   *storage;
206
+   struct _mulle_concurrent_pointerarraystorage   *next_storage;
207
+   
208
+   storage      = _mulle_atomic_pointer_nonatomic_read( &array->storage);
209
+   next_storage = _mulle_atomic_pointer_nonatomic_read( &array->next_storage);
210
+   
211
+   _mulle_allocator_abafree( array->allocator, storage);
212
+   if( storage != next_storage)
213
+      _mulle_allocator_abafree( array->allocator, next_storage);
204 214
 }
205 215
 
206 216
 
... ...
@@ -38,8 +38,6 @@
38 38
 #include <mulle_allocator/mulle_allocator.h>
39 39
 
40 40
 
41
-struct mulle_aba;
42
-
43 41
 struct mulle_concurrent_pointerarray
44 42
 {
45 43
    mulle_atomic_pointer_t   storage;
... ...
@@ -92,7 +90,7 @@ static inline struct mulle_concurrent_pointerarrayenumerator
92 90
 {
93 91
    struct mulle_concurrent_pointerarrayenumerator   rover;
94 92
    
95
-   rover.array   = array;
93
+   rover.array = array;
96 94
    rover.index = array ? 0 : (unsigned int) -1;
97 95
    
98 96
    return( rover);
... ...
@@ -103,7 +101,7 @@ static inline struct mulle_concurrent_pointerarrayreverseenumerator
103 101
 {
104 102
    struct mulle_concurrent_pointerarrayreverseenumerator   rover;
105 103
    
106
-   rover.array   = array;
104
+   rover.array = array;
107 105
    rover.index = n;
108 106
    
109 107
    return( rover);