~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Source/NSConnection.m

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2012-11-21 13:56:22 UTC
  • mfrom: (8.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20121121135622-1w035dpxneardw8q
Tags: 1.24.0-1ubuntu1
Backport upstream fix for recent libxml2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
   Boston, MA 02111 USA.
27
27
 
28
28
   <title>NSConnection class reference</title>
29
 
   $Date: 2011-06-18 18:46:28 +0100 (Sat, 18 Jun 2011) $ $Revision: 33340 $
 
29
   $Date: 2012-01-30 04:31:40 -0700 (Mon, 30 Jan 2012) $ $Revision: 34665 $
30
30
   */
31
31
 
32
32
#import "common.h"
33
33
 
 
34
#if !defined (__GNU_LIBOBJC__)
 
35
#  include <objc/encoding.h>
 
36
#endif
 
37
 
34
38
#define GS_NSConnection_IVARS \
35
39
  BOOL                  _isValid; \
36
40
  BOOL                  _independentQueueing; \
174
178
- (const char *) typeForSelector: (SEL)sel remoteTarget: (unsigned)target;
175
179
@end
176
180
 
177
 
#define F_LOCK(X) {NSDebugFLLog(@"GSConnection",@"Lock %@",X);[X lock];}
178
 
#define F_UNLOCK(X) {NSDebugFLLog(@"GSConnection",@"Unlock %@",X);[X unlock];}
179
 
#define M_LOCK(X) {NSDebugMLLog(@"GSConnection",@"Lock %@",X);[X lock];}
180
 
#define M_UNLOCK(X) {NSDebugMLLog(@"GSConnection",@"Unlock %@",X);[X unlock];}
 
181
#define GS_F_LOCK(X) \
 
182
{NSDebugFLLog(@"GSConnection",@"Lock %@",X);[X lock];}
 
183
#define GS_F_UNLOCK(X) \
 
184
{NSDebugFLLog(@"GSConnection",@"Unlock %@",X);[X unlock];}
 
185
#define GS_M_LOCK(X) \
 
186
{NSDebugMLLog(@"GSConnection",@"Lock %@",X);[X lock];}
 
187
#define GSM_UNLOCK(X) \
 
188
{NSDebugMLLog(@"GSConnection",@"Unlock %@",X);[X unlock];}
181
189
 
182
190
NSString * const NSDestinationInvalidException =
183
191
  @"NSDestinationInvalidException";
361
369
static int debug_connection = 0;
362
370
 
363
371
static NSHashTable      *connection_table;
364
 
static NSLock           *connection_table_gate = nil;
 
372
static GSLazyRecursiveLock              *connection_table_gate = nil;
365
373
 
366
374
/*
367
375
 * Locate an existing connection with the specified send and receive ports.
373
381
  NSHashEnumerator      enumerator;
374
382
  NSConnection          *c;
375
383
 
376
 
  F_LOCK(connection_table_gate);
 
384
  GS_F_LOCK(connection_table_gate);
377
385
  enumerator = NSEnumerateHashTable(connection_table);
378
386
  while ((c = (NSConnection*)NSNextHashEnumeratorItem(&enumerator)) != nil)
379
387
    {
389
397
        }
390
398
    }
391
399
  NSEndHashTableEnumeration(&enumerator);
392
 
  F_UNLOCK(connection_table_gate);
 
400
  GS_F_UNLOCK(connection_table_gate);
393
401
  return c;
394
402
}
395
403
 
401
409
{
402
410
  id    rootObject;
403
411
 
404
 
  F_LOCK(root_object_map_gate);
 
412
  GS_F_LOCK(root_object_map_gate);
405
413
  rootObject = (id)NSMapGet(root_object_map, (void*)(uintptr_t)aPort);
406
 
  F_UNLOCK(root_object_map_gate);
 
414
  GS_F_UNLOCK(root_object_map_gate);
407
415
  return rootObject;
408
416
}
409
417
 
413
421
{
414
422
  id    oldRootObject;
415
423
 
416
 
  F_LOCK(root_object_map_gate);
 
424
  GS_F_LOCK(root_object_map_gate);
417
425
  oldRootObject = (id)NSMapGet(root_object_map, (void*)(uintptr_t)aPort);
418
426
  if (oldRootObject != anObj)
419
427
    {
427
435
          NSMapRemove(root_object_map, (void*)(uintptr_t)aPort);
428
436
        }
429
437
    }
430
 
  F_UNLOCK(root_object_map_gate);
 
438
  GS_F_UNLOCK(root_object_map_gate);
431
439
}
432
440
 
433
441
static NSMapTable *targetToCached = NULL;
453
461
{
454
462
  NSArray       *a;
455
463
 
456
 
  M_LOCK(connection_table_gate);
 
464
  GS_M_LOCK(connection_table_gate);
457
465
  a = NSAllHashTableObjects(connection_table);
458
 
  M_UNLOCK(connection_table_gate);
 
466
  GSM_UNLOCK(connection_table_gate);
459
467
  return a;
460
468
}
461
469
 
658
666
        NSCreateHashTable(NSNonRetainedObjectHashCallBacks, 0);
659
667
 
660
668
      targetToCached =
661
 
        NSCreateMapTable(NSIntMapKeyCallBacks,
 
669
        NSCreateMapTable(NSIntegerMapKeyCallBacks,
662
670
          NSObjectMapValueCallBacks, 0);
663
671
 
664
672
      root_object_map =
717
725
    {
718
726
      proxy = [[connection rootProxy] retain];
719
727
    }
720
 
  [arp release];
 
728
  [arp drain];
721
729
  return [proxy autorelease];
722
730
}
723
731
 
745
753
    {
746
754
      proxy = RETAIN([connection rootProxy]);
747
755
    }
748
 
  [arp release];
 
756
  [arp drain];
749
757
  return AUTORELEASE(proxy);
750
758
}
751
759
 
791
799
  NSArray       *cached_locals;
792
800
  int   i;
793
801
 
794
 
  M_LOCK(cached_proxies_gate);
 
802
  GS_M_LOCK(cached_proxies_gate);
795
803
  cached_locals = NSAllMapTableValues(targetToCached);
796
804
  for (i = [cached_locals count]; i > 0; i--)
797
805
    {
810
818
      [t invalidate];
811
819
      timer = nil;
812
820
    }
813
 
  M_UNLOCK(cached_proxies_gate);
 
821
  GSM_UNLOCK(cached_proxies_gate);
814
822
}
815
823
 
816
824
/**
819
827
 */
820
828
- (void) addRequestMode: (NSString*)mode
821
829
{
822
 
  M_LOCK(IrefGate);
 
830
  GS_M_LOCK(IrefGate);
823
831
  if ([self isValid] == YES)
824
832
    {
825
833
      if ([IrequestModes containsObject: mode] == NO)
835
843
          [IrequestModes addObject: mode];
836
844
        }
837
845
    }
838
 
  M_UNLOCK(IrefGate);
 
846
  GSM_UNLOCK(IrefGate);
839
847
}
840
848
 
