Re: Synchronizing Thread Execution
Re: Synchronizing Thread Execution
- Subject: Re: Synchronizing Thread Execution
- From: leenoori <email@hidden>
- Date: Tue, 5 Dec 2006 01:57:31 +0100
El 5/12/2006, a las 1:04, Rosyna escribió:
http://www.opensource.apple.com/darwinsource/10.3.2/objc4-235/
runtime/objc-sync.m
http://www.opensource.apple.com/darwinsource/10.3.3/objc4-237/
runtime/objc-sync.m
Compare and contrast the 10.3.2 code with the 10.3.3 code.
Well, had a look and can't really grok what might be unsafe about the
10.3.2 version... Can you be more specific?
26c26
< // objc_sync.h
---
> // objc_sync.m
35,36d34
< #define PTHREAD_MUTEX_RECURSIVE 2
< #include <CoreFoundation/CFDictionary.h>
74,76c72,74
< struct SyncData* nextData;
< id object;
< unsigned int lockCount;
---
> struct SyncData* nextData; // only accessed
while holding sTableLock
> id object; // only accessed
while holding sTableLock
> unsigned int lockCount; // only accessed
while holding sTableLock
81a80
>
85c84,86
< static SyncData* id2data(id object)
---
> enum usage { ACQUIRE, RELEASE, CHECK };
>
> static SyncData* id2data(id object, enum usage why)
109c110,114
< // if no corresponding SyncData found, but an unused one was
found, use it
---
> // no SyncData currently associated with object
> if ( (why == RELEASE) || (why == CHECK) )
> goto done;
>
> // an unused one was found, use it
131a137,151
> if ( result != NULL ) {
> switch ( why ) {
> case ACQUIRE:
> result->lockCount++;
> break;
> case RELEASE:
> result->lockCount--;
> if ( result->lockCount == 0 )
> result->object = NULL; // now recycled
> break;
> case CHECK:
> // do nothing
> break;
> }
> }
145c165
< SyncData* data = id2data(obj);
---
> SyncData* data = id2data(obj, ACQUIRE);
150,152c170
<
< data->lockCount++; // note: lockCount is only modified
when corresponding mutex is held
<
---
>
164,172c182,183
< SyncData* data;
< data = id2data(obj); // XXX should assert that we didn't create it
< require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_INITIALIZED, "id2data failed");
<
< int oldLockCount = data->lockCount--;
< if ( oldLockCount == 1 ) {
< // XXX should move off the main chain to speed id2data
searches
< data->object = NULL; // recycle data
< }
---
> SyncData* data = id2data(obj, RELEASE);
> require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed");
191,192c202,203
< SyncData* data = id2data(obj);
< require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_INITIALIZED, "id2data failed");
---
> SyncData* data = id2data(obj, CHECK);
> require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed");
226,227c237,238
< SyncData* data = id2data(obj);
< require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_INITIALIZED, "id2data failed");
---
> SyncData* data = id2data(obj, CHECK);
> require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed");
246,247c257,258
< SyncData* data = id2data(obj);
< require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_INITIALIZED, "id2data failed");
---
> SyncData* data = id2data(obj, CHECK);
> require_action_string(data != NULL, done, result =
OBJC_SYNC_NOT_OWNING_THREAD_ERROR, "id2data failed");
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden