Skip to content

Commit

Permalink
* make MulleObjCTAOKnownThreadSafeMethods the default for -mulleTAOSt…
Browse files Browse the repository at this point in the history
…rategy for less friction (for now)

* turn MulleAutoLockingObject into a protolclass
fix some tests
  • Loading branch information
Your Name committed Nov 24, 2024
1 parent b27ebd8 commit 19e8a91
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mulle-sde-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: actions/checkout@v4

- uses: mulle-sde/github-ci@v1
- uses: mulle-sde/github-ci@v2

- uses: mulle-cc/github-ci@v5

Expand Down
5 changes: 3 additions & 2 deletions src/class/MulleObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
// of MulleObject will appear to be broken. This is basically the main
// trick MulleAutolockingObject uses and it can't be avoided.
//
@protocol MulleAutolockingObject
@end
PROTOCOLCLASS_INTERFACE0( MulleAutolockingObject)
PROTOCOLCLASS_END()


#define MulleAutolockingObjectProtocols MulleObjCThreadSafe, MulleAutolockingObject

Expand Down
11 changes: 11 additions & 0 deletions src/class/MulleObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#import "MulleObject-Private.h"


PROTOCOLCLASS_IMPLEMENTATION( MulleAutolockingObject)

- (MulleObjCTAOStrategy) mulleTAOStrategy
{
return( MulleObjCTAOKnownThreadSafe);
}

PROTOCOLCLASS_END()



@implementation MulleObject

static BOOL is_a_locking_descriptor( struct _mulle_objc_descriptor *desc,
Expand Down
43 changes: 25 additions & 18 deletions src/class/NSThread.m
Original file line number Diff line number Diff line change
Expand Up @@ -1094,18 +1094,21 @@ void MulleObjCTAOLogAndFail( struct _mulle_objc_object *obj,
mulle_thread_t osThread,
struct _mulle_objc_descriptor *desc)
{
struct _mulle_objc_class *cls;
struct _mulle_objc_universe *universe;
int ismeta;
NSThread *currentThreadObject;
NSThread *osThreadObject;
char *s;
char *strategyName;
MulleObjCTAOStrategy strategy;

cls = _mulle_objc_object_get_isa( obj);
ismeta = _mulle_objc_class_is_metaclass( cls);
universe = _mulle_objc_class_get_universe( cls);
struct _mulle_objc_class *cls;
struct _mulle_objc_universe *universe;
int ismeta;
NSThread *currentThreadObject;
NSThread *osThreadObject;
char *s;
char *strategyName;
MulleObjCTAOStrategy strategy;
struct _mulle_objc_searcharguments args;
struct _mulle_objc_method *method;
mulle_objc_implementation_t imp;

cls = _mulle_objc_object_get_isa( obj);
ismeta = _mulle_objc_class_is_metaclass( cls);
universe = _mulle_objc_class_get_universe( cls);

currentThreadObject = MulleThreadGetCurrentThread();
osThreadObject = _mulle_objc_universe_lookup_threadobject_for_thread( universe, osThread); // try to retri
Expand All @@ -1129,13 +1132,17 @@ void MulleObjCTAOLogAndFail( struct _mulle_objc_object *obj,
else
mulle_buffer_sprintf( buffer, "%p ", osThread);


strategyName = NULL;
if( [(id) obj respondsToSelector:@selector( mulleTAOStrategy)])
if( ! ismeta)
{
strategy = [(id) obj mulleTAOStrategy];
strategyName = NS_ENUM_LOOKUP( MulleObjCTAOStrategy, strategy);
mulle_buffer_sprintf( buffer, "and TAO strategy %s ", strategyName ? strategyName : "None");
args = mulle_objc_searcharguments_make_default( @selector( mulleTAOStrategy));
method = mulle_objc_class_search_method( cls, &args, 0, NULL);
if( method)
{
imp = mulle_objc_method_get_implementation( method);
strategy = (uintptr_t) _mulle_objc_implementation_invoke( imp, obj, @selector( mulleTAOStrategy), obj);
strategyName = NS_ENUM_LOOKUP( MulleObjCTAOStrategy, strategy);
mulle_buffer_sprintf( buffer, "and TAO strategy %s ", strategyName ? strategyName : "None");
}
}

mulle_buffer_sprintf( buffer, "gets a %c%s call from thread ",
Expand Down
3 changes: 3 additions & 0 deletions src/function/MulleObjCDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ void MulleObjCDotdumpMetaHierarchy( char *classname);
MULLE_OBJC_GLOBAL
void MulleObjCDumpObject( id object);

// string as help for debuggin
MULLE_OBJC_GLOBAL
char *MulleObjCDebugHelp;
6 changes: 6 additions & 0 deletions src/function/MulleObjCDebug.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ void MulleObjCDumpObject( id obj)
}


char *MulleObjCDebug = ""
"x MulleObjCDumpObject( obj) : dump current object to stderr\n"
"x MulleObjCHTMLDumpUniverse() : dump default universe to PWD\n";



#else

void MulleObjCHTMLDumpUniverseToDirectory( char *directory)
Expand Down
2 changes: 1 addition & 1 deletion src/function/MulleObjCFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ static int compare_ivar_by_name( void **p_a, void **p_b, void *userinfo)
}


void MulleObjCDescribeIvars( struct mulle_buffer *buffer, id obj)
void MulleObjCDescribeIvars( struct mulle_buffer *buffer, id obj)
{
struct _mulle_objc_infraclass *infra;
struct _mulle_objc_ivar *ivar;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/MulleObjCProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (id) mulleThreadSafeCopy
// So ensure that the strategy is back to the default
//

- (MulleObjCTAOStrategy) mulleTAOStrategy MULLE_OBJC_THREADSAFE_METHOD
- (MulleObjCTAOStrategy) mulleTAOStrategy
{
return( MulleObjCTAOCallerRemovesFromCurrentPool);
}
Expand Down
9 changes: 8 additions & 1 deletion src/protocol/MulleObjCRootObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,14 @@ - (void) mulleRelinquishAccessWithTAOStrategy:(MulleObjCTAOStrategy) strategy
//
- (MulleObjCTAOStrategy) mulleTAOStrategy
{
return( MulleObjCTAOCallerRemovesFromCurrentPool);
//
// So this default is MulleObjCTAOKnownThreadSafeMethods, because it doesn't
// break existing code. Known problematic subclasses like
// NSMutableDictionary then should actually reset this to some unsafe tag.
// In a future world where everything is a MulleObject, this would be unsafe
// and autolocking would promote this to ThreadSafe (?)
//
return( MulleObjCTAOKnownThreadSafeMethods);
}


Expand Down
1 change: 1 addition & 0 deletions src/reflect/objc-loader.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ @selector( MulleAutolockingObject), MULLE_OBJC_NO_CATEGORYID }, // 6eb2f41b;MulleAutolockingObject;;
{ @selector( MulleDynamicObject), @selector( NSMutableCopying) }, // d9918780;MulleDynamicObject;4aa86031;NSMutableCopying
{ @selector( MulleDynamicObject), MULLE_OBJC_NO_CATEGORYID }, // d9918780;MulleDynamicObject;;
{ @selector( MulleObjCClassCluster), MULLE_OBJC_NO_CATEGORYID }, // 6ed73da1;MulleObjCClassCluster;;
Expand Down
10 changes: 10 additions & 0 deletions test/PROTOCOLCLASS/macro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ add_executable( macro.exe
${SOURCES}
)

get_filename_component( C_COMPILER_NAME "${CMAKE_C_COMPILER}" NAME_WE)

if( "${C_COMPILER_NAME}" MATCHES "mulle-cl*")
if( CMAKE_BUILD_TYPE MATCHES "^Debug|^Test")
target_compile_options( "macro.exe" PRIVATE -fobjc-tao)
message( STATUS "TAO enabled via compiler flag")
endif()
endif()


target_link_libraries( macro.exe
${TEST_LIBRARIES}
)
10 changes: 10 additions & 0 deletions test/PROTOCOLCLASS/manual/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ add_executable( manual.exe
${SOURCES}
)

get_filename_component( C_COMPILER_NAME "${CMAKE_C_COMPILER}" NAME_WE)

if( "${C_COMPILER_NAME}" MATCHES "mulle-cl*")
if( CMAKE_BUILD_TYPE MATCHES "^Debug|^Test")
target_compile_options( "manual.exe" PRIVATE -fobjc-tao)
message( STATUS "TAO enabled via compiler flag")
endif()
endif()


target_link_libraries( manual.exe
${TEST_LIBRARIES}
)
3 changes: 3 additions & 0 deletions test/tao-mix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# -DMULLE_TECHNICAL_FLAGS=-vvv \
# -DCMAKE_RULE_MESSAGES=OFF \
# -DTEST_LIBRARIES='-L/home/nat/.mulle/var/MulleObjC-d1c1acfc730b/dependency/Debug/lib;-Wl,--no-as-needed;...' \
cmake_minimum_required(VERSION 3.15)

set( CMAKE_C_COMPILER_WORKS 1)

project( tao-mix C)

Expand Down
8 changes: 8 additions & 0 deletions test/tao-thread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ add_executable( "${PROJECT_NAME}.exe"
main.m
)

if( "${C_COMPILER_NAME}" MATCHES "mulle-cl*")
if( CMAKE_BUILD_TYPE MATCHES "^Debug|^Test")
target_compile_options( "${PROJECT_NAME}.exe" PRIVATE -fobjc-tao)
message( STATUS "TAO enabled via compiler flag")
endif()
endif()


target_link_libraries( "${PROJECT_NAME}.exe"
${TEST_LIBRARIES}
)

0 comments on commit 19e8a91

Please sign in to comment.