841
849
/**
844
852
 */
845
853
- (void) addRunLoop: (NSRunLoop*)loop
846
854
{
847
 
  M_LOCK(IrefGate);
 
855
  GS_M_LOCK(IrefGate);
848
856
  if ([self isValid] == YES)
849
857
    {
850
858
      if ([IrunLoops indexOfObjectIdenticalTo: loop] == NSNotFound)
860
868
          [IrunLoops addObject: loop];
861
869
        }
862
870
    }
863
 
  M_UNLOCK(IrefGate);
 
871
  GSM_UNLOCK(IrefGate);
864
872
}
865
873
 
866
874
- (void) dealloc
1034
1042
        @"Send: %@\n  Recv: %@", parent, self, s, r);
1035
1043
    }
1036
1044
 
1037
 
  M_LOCK(connection_table_gate);
 
1045
  GS_M_LOCK(connection_table_gate);
1038
1046
 
1039
1047
  IisValid = YES;
1040
1048
  IreceivePort = RETAIN(r);
1175
1183
    {
1176
1184
      if ([del connection: parent shouldMakeNewConnection: self] == NO)
1177
1185
        {
1178
 
          M_UNLOCK(connection_table_gate);
 
1186
          GSM_UNLOCK(connection_table_gate);
1179
1187
          DESTROY(self);
1180
1188
          return nil;
1181
1189
        }
1185
1193
    {
1186
1194
      if (![del makeNewConnection: self sender: parent])
1187
1195
        {
1188
 
          M_UNLOCK(connection_table_gate);
 
1196
          GSM_UNLOCK(connection_table_gate);
1189
1197
          DESTROY(self);
1190
1198
          return nil;
1191
1199
        }
1219
1227
     implementation of [-release] to automatically remove the connection
1220
1228
     from this array when it is the only thing retaining it. */
1221
1229
  NSHashInsert(connection_table, (void*)self);
1222
 
  M_UNLOCK(connection_table_gate);
 
1230
  GSM_UNLOCK(connection_table_gate);
1223
1231
 
1224
1232
  [nCenter postNotificationName: NSConnectionDidInitializeNotification
1225
1233
                         object: self];
1238
1246
 */
1239
1247
- (void) invalidate
1240
1248
{
1241
 
  M_LOCK(IrefGate);
 
1249
  GS_M_LOCK(IrefGate);
1242
1250
  if (IisValid == NO)
1243
1251
    {
1244
 
      M_UNLOCK(IrefGate);
 
1252
      GSM_UNLOCK(IrefGate);
1245
1253
      return;
1246
1254
    }
1247
1255
  if (IshuttingDown == NO)
1254
1262
      //[self _shutdown];
1255
1263
    }
1256
1264
  IisValid = NO;
1257
 
  M_LOCK(connection_table_gate);
 
1265
  GS_M_LOCK(connection_table_gate);
1258
1266
  NSHashRemove(connection_table, self);
1259
 
  M_UNLOCK(connection_table_gate);
 
1267
  GSM_UNLOCK(connection_table_gate);
1260
1268
 
1261
 
  M_UNLOCK(IrefGate);
 
1269
  GSM_UNLOCK(IrefGate);
1262
1270
 
1263
1271
  /*
1264
1272
   * Don't need notifications any more - so remove self as observer.
1310
1318
    [[NSNotificationCenter defaultCenter]
1311
1319
      postNotificationName: NSConnectionDidDieNotification
1312
1320
                    object: self];
1313
 
    [arp release];
 
1321
    [arp drain];
1314
1322
  }
1315
1323
 
1316
1324
  /*
1319
1327
   *    these proxies in case they are keeping us retained when we
1320
1328
   *    might otherwise de deallocated.
1321
1329
   */
1322
 
  M_LOCK(IrefGate);
 
1330
  GS_M_LOCK(IrefGate);
1323
1331
  if (IlocalTargets != 0)
1324
1332
    {
1325
1333
      NSMutableArray            *targets;
1367
1375
      NSZoneFree(IlocalObjects->zone, (void*)IlocalObjects);
1368
1376
      IlocalObjects = 0;
1369
1377
    }
1370
 
  M_UNLOCK(IrefGate);
 
1378
  GSM_UNLOCK(IrefGate);
1371
1379
 
1372
1380
  /*
1373
1381
   * If we are invalidated, we shouldn't be receiving any event and
1408
1416
  NSMutableArray        *c;
1409
1417
 
1410
1418
  /* Don't assert (IisValid); */
1411
 
  M_LOCK(IrefGate);
 
1419
  GS_M_LOCK(IrefGate);
1412
1420
  if (IlocalObjects != 0)
1413
1421
    {
1414
1422
      GSIMapEnumerator_t        enumerator;
1428
1436
    {
1429
1437
      c = [NSArray array];
1430
1438
    }
1431
 
  M_UNLOCK(IrefGate);
 
1439
  GSM_UNLOCK(IrefGate);
1432
1440
  return c;
1433
1441
}
1434
1442
 
1489
1497
  return result;
1490
1498
}
1491
1499
 
1492
 
- (void) release
 
1500
- (oneway void) release
1493
1501
{
1494
1502
  /* We lock the connection table while checking, to prevent
1495
1503
   * another thread from grabbing this connection while we are
1498
1506
   * it from the table so that no other thread will find it
1499
1507
   * and try to use it while it is being deallocated.
1500
1508
   */
1501
 
  M_LOCK(connection_table_gate);
 
1509
  GS_M_LOCK(connection_table_gate);
1502
1510
  if (NSDecrementExtraRefCountWasZero(self))
1503
1511
    {
1504
1512
      NSHashRemove(connection_table, self);
1505
 
      M_UNLOCK(connection_table_gate);
 
1513
      GSM_UNLOCK(connection_table_gate);
1506
1514
      [self dealloc];
1507
1515
    }
1508
1516
  else
1509
1517
    {
1510
 
      M_UNLOCK(connection_table_gate);
 
1518
      GSM_UNLOCK(connection_table_gate);
1511
1519
    }
1512
1520
}
1513
1521
 
1520
1528
  NSMutableArray        *c;
1521
1529
 
1522
1530
  /* Don't assert (IisValid); */
1523
 
  M_LOCK(IrefGate);
 
1531
  GS_M_LOCK(IrefGate);
1524
1532
  if (IremoteProxies != 0)
1525
1533
    {
1526
1534
      GSIMapEnumerator_t        enumerator;
1540
1548
    {
1541
1549
      c = [NSMutableArray array];
1542
1550
    }
1543
 
  M_UNLOCK(IrefGate);
 
1551
  GSM_UNLOCK(IrefGate);
1544
1552
  return c;
1545
1553
}
1546
1554
 
1549
1557
 */
1550
1558
- (void) removeRequestMode: (NSString*)mode
1551
1559
{
1552
 
  M_LOCK(IrefGate);
 
1560
  GS_M_LOCK(IrefGate);
1553
1561
  if (IrequestModes != nil && [IrequestModes containsObject: mode])
1554
1562
    {
1555
1563
      unsigned  c = [IrunLoops count];
1564
1572
        }
1565
1573
      [IrequestModes removeObject: mode];
1566
1574
    }
1567
 
  M_UNLOCK(IrefGate);
 
1575
  GSM_UNLOCK(IrefGate);
1568
1576
}
1569
1577
 
