Ignore:
Timestamp:
Dec 12, 2012, 8:22:57 PM (9 years ago)
Author:
jordan
Message:

(trunk) #5168 'make libtransmission's public funcs nonblocking when possible' -- first attempt.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r13631 r13651  
    153153
    154154bool
    155 tr_torrentIsPieceTransferAllowed (const tr_torrent  * tor,
    156                                   tr_direction        direction)
    157 {
    158     unsigned int limit;
    159     bool allowed = true;
    160 
    161     if (tr_torrentUsesSpeedLimit (tor, direction))
     155tr_torrentIsPieceTransferAllowed (tr_torrent   * tor,
     156                                  tr_direction   direction)
     157{
     158  bool allowed = false;
     159
     160  assert (tr_isDirection (direction));
     161
     162  if (tr_torrentRef (tor))
     163    {
     164      unsigned int limit;
     165
     166      allowed = true;
     167
     168      if (tr_torrentUsesSpeedLimit (tor, direction))
    162169        if (tr_torrentGetSpeedLimit_Bps (tor, direction) <= 0)
     170          allowed = false;
     171
     172      if (tr_torrentUsesSessionLimits (tor))
     173        if (tr_sessionGetActiveSpeedLimit_Bps (tor->session, direction, &limit))
     174          if (limit <= 0)
    163175            allowed = false;
    164 
    165     if (tr_torrentUsesSessionLimits (tor))
    166         if (tr_sessionGetActiveSpeedLimit_Bps (tor->session, direction, &limit))
    167             if (limit <= 0)
    168                 allowed = false;
    169 
    170     return allowed;
     176    }
     177
     178  return allowed;
    171179}
    172180
     
    199207}
    200208unsigned int
    201 tr_torrentGetSpeedLimit_KBps (const tr_torrent * tor, tr_direction dir)
    202 {
    203     return toSpeedKBps (tr_torrentGetSpeedLimit_Bps (tor, dir));
     209tr_torrentGetSpeedLimit_KBps (tr_torrent * tor, tr_direction dir)
     210{
     211  unsigned int limit = 0;
     212
     213  assert (tr_isDirection (dir));
     214
     215  if (tr_torrentRef (tor))
     216    {
     217      limit = toSpeedKBps (tr_torrentGetSpeedLimit_Bps (tor, dir));
     218      tr_torrentUnref (tor);
     219    }
     220
     221  return limit;
    204222}
    205223
     
    207225tr_torrentUseSpeedLimit (tr_torrent * tor, tr_direction dir, bool do_use)
    208226{
    209     assert (tr_isTorrent (tor));
    210     assert (tr_isDirection (dir));
    211 
    212     if (tr_bandwidthSetLimited (&tor->bandwidth, dir, do_use))
    213         tr_torrentSetDirty (tor);
     227  assert (tr_isTorrent (tor));
     228  assert (tr_isDirection (dir));
     229
     230  if (tr_bandwidthSetLimited (&tor->bandwidth, dir, do_use))
     231    tr_torrentSetDirty (tor);
    214232}
    215233
    216234bool
    217 tr_torrentUsesSpeedLimit (const tr_torrent * tor, tr_direction dir)
    218 {
    219     assert (tr_isTorrent (tor));
    220     assert (tr_isDirection (dir));
    221 
    222     return tr_bandwidthIsLimited (&tor->bandwidth, dir);
     235tr_torrentUsesSpeedLimit (tr_torrent * tor, tr_direction dir)
     236{
     237  bool limited = false;
     238
     239  if (tr_torrentRef (tor))
     240    {
     241      limited = tr_bandwidthIsLimited (&tor->bandwidth, dir);
     242      tr_torrentUnref (tor);
     243    }
     244
     245  return limited;
    223246}
    224247
     
    226249tr_torrentUseSessionLimits (tr_torrent * tor, bool doUse)
    227250{
    228     bool changed;
    229 
    230     assert (tr_isTorrent (tor));
    231 
    232     changed = tr_bandwidthHonorParentLimits (&tor->bandwidth, TR_UP, doUse);
    233     changed |= tr_bandwidthHonorParentLimits (&tor->bandwidth, TR_DOWN, doUse);
    234 
    235     if (changed)
    236         tr_torrentSetDirty (tor);
     251  bool changed;
     252
     253  assert (tr_isTorrent (tor));
     254
     255  changed = tr_bandwidthHonorParentLimits (&tor->bandwidth, TR_UP, doUse);
     256  changed |= tr_bandwidthHonorParentLimits (&tor->bandwidth, TR_DOWN, doUse);
     257
     258  if (changed)
     259    tr_torrentSetDirty (tor);
    237260}
    238261
    239262bool
    240 tr_torrentUsesSessionLimits (const tr_torrent * tor)
    241 {
    242     assert (tr_isTorrent (tor));
    243 
    244     return tr_bandwidthAreParentLimitsHonored (&tor->bandwidth, TR_UP);
     263tr_torrentUsesSessionLimits (tr_torrent * tor)
     264{
     265  bool limited = false;
     266
     267  if (tr_torrentRef (tor))
     268    {
     269      limited = tr_bandwidthAreParentLimitsHonored (&tor->bandwidth, TR_UP);
     270      tr_torrentUnref (tor);
     271    }
     272
     273  return limited;
    245274}
    246275
     
    252281tr_torrentSetRatioMode (tr_torrent *  tor, tr_ratiolimit mode)
    253282{
    254     assert (tr_isTorrent (tor));
    255     assert (mode==TR_RATIOLIMIT_GLOBAL || mode==TR_RATIOLIMIT_SINGLE || mode==TR_RATIOLIMIT_UNLIMITED);
    256 
    257     if (mode != tor->ratioLimitMode)
    258     {
    259         tor->ratioLimitMode = mode;
    260 
    261         tr_torrentSetDirty (tor);
     283  assert (tr_isTorrent (tor));
     284  assert (mode==TR_RATIOLIMIT_GLOBAL || mode==TR_RATIOLIMIT_SINGLE || mode==TR_RATIOLIMIT_UNLIMITED);
     285
     286  if (mode != tor->ratioLimitMode)
     287    {
     288      tor->ratioLimitMode = mode;
     289
     290      tr_torrentSetDirty (tor);
    262291    }
    263292}
     
    266295tr_torrentGetRatioMode (const tr_torrent * tor)
    267296{
    268     assert (tr_isTorrent (tor));
    269 
    270     return tor->ratioLimitMode;
     297  assert (tr_isTorrent (tor));
     298
     299  return tor->ratioLimitMode;
    271300}
    272301
     
    274303tr_torrentSetRatioLimit (tr_torrent * tor, double desiredRatio)
    275304{
    276     assert (tr_isTorrent (tor));
    277 
    278     if ((int)(desiredRatio*100.0) != (int)(tor->desiredRatio*100.0))
    279     {
    280         tor->desiredRatio = desiredRatio;
    281 
    282         tr_torrentSetDirty (tor);
     305  assert (tr_isTorrent (tor));
     306
     307  if ((int)(desiredRatio*100.0) != (int)(tor->desiredRatio*100.0))
     308    {
     309      tor->desiredRatio = desiredRatio;
     310
     311      tr_torrentSetDirty (tor);
    283312    }
    284313}
    285314
    286315double
    287 tr_torrentGetRatioLimit (const tr_torrent * tor)
    288 {
    289     assert (tr_isTorrent (tor));
    290 
    291     return tor->desiredRatio;
     316tr_torrentGetRatioLimit (tr_torrent * tor)
     317{
     318  double limit = 0;
     319
     320  if (tr_torrentRef (tor))
     321    {
     322      limit = tor->desiredRatio;
     323      tr_torrentUnref (tor);
     324    }
     325
     326  return limit;
    292327}
    293328
    294329bool
    295 tr_torrentGetSeedRatio (const tr_torrent * tor, double * ratio)
    296 {
    297     bool isLimited;
    298 
    299     switch (tr_torrentGetRatioMode (tor))
    300     {
    301         case TR_RATIOLIMIT_SINGLE:
     330tr_torrentGetSeedRatio (tr_torrent * tor, double * ratio)
     331{
     332  bool isLimited = false;
     333
     334  if (tr_torrentRef (tor))
     335    {
     336      switch (tr_torrentGetRatioMode (tor))
     337        {
     338          case TR_RATIOLIMIT_SINGLE:
    302339            isLimited = true;
    303340            if (ratio)
    304                 *ratio = tr_torrentGetRatioLimit (tor);
     341              *ratio = tr_torrentGetRatioLimit (tor);
    305342            break;
    306343
    307         case TR_RATIOLIMIT_GLOBAL:
     344          case TR_RATIOLIMIT_GLOBAL:
    308345            isLimited = tr_sessionIsRatioLimited (tor->session);
    309346            if (isLimited && ratio)
    310                 *ratio = tr_sessionGetRatioLimit (tor->session);
     347              *ratio = tr_sessionGetRatioLimit (tor->session);
    311348            break;
    312349
    313         default: /* TR_RATIOLIMIT_UNLIMITED */
     350          default: /* TR_RATIOLIMIT_UNLIMITED */
    314351            isLimited = false;
    315352            break;
    316     }
    317 
    318     return isLimited;
     353        }
     354
     355      tr_torrentUnref (tor);
     356    }
     357
     358  return isLimited;
    319359}
    320360
     
    809849    tor->uniqueId = nextUniqueId++;
    810850    tor->magicNumber = TORRENT_MAGIC_NUMBER;
     851    tor->refCount = 1;
    811852    tor->queuePosition = session->torrentCount;
    812853
     
    10971138}
    10981139
    1099 static tr_torrent_activity
    1100 torrentGetActivity (const tr_torrent * tor)
    1101 {
    1102     const bool is_seed = tr_torrentIsSeed (tor);
    1103     assert (tr_isTorrent (tor));
    1104 
    1105     if (tor->verifyState == TR_VERIFY_NOW)
    1106         return TR_STATUS_CHECK;
    1107 
    1108     if (tor->verifyState == TR_VERIFY_WAIT)
    1109         return TR_STATUS_CHECK_WAIT;
    1110 
    1111     if (tor->isRunning)
    1112         return is_seed ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
    1113 
    1114     if (tr_torrentIsQueued (tor)) {
    1115         if (is_seed && tr_sessionGetQueueEnabled (tor->session, TR_UP))
    1116             return TR_STATUS_SEED_WAIT;
    1117         if (!is_seed && tr_sessionGetQueueEnabled (tor->session, TR_DOWN))
    1118             return TR_STATUS_DOWNLOAD_WAIT;
    1119     }
    1120 
    1121     return TR_STATUS_STOPPED;
    1122 }
    1123 
    11241140tr_torrent_activity
    1125 tr_torrentGetActivity (tr_torrent * tor)
    1126 {
    1127     /* FIXME: is this call still needed? */
    1128     tr_torrentRecheckCompleteness (tor);
    1129 
    1130     return torrentGetActivity (tor);
     1141tr_torrentGetActivity (const tr_torrent * tor)
     1142{
     1143  tr_torrent_activity ret = TR_STATUS_STOPPED;
     1144
     1145  const bool is_seed = tr_torrentIsSeed (tor);
     1146
     1147  if (tor->verifyState == TR_VERIFY_NOW)
     1148    {
     1149      ret = TR_STATUS_CHECK;
     1150    }
     1151  else if (tor->verifyState == TR_VERIFY_WAIT)
     1152    {
     1153      ret = TR_STATUS_CHECK_WAIT;
     1154    }
     1155  else if (tor->isRunning)
     1156    {
     1157      ret = is_seed ? TR_STATUS_SEED : TR_STATUS_DOWNLOAD;
     1158    }
     1159  else if (tr_torrentIsQueued (tor))
     1160    {
     1161      if (is_seed && tr_sessionGetQueueEnabled (tor->session, TR_UP))
     1162        ret = TR_STATUS_SEED_WAIT;
     1163      else if (!is_seed && tr_sessionGetQueueEnabled (tor->session, TR_DOWN))
     1164        ret = TR_STATUS_DOWNLOAD_WAIT;
     1165    }
     1166
     1167  return ret;
    11311168}
    11321169
     
    11351172{
    11361173    int idle_secs;
    1137     const tr_torrent_activity activity = torrentGetActivity (tor);
     1174    const tr_torrent_activity activity = tr_torrentGetActivity (tor);
    11381175
    11391176    if ((activity == TR_STATUS_DOWNLOAD || activity == TR_STATUS_SEED) && tor->startDate != 0)
     
    11541191
    11551192static double
    1156 getVerifyProgress (const tr_torrent * tor)
    1157 {
    1158     double d = 0;
    1159 
    1160     assert (tr_isTorrent (tor));
    1161 
    1162     if (tr_torrentHasMetadata (tor))
    1163     {
    1164         tr_piece_index_t i, n;
    1165         tr_piece_index_t checked = 0;
    1166 
    1167         for (i=0, n=tor->info.pieceCount; i!=n; ++i)
     1193getVerifyProgress (tr_torrent * tor)
     1194{
     1195  double d = 0;
     1196
     1197  if (tr_torrentRef (tor))
     1198    {
     1199      if (tr_torrentHasMetadata (tor))
     1200        {
     1201          tr_piece_index_t i, n;
     1202          tr_piece_index_t checked = 0;
     1203
     1204          for (i=0, n=tor->info.pieceCount; i!=n; ++i)
    11681205            if (tor->info.pieces[i].timeChecked)
    1169                 ++checked;
    1170 
    1171         d = checked / (double)tor->info.pieceCount;
    1172     }
    1173 
    1174     return d;
     1206              ++checked;
     1207
     1208          d = checked / (double)tor->info.pieceCount;
     1209        }
     1210
     1211      tr_torrentUnref (tor);
     1212    }
     1213
     1214  return d;
    11751215}
    11761216
     
    11851225    uint16_t                seedIdleMinutes;
    11861226
    1187     if (!tor)
     1227    if (!tr_torrentRef(tor))
    11881228        return NULL;
    1189 
    1190     assert (tr_isTorrent (tor));
    1191     tr_torrentLock (tor);
    11921229
    11931230    tor->lastStatTime = tr_time ();
     
    13091346        s->seedRatioPercentDone = (double)(seedRatioBytesGoal - seedRatioBytesLeft) / seedRatioBytesGoal;
    13101347
    1311     tr_torrentUnlock (tor);
    1312 
    13131348    /* test some of the constraints */
    13141349    assert (s->sizeWhenDone <= tor->info.totalSize);
    13151350    assert (s->leftUntilDone <= s->sizeWhenDone);
    13161351    assert (s->desiredAvailable <= s->leftUntilDone);
     1352
     1353    tr_torrentUnref (tor);
     1354
    13171355    return s;
    13181356}
     
    13971435
    13981436double*
    1399 tr_torrentWebSpeeds_KBps (const tr_torrent * tor)
    1400 {
    1401     double * ret = NULL;
    1402 
    1403     if (tr_isTorrent (tor))
    1404     {
    1405         tr_torrentLock (tor);
    1406         ret = tr_peerMgrWebSpeeds_KBps (tor);
    1407         tr_torrentUnlock (tor);
    1408     }
    1409 
    1410     return ret;
     1437tr_torrentWebSpeeds_KBps (tr_torrent * tor)
     1438{
     1439  double * ret = NULL;
     1440
     1441  if (tr_torrentRef (tor))
     1442    {
     1443      ret = tr_peerMgrWebSpeeds_KBps (tor);
     1444      tr_torrentUnref (tor);
     1445    }
     1446
     1447  return ret;
    14111448}
    14121449
    14131450tr_peer_stat *
    1414 tr_torrentPeers (const tr_torrent * tor, int * peerCount)
    1415 {
    1416     tr_peer_stat * ret = NULL;
    1417 
    1418     if (tr_isTorrent (tor))
    1419     {
    1420         tr_torrentLock (tor);
    1421         ret = tr_peerMgrPeerStats (tor, peerCount);
    1422         tr_torrentUnlock (tor);
    1423     }
    1424 
    1425     return ret;
     1451tr_torrentPeers (tr_torrent * tor, int * peerCount)
     1452{
     1453  tr_peer_stat * ret = NULL;
     1454
     1455  if (tr_torrentRef (tor))
     1456    {
     1457      ret = tr_peerMgrPeerStats (tor, peerCount);
     1458      tr_torrentUnref (tor);
     1459    }
     1460
     1461  return ret;
    14261462}
    14271463
     
    14291465tr_torrentPeersFree (tr_peer_stat * peers, int peerCount UNUSED)
    14301466{
    1431     tr_free (peers);
     1467  tr_free (peers);
    14321468}
    14331469
    14341470tr_tracker_stat *
    1435 tr_torrentTrackers (const tr_torrent * torrent, int * setmeTrackerCount)
    1436 {
    1437     tr_tracker_stat * ret = NULL;
    1438 
    1439     if (tr_isTorrent (torrent))
    1440     {
    1441         tr_torrentLock (torrent);
    1442         ret = tr_announcerStats (torrent, setmeTrackerCount);
    1443         tr_torrentUnlock (torrent);
    1444     }
    1445 
    1446     return ret;
     1471tr_torrentTrackers (tr_torrent * torrent, int * setmeTrackerCount)
     1472{
     1473  tr_tracker_stat * ret = NULL;
     1474
     1475  if (tr_torrentRef (torrent))
     1476    {
     1477      ret = tr_announcerStats (torrent, setmeTrackerCount);
     1478      tr_torrentUnref (torrent);
     1479    }
     1480
     1481  return ret;
    14471482}
    14481483
     
    14541489
    14551490void
    1456 tr_torrentAvailability (const tr_torrent * tor, int8_t * tab, int size)
    1457 {
    1458     if (tr_isTorrent (tor) && (tab != NULL) && (size > 0))
    1459     {
    1460         tr_torrentLock (tor);
    1461         tr_peerMgrTorrentAvailability (tor, tab, size);
    1462         tr_torrentUnlock (tor);
    1463     }
    1464 }
    1465 
    1466 void
    1467 tr_torrentAmountFinished (const tr_torrent * tor,
    1468                           float *            tab,
    1469                           int                size)
    1470 {
    1471     assert (tr_isTorrent (tor));
    1472 
    1473     tr_torrentLock (tor);
    1474     tr_cpGetAmountDone (&tor->completion, tab, size);
    1475     tr_torrentUnlock (tor);
     1491tr_torrentAvailability (tr_torrent * tor, int8_t * tab, int size)
     1492{
     1493  if ((tab != NULL) && (size > 0) && tr_torrentRef (tor))
     1494    {
     1495      tr_peerMgrTorrentAvailability (tor, tab, size);
     1496      tr_torrentUnref (tor);
     1497    }
     1498}
     1499
     1500void
     1501tr_torrentAmountFinished (tr_torrent * tor, float * tab, int size)
     1502{
     1503  if (tr_torrentRef (tor))
     1504    {
     1505      tr_cpGetAmountDone (&tor->completion, tab, size);
     1506      tr_torrentUnref (tor);
     1507    }
    14761508}
    14771509
     
    16371669torrentStart (tr_torrent * tor, bool bypass_queue)
    16381670{
    1639     switch (torrentGetActivity (tor))
     1671    switch (tr_torrentGetActivity (tor))
    16401672    {
    16411673        case TR_STATUS_SEED:
     
    17761808stopTorrent (void * vtor)
    17771809{
    1778     tr_torrent * tor = vtor;
    1779     tr_torinf (tor, "Pausing");
    1780 
    1781     assert (tr_isTorrent (tor));
    1782 
    1783     tr_torrentLock (tor);
    1784 
    1785     tr_verifyRemove (tor);
    1786     torrentSetQueued (tor, false);
    1787     tr_peerMgrStopTorrent (tor);
    1788     tr_announcerTorrentStopped (tor);
    1789     tr_cacheFlushTorrent (tor->session->cache, tor);
    1790 
    1791     tr_fdTorrentClose (tor->session, tor->uniqueId);
    1792 
    1793     if (!tor->isDeleting)
     1810  tr_torrent * tor = vtor;
     1811  tr_torinf (tor, "Pausing");
     1812
     1813  if (tr_torrentLock (tor))
     1814    {
     1815      tr_verifyRemove (tor);
     1816      torrentSetQueued (tor, false);
     1817      tr_peerMgrStopTorrent (tor);
     1818      tr_announcerTorrentStopped (tor);
     1819      tr_cacheFlushTorrent (tor->session->cache, tor);
     1820
     1821      tr_fdTorrentClose (tor->session, tor->uniqueId);
     1822
     1823      if (!tor->isDeleting)
    17941824        tr_torrentSave (tor);
    17951825
    1796     tr_torrentUnlock (tor);
     1826      tr_torrentUnlock (tor);
     1827    }
    17971828}
    17981829
     
    18421873
    18431874void
    1844 tr_torrentFree (tr_torrent * tor)
    1845 {
    1846     if (tr_isTorrent (tor))
    1847     {
    1848         tr_session * session = tor->session;
    1849         assert (tr_isSession (session));
    1850         tr_sessionLock (session);
    1851 
    1852         tr_torrentClearCompletenessCallback (tor);
    1853         tr_runInEventThread (session, closeTorrent, tor);
    1854 
    1855         tr_sessionUnlock (session);
    1856     }
     1875tr_torrentUnref (tr_torrent * tor)
     1876{
     1877  assert (tr_isTorrent (tor));
     1878
     1879  if (--tor->refCount == 0)
     1880    {
     1881      tr_session * session = tor->session;
     1882
     1883      tr_sessionLock (session);
     1884      tr_torrentClearCompletenessCallback (tor);
     1885      tr_runInEventThread (session, closeTorrent, tor);
     1886      tr_sessionUnlock (session);
     1887    }
     1888}
     1889
     1890bool
     1891tr_torrentLock (const tr_torrent * tor)
     1892{
     1893  if (!tr_isTorrent (tor))
     1894    return false;
     1895
     1896  tr_sessionLock (tor->session);
     1897  return true;
     1898}
     1899
     1900bool
     1901tr_torrentRef (tr_torrent * tor)
     1902{
     1903  if (!tr_isTorrent (tor))
     1904    return false;
     1905
     1906  ++tor->refCount;
     1907  return true;
    18571908}
    18581909
     
    20382089tr_torrentRecheckCompleteness (tr_torrent * tor)
    20392090{
    2040     tr_completeness completeness;
    2041 
    2042     assert (tr_isTorrent (tor));
    2043 
    2044     tr_torrentLock (tor);
    2045 
    2046     completeness = tr_cpGetStatus (&tor->completion);
    2047 
    2048     if (completeness != tor->completeness)
    2049     {
    2050         const int recentChange = tor->downloadedCur != 0;
    2051         const bool wasLeeching = !tr_torrentIsSeed (tor);
    2052         const bool wasRunning = tor->isRunning;
    2053 
    2054         if (recentChange)
     2091  if (tr_torrentLock (tor))
     2092    {
     2093      const tr_completeness completeness = tr_cpGetStatus (&tor->completion);
     2094
     2095      if (completeness != tor->completeness)
    20552096        {
     2097          const int recentChange = tor->downloadedCur != 0;
     2098          const bool wasLeeching = !tr_torrentIsSeed (tor);
     2099          const bool wasRunning = tor->isRunning;
     2100
     2101          if (recentChange)
    20562102            tr_torinf (tor, _("State changed from \"%1$s\" to \"%2$s\""),
    2057                       getCompletionString (tor->completeness),
    2058                       getCompletionString (completeness));
     2103                       getCompletionString (tor->completeness),
     2104                       getCompletionString (completeness));
     2105
     2106          tor->completeness = completeness;
     2107          tr_fdTorrentClose (tor->session, tor->uniqueId);
     2108
     2109          fireCompletenessChange (tor, completeness, wasRunning);
     2110
     2111          if (tr_torrentIsSeed (tor))
     2112            {
     2113              if (recentChange)
     2114                {
     2115                  tr_announcerTorrentCompleted (tor);
     2116                  tor->doneDate = tor->anyDate = tr_time ();
     2117                }
     2118
     2119              if (wasLeeching && wasRunning)
     2120                {
     2121                  /* clear interested flag on all peers */
     2122                  tr_peerMgrClearInterest (tor);
     2123
     2124                  /* if completeness was TR_LEECH then the seed limit check will have been skipped in bandwidthPulse */
     2125                  tr_torrentCheckSeedLimit (tor);
     2126                }
     2127
     2128              if (tor->currentDir == tor->incompleteDir)
     2129                tr_torrentSetLocation (tor, tor->downloadDir, true, NULL, NULL);
     2130
     2131              if (tr_sessionIsTorrentDoneScriptEnabled (tor->session))
     2132                torrentCallScript (tor, tr_sessionGetTorrentDoneScript (tor->session));
     2133            }
     2134
     2135          tr_torrentSetDirty (tor);
    20592136        }
    20602137
    2061         tor->completeness = completeness;
    2062         tr_fdTorrentClose (tor->session, tor->uniqueId);
    2063 
    2064         fireCompletenessChange (tor, completeness, wasRunning);
    2065 
    2066         if (tr_torrentIsSeed (tor))
    2067         {
    2068             if (recentChange)
    2069             {
    2070                 tr_announcerTorrentCompleted (tor);
    2071                 tor->doneDate = tor->anyDate = tr_time ();
    2072             }
    2073 
    2074             if (wasLeeching && wasRunning)
    2075             {
    2076                 /* clear interested flag on all peers */
    2077                 tr_peerMgrClearInterest (tor);
    2078 
    2079                 /* if completeness was TR_LEECH then the seed limit check will have been skipped in bandwidthPulse */
    2080                 tr_torrentCheckSeedLimit (tor);
    2081             }
    2082 
    2083             if (tor->currentDir == tor->incompleteDir)
    2084                 tr_torrentSetLocation (tor, tor->downloadDir, true, NULL, NULL);
    2085 
    2086             if (tr_sessionIsTorrentDoneScriptEnabled (tor->session))
    2087                 torrentCallScript (tor, tr_sessionGetTorrentDoneScript (tor->session));
    2088         }
    2089 
    2090         tr_torrentSetDirty (tor);
    2091     }
    2092 
    2093     tr_torrentUnlock (tor);
     2138      tr_torrentUnlock (tor);
     2139    }
    20942140}
    20952141
     
    21612207
    21622208tr_priority_t*
    2163 tr_torrentGetFilePriorities (const tr_torrent * tor)
    2164 {
    2165     tr_file_index_t i;
    2166     tr_priority_t * p;
    2167 
    2168     assert (tr_isTorrent (tor));
    2169 
    2170     tr_torrentLock (tor);
    2171     p = tr_new0 (tr_priority_t, tor->info.fileCount);
    2172     for (i = 0; i < tor->info.fileCount; ++i)
     2209tr_torrentGetFilePriorities (tr_torrent * tor)
     2210{
     2211  tr_file_index_t i;
     2212  tr_priority_t * p = NULL;
     2213
     2214  if (tr_torrentRef (tor))
     2215    {
     2216      p = tr_new0 (tr_priority_t, tor->info.fileCount);
     2217
     2218      for (i=0; i<tor->info.fileCount; ++i)
    21732219        p[i] = tor->info.files[i].priority;
    2174     tr_torrentUnlock (tor);
    2175 
    2176     return p;
     2220
     2221      tr_torrentUnref (tor);
     2222    }
     2223
     2224  return p;
    21772225}
    21782226
Note: See TracChangeset for help on using the changeset viewer.