1570
1578
/**
1572
1580
 */
1573
1581
- (void) removeRunLoop: (NSRunLoop*)loop
1574
1582
{
1575
 
  M_LOCK(IrefGate);
 
1583
  GS_M_LOCK(IrefGate);
1576
1584
  if (IrunLoops != nil)
1577
1585
    {
1578
1586
      unsigned  pos = [IrunLoops indexOfObjectIdenticalTo: loop];
1592
1600
          [IrunLoops removeObjectAtIndex: pos];
1593
1601
        }
1594
1602
    }
1595
 
  M_UNLOCK(IrefGate);
 
1603
  GSM_UNLOCK(IrefGate);
1596
1604
}
1597
1605
 
1598
1606
/**
1615
1623
{
1616
1624
  NSArray       *c;
1617
1625
 
1618
 
  M_LOCK(IrefGate);
 
1626
  GS_M_LOCK(IrefGate);
1619
1627
  c = AUTORELEASE([IrequestModes copy]);
1620
 
  M_UNLOCK(IrefGate);
 
1628
  GSM_UNLOCK(IrefGate);
1621
1629
  return c;
1622
1630
}
1623
1631
 
1739
1747
 */
1740
1748
- (void) setRequestMode: (NSString*)mode
1741
1749
{
1742
 
  M_LOCK(IrefGate);
 
1750
  GS_M_LOCK(IrefGate);
1743
1751
  if (IrequestModes != nil)
1744
1752
    {
1745
1753
      while ([IrequestModes count] > 0
1756
1764
          [self addRequestMode: mode];
1757
1765
        }
1758
1766
    }
1759
 
  M_UNLOCK(IrefGate);
 
1767
  GSM_UNLOCK(IrefGate);
1760
1768
}
1761
1769
 
1762
1770
/**
1826
1834
 
1827
1835
  d = [NSMutableDictionary dictionaryWithCapacity: 8];
1828
1836
 
1829
 
  M_LOCK(IrefGate);
 
1837
  GS_M_LOCK(IrefGate);
1830
1838
 
1831
1839
  /*
1832
1840
   *    These are in OPENSTEP 4.2
1855
1863
  o = [NSNumber numberWithUnsignedInt: [IrequestQueue count]];
1856
1864
  [d setObject: o forKey: @"NSConnectionRequestQueue"];
1857
1865
 
1858
 
  M_UNLOCK(IrefGate);
 
1866
  GSM_UNLOCK(IrefGate);
1859
1867
 
1860
1868
  return d;
1861
1869
}
1950
1958
 
1951
1959
  DESTROY(IrefGate);
1952
1960
 
1953
 
  [arp release];
 
1961
  [arp drain];
1954
1962
}
1955
1963
 
1956
1964
/*
2043
2051
       * the IreplyMap.  However, in case the other end has already sent us
2044
2052
       * a response, we must check for it and scrap it if necessary.
2045
2053
       */
2046
 
      M_LOCK(IrefGate);
 
2054
      GS_M_LOCK(IrefGate);
2047
2055
      node = GSIMapNodeForKey(IreplyMap, (GSIMapKey)(NSUInteger)seq);
2048
2056
      if (node != 0 && node->value.obj != dummyObject)
2049
2057
        {
2059
2067
          [self _doneInRmc: node->value.obj];
2060
2068
        }
2061
2069
      GSIMapRemoveKey(IreplyMap, (GSIMapKey)(NSUInteger)seq);
2062
 
      M_UNLOCK(IrefGate);
 
2070
      GSM_UNLOCK(IrefGate);
2063
2071
    }
2064
2072
  else
2065
2073
    {
2133
2141
                    break;
2134
2142
                }
2135
2143
            }
 
2144
          else
 
2145
            {
 
2146
              datum = 0;
 
2147
            }
2136
2148
          [inv setReturnValue: datum];
2137
2149
 
2138
2150
          /* Decode the values returned by reference.  Note: this logic
2207
2219
{
2208
2220
  unsigned      result;
2209
2221
 
2210
 
  M_LOCK(connection_table_gate);
 
2222
  GS_M_LOCK(connection_table_gate);
2211
2223
  result = NSCountHashTable(connection_table);
2212
 
  M_UNLOCK(connection_table_gate);
 
2224
  GSM_UNLOCK(connection_table_gate);
2213
2225
  return result;
2214
2226
}
2215
2227
 
2219
2231
  NSHashEnumerator      enumerator;
2220
2232
  NSConnection          *o;
2221
2233
 
2222
 
  M_LOCK(connection_table_gate);
 
2234
  GS_M_LOCK(connection_table_gate);
2223
2235
  enumerator = NSEnumerateHashTable(connection_table);
2224
2236
  while ((o = (NSConnection*)NSNextHashEnumeratorItem(&enumerator)) != nil)
2225
2237
    {
2229
2241
        }
2230
2242
    }
2231
2243
  NSEndHashTableEnumeration(&enumerator);
2232
 
  M_UNLOCK(connection_table_gate);
 
2244
  GSM_UNLOCK(connection_table_gate);
2233
2245
 
2234
2246
  return count;
2235
2247
}
2322
2334
         * If REPLY_DEPTH is non-zero, we may still want to service it now
2323
2335
         * if independent_queuing is NO.
2324
2336
         */
2325
 
        M_LOCK(GSIVar(conn, _refGate));
 
2337
        GS_M_LOCK(GSIVar(conn, _refGate));
2326
2338
        if (GSIVar(conn, _requestDepth) == 0
2327
2339
          || GSIVar(conn, _independentQueueing) == NO)
2328
2340
          {
2329
2341
            GSIVar(conn, _requestDepth)++;
2330
 
            M_UNLOCK(GSIVar(conn, _refGate));
 
2342
            GSM_UNLOCK(GSIVar(conn, _refGate));
2331
2343
            [conn _service_forwardForProxy: rmc];       // Catches exceptions
2332
 
            M_LOCK(GSIVar(conn, _refGate));
 
2344
            GS_M_LOCK(GSIVar(conn, _refGate));
2333
2345
            GSIVar(conn, _requestDepth)--;
2334
2346
          }
2335
2347
        else
2345
2357
          {
2346
2358
            rmc = [GSIVar(conn, _requestQueue) objectAtIndex: 0];
2347
2359
            [GSIVar(conn, _requestQueue) removeObjectAtIndex: 0];
2348
 
            M_UNLOCK(GSIVar(conn, _refGate));
 
2360
            GSM_UNLOCK(GSIVar(conn, _refGate));
2349
2361
            [conn _service_forwardForProxy: rmc];       // Catches exceptions
2350
 
            M_LOCK(GSIVar(conn, _refGate));
 
2362
            GS_M_LOCK(GSIVar(conn, _refGate));
2351
2363
          }
2352
 
        M_UNLOCK(GSIVar(conn, _refGate));
 
2364
        GSM_UNLOCK(GSIVar(conn, _refGate));
2353
2365
        break;
2354
2366
 
2355
2367
      /*
2375
2387
              [self _doneInRmc: rmc];
2376
2388
              break;
2377
2389
            }
2378
 
          M_LOCK(GSIVar(conn, _refGate));
 
2390
          GS_M_LOCK(GSIVar(conn, _refGate));
2379
2391
          node = GSIMapNodeForKey(GSIVar(conn, _replyMap),
2380
2392
            (GSIMapKey)(NSUInteger)sequence);
2381
2393
          if (node == 0)
2397
2409
              [self _doneInRmc: node->value.obj];
2398
2410
              node->value.obj = rmc;
2399
2411
            }
2400
 
          M_UNLOCK(GSIVar(conn, _refGate));
 
2412
          GSM_UNLOCK(GSIVar(conn, _refGate));
2401
2413
        }
2402
2414
        break;
2403
2415
 
2505
2517
      id                tmp;
2506
2518
      id                object;
2507
2519
      SEL               selector;
2508
 
      GSMethod          meth = 0;
2509
2520
      BOOL              is_exception = NO;
2510
2521
      unsigned          flags;
2511
2522
      int               argnum;
2548
2559
 
2549
2560
      decoder = aRmc;
2550
2561
 
2551
 
      /* Decode the object, (which is always the first argument to a method). */
2552
 
      [decoder decodeValueOfObjCType: @encode(id) at: &object];
 
2562
      /* Decode the object, (which is always the first argument to a method).
 
2563
       * Use the -decodeObject method to ensure that the target of the
 
2564
       * invocation is autoreleased and will be deallocated when we finish.
 
2565
       */
 
2566
      object = [decoder decodeObject];
2553
2567
 
2554
2568
      /* Decode the selector, (which is the second argument to a method). */ 
2555
2569
      /* xxx @encode(SEL) produces "^v" in gcc 2.5.8.  It should be ":" */
2563
2577
         as the ENCODED_TYPES string, but it will have different register
2564
2578
         and stack locations if the ENCODED_TYPES came from a machine of a
2565
2579
         different architecture. */
2566
 
      if (GSObjCIsClass(object))
2567
 
        {
2568
 
          meth = GSGetMethod(object, selector, NO, YES);
2569
 
        }
2570
 
      else if (GSObjCIsInstance(object))
2571
 
        {
2572
 
          meth = GSGetMethod(object_getClass(object), selector, YES, YES);
2573
 
        }
2574
 
      else
 
2580
      sig = [object methodSignatureForSelector: selector];
 
2581
      if (nil == sig)
2575
2582
        {
2576
2583
          [NSException raise: NSInvalidArgumentException
2577
 
                       format: @"decoded object %p is invalid", object];
 
2584
                       format: @"decoded object %p doesn't handle %s",
 
2585
            object, sel_getName(selector)];
2578
2586
        }
 
2587
      type = [sig methodType];
2579
2588
      
2580
 
      if (meth != 0)
2581
 
        {
2582
 
          type = method_getTypeEncoding(meth);
2583
 
        }
2584
 
      else
2585
 
        {
2586
 
          NSDebugLog(@"Local object <%p %s> doesn't implement: %s directly.  "
2587
 
                     @"Will search for arbitrary signature.",
2588
 
                     object,
2589
 
                     class_getName(GSObjCIsClass(object) 
2590
 
                                     ? object : (id)object_getClass(object)),
2591
 
                     sel_getName(selector));
2592
 
          type = GSTypesFromSelector(selector);
2593
 
        }
2594
 
 
2595
2589
      /* Make sure we successfully got the method type, and that its
2596
2590
         types match the ENCODED_TYPES. */
2597
2591
      NSCParameterAssert (type);
2602
2596
            encoded_types, type, sel_getName(selector)];
2603
2597
        }
2604
2598
 
2605
 
      sig = [NSMethodSignature signatureWithObjCTypes: type];
2606
2599
      inv = [[NSInvocation alloc] initWithMethodSignature: sig];
2607
2600
 
2608
2601
      tmptype = skip_argspec (type);
2926
2919
          if (debug_connection > 3)
2927
2920
            NSLog(@"releasing object with target (0x%x) on (%@) counter %d",
2928
2921
                target, self, prox->_counter);
2929
 
          M_LOCK(IrefGate);
 
2922
          GS_M_LOCK(IrefGate);
2930
2923
          NS_DURING
2931
2924
            {
2932
2925
              if (--(prox->_counter) == 0)
2947
2940
            }
2948
2941
          NS_HANDLER
2949
2942
            {
2950
 
              M_UNLOCK(IrefGate);
 
2943
              GSM_UNLOCK(IrefGate);
2951
2944
              [localException raise];
2952
2945
            }
2953
2946
          NS_ENDHANDLER
2954
 
          M_UNLOCK(IrefGate);
 
2947
          GSM_UNLOCK(IrefGate);
2955
2948
        }
2956
2949
      else if (debug_connection > 3)
2957
2950
        NSLog(@"releasing object with target (0x%x) on (%@) - nothing to do",
2980
2973
    NSLog(@"looking to retain local object with target (0x%x) on (%@)",
2981
2974
      target, self);
2982
2975
 
2983
 
  M_LOCK(IrefGate);
 
2976
  GS_M_LOCK(IrefGate);
2984
2977
  local = [self locateLocalTarget: target];
2985
2978
  if (local == nil)
2986
2979
    {
2990
2983
    {
2991
2984
      local->_counter++;        // Vended on connection.
2992
2985
    }
2993
 
  M_UNLOCK(IrefGate);
 
2986
  GSM_UNLOCK(IrefGate);
2994
2987
 
2995
2988
  [op encodeObject: response];
2996
2989
  [self _sendOutRmc: op type: RETAIN_REPLY];
3132
3125
      if (debug_connection > 5)
3133
3126
        NSLog(@"Waiting for reply sequence %d on %@",
3134
3127
          sn, self);
3135
 
      M_LOCK(IrefGate); isLocked = YES;
 
3128
      GS_M_LOCK(IrefGate); isLocked = YES;
3136
3129
      while (IisValid == YES
3137
3130
        && (node = GSIMapNodeForKey(IreplyMap, (GSIMapKey)(NSUInteger)sn)) != 0
3138
3131
        && node->value.obj == dummyObject)
3139
3132
        {
3140
3133
          NSDate        *limit_date;
3141
3134
 
3142
 
          M_UNLOCK(IrefGate); isLocked = NO;
 
3135
          GSM_UNLOCK(IrefGate); isLocked = NO;
3143
3136
          if (start_date == nil)
3144
3137
            {
3145
3138
              start_date = [dateClass allocWithZone: NSDefaultMallocZone()];
3183
3176
            && (limit_date == timeout_date))
3184
3177
            || [timeout_date timeIntervalSinceNow] <= 0.0)
3185
3178
            {
3186
 
              M_LOCK(IrefGate); isLocked = YES;
 
3179
              GS_M_LOCK(IrefGate); isLocked = YES;
3187
3180
              node = GSIMapNodeForKey(IreplyMap, (GSIMapKey)(NSUInteger)sn);
3188
3181
              break;
3189
3182
            }
3193
3186
              NSLog(@"WARNING ... waiting for reply %u since %@ on %@",
3194
3187
                sn, start_date, self);
3195
3188
            }
3196
 
          M_LOCK(IrefGate); isLocked = YES;
 
3189
          GS_M_LOCK(IrefGate); isLocked = YES;
3197
3190
        }
3198
3191
      if (node == 0)
3199
3192
        {
3204
3197
          rmc = node->value.obj;
3205
3198
          GSIMapRemoveKey(IreplyMap, (GSIMapKey)(NSUInteger)sn);
3206
3199
        }
3207
 
      M_UNLOCK(IrefGate); isLocked = NO;
 
3200
      GSM_UNLOCK(IrefGate); isLocked = NO;
3208
3201
      TEST_RELEASE(start_date);
3209
3202
      TEST_RELEASE(delay_date);
3210
3203
      TEST_RELEASE(timeout_date);
3231
3224
    {
3232
3225
      if (isLocked == YES)
3233
3226
        {
3234
 
          M_UNLOCK(IrefGate);
 
3227
          GSM_UNLOCK(IrefGate);
3235
3228
        }
3236
3229
      [localException raise];
3237
3230
    }
3249
3242
 
3250
3243
- (void) _doneInRmc: (NSPortCoder*)c
3251
3244
{
3252
 
  M_LOCK(IrefGate);
 
3245
  GS_M_LOCK(IrefGate);
3253
3246
  if (debug_connection > 5)
3254
3247
    {
3255
3248
      NSLog(@"done rmc %p", c);
3260
3253
    }
3261
3254
  [c dispatch]; /* Tell NSPortCoder to release the connection.  */
3262
3255
  RELEASE(c);
3263
 
  M_UNLOCK(IrefGate);
 
3256
  GSM_UNLOCK(IrefGate);
3264
3257
}
3265
3258
 
3266
3259
/*
3269
3262
 */
3270
3263
- (void) _failInRmc: (NSPortCoder*)c
3271
3264
{
3272
 
  M_LOCK(IrefGate);
 
3265
  GS_M_LOCK(IrefGate);
3273
3266
  if (cacheCoders == YES && IcachedDecoders != nil
3274
3267
    && [IcachedDecoders indexOfObjectIdenticalTo: c] == NSNotFound)
3275
3268
    {
3281
3274
    }
3282
3275
  [c dispatch]; /* Tell NSPortCoder to release the connection.  */
3283
3276
  RELEASE(c);
3284
 
  M_UNLOCK(IrefGate);
 
3277
  GSM_UNLOCK(IrefGate);
3285
3278
}
3286
3279
 
3287
3280
/*
3290
3283
 */
3291
3284
- (void) _failOutRmc: (NSPortCoder*)c
3292
3285
{
3293
 
  M_LOCK(IrefGate);
 
3286
  GS_M_LOCK(IrefGate);
3294
3287
  if (cacheCoders == YES && IcachedEncoders != nil
3295
3288
    && [IcachedEncoders indexOfObjectIdenticalTo: c] == NSNotFound)
3296
3289
    {
3298
3291
    }
3299
3292
  [c dispatch]; /* Tell NSPortCoder to release the connection.  */
3300
3293
  RELEASE(c);
3301
 
  M_UNLOCK(IrefGate);
 
3294
  GSM_UNLOCK(IrefGate);
3302
3295
}
3303
3296
 
3304
3297
- (NSPortCoder*) _makeInRmc: (NSMutableArray*)components
3308
3301
 
3309
3302
  NSParameterAssert(IisValid);
3310
3303
 
3311
 
  M_LOCK(IrefGate);
 
3304
  GS_M_LOCK(IrefGate);
3312
3305
  if (cacheCoders == YES && IcachedDecoders != nil
3313
3306
    && (count = [IcachedDecoders count]) > 0)
3314
3307
    {
3319
3312
    {
3320
3313
      coder = [recvCoderClass allocWithZone: NSDefaultMallocZone()];
3321
3314
    }
3322
 
  M_UNLOCK(IrefGate);
 
3315
  GSM_UNLOCK(IrefGate);
3323
3316
 
3324
3317
  coder = [coder initWithReceivePort: IreceivePort
3325
3318
                            sendPort:IsendPort
3343
3336
 
3344
3337
  NSParameterAssert(IisValid);
3345
3338
 
3346
 
  M_LOCK(IrefGate);
 
3339
  GS_M_LOCK(IrefGate);
3347
3340
  /*
3348
3341
   * Generate a new sequence number if required.
3349
3342
   */
3373
3366
    {
3374
3367
      coder = [sendCoderClass allocWithZone: NSDefaultMallocZone()];
3375
3368
    }
3376
 
  M_UNLOCK(IrefGate);
 
3369
  GSM_UNLOCK(IrefGate);
3377
3370
 
3378
3371
  coder = [coder initWithReceivePort: IreceivePort
3379
3372
                            sendPort:IsendPort
3436
3429
                              from: IreceivePort
3437
3430
                          reserved: [IsendPort reservedSpaceLength]];
3438
3431
 
3439
 
  M_LOCK(IrefGate);
 
3432
  GS_M_LOCK(IrefGate);
3440
3433
 
3441
3434
  /*
3442
3435
   * We replace the coder we have just used in the cache, and tell it not to
3448
3441
    }
3449
3442
  [c dispatch]; /* Tell NSPortCoder to release the connection.  */
3450
3443
  RELEASE(c);
3451
 
  M_UNLOCK(IrefGate);
 
3444
  GSM_UNLOCK(IrefGate);
3452
3445
 
3453
3446
  if (sent == NO)
3454
3447
    {
3493
3486
  unsigned              target;
3494
3487
  GSIMapNode            node;
3495
3488
 
3496
 
  M_LOCK(IrefGate);
 
3489
  GS_M_LOCK(IrefGate);
3497
3490
  NSParameterAssert (IisValid);
3498
3491
 
3499
3492
  object = anObj->_object;
3521
3514
    (GSIMapKey)(NSUInteger)target, (GSIMapVal)((id)anObj));
3522
3515
 
3523
3516
  if (debug_connection > 2)
3524
 
    NSLog(@"add local object (0x%x) target (0x%x) "
3525
 
          @"to connection (%@)", (uintptr_t)object, target, self);
 
3517
    NSLog(@"add local object (%p) target (0x%x) "
 
3518
          @"to connection (%@)", object, target, self);
3526
3519
 
3527
 
  M_UNLOCK(IrefGate);
 
3520
  GSM_UNLOCK(IrefGate);
3528
3521
}
3529
3522
 
3530
3523
- (NSDistantObject*) retainOrAddLocal: (NSDistantObject*)proxy
3534
3527
  NSDistantObject       *p;
3535
3528
 
3536
3529
  /* Don't assert (IisValid); */
3537
 
  M_LOCK(IrefGate);
 
3530
  GS_M_LOCK(IrefGate);
3538
3531
  node = GSIMapNodeForKey(IlocalObjects, (GSIMapKey)object);
3539
3532
  if (node == 0)
3540
3533
    {
3550
3543
      p = proxy;
3551
3544
      [self addLocalObject: p];
3552
3545
    }
3553
 
  M_UNLOCK(IrefGate);
 
3546
  GSM_UNLOCK(IrefGate);
3554
3547
  return p;
3555
3548
}
3556
3549
 
3561
3554
  unsigned      val = 0;
3562
3555
  GSIMapNode    node;
3563
3556
 
3564
 
  M_LOCK(IrefGate);
 
3557
  GS_M_LOCK(IrefGate);
3565
3558
  anObj = prox->_object;
3566
3559
  node = GSIMapNodeForKey(IlocalObjects, (GSIMapKey)anObj);
3567
3560
 
3585
3578
          CachedLocalObject     *item;
3586
3579
 
3587
3580
          (prox->_counter) = 0;
3588
 
          M_LOCK(cached_proxies_gate);
 
3581
          GS_M_LOCK(cached_proxies_gate);
3589
3582
          if (timer == nil)
3590
3583
            {
3591
3584
              timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
3596
3589
            }
3597
3590
          item = [CachedLocalObject newWithObject: prox time: 5];
3598
3591
          NSMapInsert(targetToCached, (void*)(uintptr_t)target, item);
3599
 
          M_UNLOCK(cached_proxies_gate);
 
3592
          GSM_UNLOCK(cached_proxies_gate);
3600
3593
          RELEASE(item);
3601
3594
          if (debug_connection > 3)
3602
 
            NSLog(@"placed local object (0x%x) target (0x%x) in cache",
3603
 
                        (uintptr_t)anObj, target);
 
3595
            NSLog(@"placed local object (%p) target (0x%x) in cache",
 
3596
                        anObj, target);
3604
3597
        }
3605
3598
 
3606
3599
      /*
3615
3608
      GSIMapRemoveKey(IlocalTargets, (GSIMapKey)(NSUInteger)target);
3616
3609
 
3617
3610
      if (debug_connection > 2)
3618
 
        NSLog(@"removed local object (0x%x) target (0x%x) "
3619
 
          @"from connection (%@) (ref %d)", (uintptr_t)anObj, target, self, val);
 
3611
        NSLog(@"removed local object (%p) target (0x%x) "
 
3612
          @"from connection (%@) (ref %d)", anObj, target, self, val);
3620
3613
    }
3621
 
  M_UNLOCK(IrefGate);
 
3614
  GSM_UNLOCK(IrefGate);
3622
3615
}
3623
3616
 
3624
3617
- (void) _release_target: (unsigned)target count: (unsigned)number
3664
3657
  NSDistantObject       *proxy = nil;
3665
3658
  GSIMapNode            node;
3666
3659
 
3667
 
  M_LOCK(IrefGate);
 
3660
  GS_M_LOCK(IrefGate);
3668
3661
 
3669
3662
  /*
3670
3663
   * Try a quick lookup to see if the target references a local object
3685
3678
    {
3686
3679
      CachedLocalObject *cached;
3687
3680
 
3688
 
      M_LOCK(cached_proxies_gate);
 
3681
      GS_M_LOCK(cached_proxies_gate);
3689
3682
      cached = NSMapGet (targetToCached, (void*)(uintptr_t)target);
3690
3683
      if (cached != nil)
3691
3684
        {
3700
3693
          if (debug_connection > 3)
3701
3694
            NSLog(@"target (0x%x) moved from cache", target);
3702
3695
        }
3703
 
      M_UNLOCK(cached_proxies_gate);
 
3696
      GSM_UNLOCK(cached_proxies_gate);
3704
3697
    }
3705
3698
 
3706
3699
  /*
3712
3705
      NSHashEnumerator  enumerator;
3713
3706
      NSConnection      *c;
3714
3707
 
3715
 
      M_LOCK(connection_table_gate);
 
3708
      GS_M_LOCK(connection_table_gate);
3716
3709
      enumerator = NSEnumerateHashTable(connection_table);
3717
3710
      while (proxy == nil
3718
3711
        && (c = (NSConnection*)NSNextHashEnumeratorItem(&enumerator)) != nil)
3719
3712
        {
3720
3713
          if (c != self && [c isValid] == YES)
3721
3714
            {
3722
 
              M_LOCK(GSIVar(c, _refGate));
 
3715
              GS_M_LOCK(GSIVar(c, _refGate));
3723
3716
              node = GSIMapNodeForKey(GSIVar(c, _localTargets),
3724
3717
                (GSIMapKey)(NSUInteger)target);
3725
3718
              if (node != 0)
3749
3742
                  GSIMapAddPair(IlocalTargets,
3750
3743
                    (GSIMapKey)(NSUInteger)target, (GSIMapVal)((id)proxy));
3751
3744
                }
3752
 
              M_UNLOCK(GSIVar(c, _refGate));
 
3745
              GSM_UNLOCK(GSIVar(c, _refGate));
3753
3746
            }
3754
3747
        }
3755
3748
      NSEndHashTableEnumeration(&enumerator);
3756
 
      M_UNLOCK(connection_table_gate);
 
3749
      GSM_UNLOCK(connection_table_gate);
3757
3750
    }
3758
3751
 
3759
 
  M_UNLOCK(IrefGate);
 
3752
  GSM_UNLOCK(IrefGate);
3760
3753
 
3761
3754
  if (proxy == nil)
3762
3755
    {
3768
3761
 
3769
3762
- (void) vendLocal: (NSDistantObject*)aProxy
3770
3763
{
3771
 
  M_LOCK(IrefGate);
 
3764
  GS_M_LOCK(IrefGate);
3772
3765
  aProxy->_counter++;
3773
 
  M_UNLOCK(IrefGate);
 
3766
  GSM_UNLOCK(IrefGate);
3774
3767
}
3775
3768
 
3776
3769
- (void) acquireProxyForTarget: (unsigned)target
3779
3772
  GSIMapNode            node;
3780
3773
 
3781
3774
  /* Don't assert (IisValid); */
3782
 
  M_LOCK(IrefGate);
 
3775
  GS_M_LOCK(IrefGate);
3783
3776
  node = GSIMapNodeForKey(IremoteProxies, (GSIMapKey)(NSUInteger)target);
3784
3777
  if (node == 0)
3785
3778
    {
3789
3782
    {
3790
3783
      found = node->value.obj;
3791
3784
    }
3792
 
  M_UNLOCK(IrefGate);
 
3785
  GSM_UNLOCK(IrefGate);
3793
3786
  if (found == nil)
3794
3787
    {
3795
3788
      NS_DURING
3833
3826
 
3834
3827
- (void) removeProxy: (NSDistantObject*)aProxy
3835
3828
{
3836
 
  M_LOCK(IrefGate);
 
3829
  GS_M_LOCK(IrefGate);
3837
3830
  if (IisValid == YES)
3838
3831
    {
3839
3832
      unsigned          target;
3858
3851
          [self _release_target: target count: count];
3859
3852
        }
3860
3853
    }
3861
 
  M_UNLOCK(IrefGate);
 
3854
  GSM_UNLOCK(IrefGate);
3862
3855
}
3863
3856
 
3864
3857
 
3890
3883
  NSParameterAssert(aProxy == nil || [aProxy connectionForProxy] == self);
3891
3884
  NSParameterAssert(aProxy == nil || aTarget == aProxy->_handle);
3892
3885
 
3893
 
  M_LOCK(IrefGate);
 
3886
  GS_M_LOCK(IrefGate);
3894
3887
  node = GSIMapNodeForKey(IremoteProxies, (GSIMapKey)(NSUInteger)aTarget);
3895
3888
  if (node == 0)
3896
3889
    {
3916
3909
    {
3917
3910
      p->_counter++;
3918
3911
    }
3919
 
  M_UNLOCK(IrefGate);
 
3912
  GSM_UNLOCK(IrefGate);
3920
3913
  return p;
3921
3914
}
3922
3915
 
3926
3919
  GSIMapNode            node;
3927
3920
 
3928
3921
  /* Don't assert (IisValid); */
3929
 
  M_LOCK(IrefGate);
 
3922
  GS_M_LOCK(IrefGate);
3930
3923
  node = GSIMapNodeForKey(IlocalObjects, (GSIMapKey)(NSUInteger)anObj);
3931
3924
  if (node == 0)
3932
3925
    {
3936
3929
    {
3937
3930
      ret = node->value.obj;
3938
3931
    }
3939
 
  M_UNLOCK(IrefGate);
 
3932
  GSM_UNLOCK(IrefGate);
3940
3933
  return ret;
3941
3934
}
3942
3935
 
3946
3939
  GSIMapNode            node;
3947
3940
 
3948
3941
  /* Don't assert (IisValid); */
3949
 
  M_LOCK(IrefGate);
 
3942
  GS_M_LOCK(IrefGate);
3950
3943
  node = GSIMapNodeForKey(IlocalTargets, (GSIMapKey)(NSUInteger)target);
3951
3944
  if (node == 0)
3952
3945
    {
3956
3949
    {
3957
3950
      ret = node->value.obj;
3958
3951
    }
3959
 
  M_UNLOCK(IrefGate);
 
3952
  GSM_UNLOCK(IrefGate);
3960
3953
  return ret;
3961
3954
}
3962
3955
 
4012
4005
      NSEnumerator      *enumerator;
4013
4006
      NSConnection      *c;
4014
4007
 
4015
 
      M_LOCK (connection_table_gate);
 
4008
      GS_M_LOCK (connection_table_gate);
4016
4009
      enumerator = [NSAllHashTableObjects(connection_table) objectEnumerator];
4017
 
      M_UNLOCK (connection_table_gate);
 
4010
      GSM_UNLOCK (connection_table_gate);
4018
4011
 
4019
4012
      /*
4020
4013
       * We enumerate an array copy of the contents of the hash table