/[LeafOK_CVS]/lbbs/src/section_list.c
ViewVC logotype

Diff of /lbbs/src/section_list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.34 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.55 by sysadm, Wed Nov 5 04:19:21 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                             section_list.c  -  description  /*
3                                                           -------------------   * section_list
4          Copyright            : (C) 2004-2025 by Leaflet   *   - data models and basic operations of section and article
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "log.h"  #include "log.h"
10  #include "section_list.h"  #include "section_list.h"
11  #include "trie_dict.h"  #include "trie_dict.h"
12    #include "user_list.h"
13  #include <errno.h>  #include <errno.h>
14  #include <signal.h>  #include <signal.h>
15  #include <stdio.h>  #include <stdio.h>
# Line 39  union semun Line 32  union semun
32  };  };
33  #endif // #ifdef _SEM_SEMUN_UNDEFINED  #endif // #ifdef _SEM_SEMUN_UNDEFINED
34    
35  #define SECTION_TRY_LOCK_WAIT_TIME 1 // second  enum _section_list_constant_t
36  #define SECTION_TRY_LOCK_TIMES 10  {
37            SECTION_TRY_LOCK_WAIT_TIME = 1, // second
38            SECTION_TRY_LOCK_TIMES = 10,
39    
40  #define ARTICLE_BLOCK_PER_SHM 1000                // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate          ARTICLE_BLOCK_PER_SHM = 1000,           // sizeof(ARTICLE_BLOCK) * ARTICLE_BLOCK_PER_SHM is the size of each shm segment to allocate
41  #define ARTICLE_BLOCK_SHM_COUNT_LIMIT 80 // limited by length (8-bit) of proj_id in ftok(path, proj_id)          ARTICLE_BLOCK_SHM_COUNT_LIMIT = 80, // limited by length (8-bit) of proj_id in ftok(path, proj_id)
42  #define ARTICLE_BLOCK_PER_POOL (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT)          ARTICLE_BLOCK_PER_POOL = (ARTICLE_BLOCK_PER_SHM * ARTICLE_BLOCK_SHM_COUNT_LIMIT),
43    
44  #define CALCULATE_PAGE_THRESHOLD 100 // Adjust to tune performance of moving topic between sections          CALCULATE_PAGE_THRESHOLD = 100, // Adjust to tune performance of moving topic between sections
45    
46  #define SID_STR_LEN 5 // 32-bit + NULL          SID_STR_LEN = 5, // 32-bit + NULL
47    };
48    
49  struct article_block_t  struct article_block_t
50  {  {
51          ARTICLE articles[ARTICLE_PER_BLOCK];          ARTICLE articles[BBS_article_count_per_block];
52          int article_count;          int article_count;
53          struct article_block_t *p_next_block;          struct article_block_t *p_next_block;
54  };  };
# Line 75  typedef struct article_block_pool_t ARTI Line 71  typedef struct article_block_pool_t ARTI
71    
72  static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL;  static ARTICLE_BLOCK_POOL *p_article_block_pool = NULL;
73    
74  struct section_list_pool_t  SECTION_LIST_POOL *p_section_list_pool = NULL;
 {  
         int shmid;  
         SECTION_LIST sections[BBS_max_section];  
         int section_count;  
         int semid;  
         TRIE_NODE *p_trie_dict_section_by_name;  
         TRIE_NODE *p_trie_dict_section_by_sid;  
 };  
 typedef struct section_list_pool_t SECTION_LIST_POOL;  
   
 static SECTION_LIST_POOL *p_section_list_pool = NULL;  
75    
76  int article_block_init(const char *filename, int block_count)  int article_block_init(const char *filename, int block_count)
77  {  {
# Line 226  void article_block_cleanup(void) Line 211  void article_block_cleanup(void)
211                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);
212          }          }
213    
214          if (shmctl(shmid, IPC_RMID, NULL) == -1)          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)
215          {          {
216                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);
217          }          }
# Line 353  ARTICLE *article_block_find_by_aid(int32 Line 338  ARTICLE *article_block_find_by_aid(int32
338          }          }
339    
340          left = 0;          left = 0;
341          right = p_article_block_pool->block_count;          right = p_article_block_pool->block_count - 1;
342    
343          // aid in the range [ head aid of blocks[left], tail aid of blocks[right - 1] ]          // aid in the range [ head aid of blocks[left], tail aid of blocks[right] ]
344          while (left < right - 1)          while (left < right)
345          {          {
346                  // get block offset no less than mid value of left and right block offsets                  // get block offset no less than mid value of left and right block offsets
347                  mid = (left + right) / 2 + (right - left) % 2;                  mid = (left + right) / 2 + (left + right) % 2;
   
                 if (mid >= p_article_block_pool->block_count)  
                 {  
                         log_error("block(mid = %d) is out of boundary\n", mid);  
                         return NULL;  
                 }  
348    
349                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)
350                  {                  {
351                          right = mid;                          right = mid - 1;
352                  }                  }
353                  else                  else // if (aid >= p_article_block_pool->p_block[mid]->articles[0].aid)
354                  {                  {
355                          left = mid;                          left = mid;
356                  }                  }
# Line 415  ARTICLE *article_block_find_by_index(int Line 394  ARTICLE *article_block_find_by_index(int
394                  return NULL;                  return NULL;
395          }          }
396    
397          if (index < 0 || index / ARTICLE_PER_BLOCK >= p_article_block_pool->block_count)          if (index < 0 || index / BBS_article_count_per_block >= p_article_block_pool->block_count)
398          {          {
399                  log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)\n", index, p_article_block_pool->block_count);                  log_error("article_block_find_by_index(%d) is out of boundary of block [0, %d)\n", index, p_article_block_pool->block_count);
400                  return NULL;                  return NULL;
401          }          }
402    
403          p_block = p_article_block_pool->p_block[index / ARTICLE_PER_BLOCK];          p_block = p_article_block_pool->p_block[index / BBS_article_count_per_block];
404    
405          if (index % ARTICLE_PER_BLOCK >= p_block->article_count)          if (index % BBS_article_count_per_block >= p_block->article_count)
406          {          {
407                  log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)\n", index, p_block->article_count);                  log_error("article_block_find_by_index(%d) is out of boundary of article [0, %d)\n", index, p_block->article_count);
408                  return NULL;                  return NULL;
409          }          }
410    
411          return (p_block->articles + (index % ARTICLE_PER_BLOCK));          return (p_block->articles + (index % BBS_article_count_per_block));
412  }  }
413    
414  extern int section_list_init(const char *filename)  extern int section_list_init(const char *filename)
# Line 547  void section_list_cleanup(void) Line 526  void section_list_cleanup(void)
526                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);
527          }          }
528    
529          if (shmctl(shmid, IPC_RMID, NULL) == -1)          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)
530          {          {
531                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);
532          }          }
# Line 630  SECTION_LIST *section_list_create(int32_ Line 609  SECTION_LIST *section_list_create(int32_
609          p_section = p_section_list_pool->sections + p_section_list_pool->section_count;          p_section = p_section_list_pool->sections + p_section_list_pool->section_count;
610    
611          p_section->sid = sid;          p_section->sid = sid;
612            p_section->ex_menu_tm = 0;
613    
614          strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);          strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);
615          p_section->sname[sizeof(p_section->sname) - 1] = '\0';          p_section->sname[sizeof(p_section->sname) - 1] = '\0';
# Line 659  SECTION_LIST *section_list_create(int32_ Line 639  SECTION_LIST *section_list_create(int32_
639          return p_section;          return p_section;
640  }  }
641    
642    int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list)
643    {
644            int64_t index;
645    
646            if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL)
647            {
648                    log_error("NULL pointer error\n");
649                    return -1;
650            }
651    
652            index = get_section_index(p_section);
653    
654            strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);
655            p_section->sname[sizeof(p_section->sname) - 1] = '\0';
656    
657            strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1);
658            p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';
659    
660            strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);
661            p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';
662    
663            if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0)
664            {
665                    log_error("trie_dict_set(section, %s, %d) error\n", sname, index);
666                    return -2;
667            }
668    
669            return 0;
670    }
671    
672  void section_list_reset_articles(SECTION_LIST *p_section)  void section_list_reset_articles(SECTION_LIST *p_section)
673  {  {
674          p_section->article_count = 0;          p_section->article_count = 0;
# Line 670  void section_list_reset_articles(SECTION Line 680  void section_list_reset_articles(SECTION
680    
681          p_section->page_count = 0;          p_section->page_count = 0;
682          p_section->last_page_visible_article_count = 0;          p_section->last_page_visible_article_count = 0;
683    
684            p_section->ontop_article_count = 0;
685  }  }
686    
687  SECTION_LIST *section_list_find_by_name(const char *sname)  SECTION_LIST *section_list_find_by_name(const char *sname)
# Line 735  int section_list_append_article(SECTION_ Line 747  int section_list_append_article(SECTION_
747    
748          if (p_section == NULL || p_article_src == NULL)          if (p_section == NULL || p_article_src == NULL)
749          {          {
750                  log_error("section_list_append_article() NULL pointer error\n");                  log_error("NULL pointer error\n");
751                  return -1;                  return -1;
752          }          }
753    
# Line 758  int section_list_append_article(SECTION_ Line 770  int section_list_append_article(SECTION_
770          }          }
771    
772          if (p_article_block_pool->block_count == 0 ||          if (p_article_block_pool->block_count == 0 ||
773                  p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= ARTICLE_PER_BLOCK)                  p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count >= BBS_article_count_per_block)
774          {          {
775                  if ((p_block = pop_free_article_block()) == NULL)                  if ((p_block = pop_free_article_block()) == NULL)
776                  {                  {
# Line 768  int section_list_append_article(SECTION_ Line 780  int section_list_append_article(SECTION_
780    
781                  if (p_article_block_pool->block_count > 0)                  if (p_article_block_pool->block_count > 0)
782                  {                  {
783                          last_aid = p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->articles[ARTICLE_PER_BLOCK - 1].aid;                          last_aid = p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->articles[BBS_article_count_per_block - 1].aid;
784                  }                  }
785    
786                  p_article_block_pool->p_block[p_article_block_pool->block_count] = p_block;                  p_article_block_pool->p_block[p_article_block_pool->block_count] = p_block;
# Line 847  int section_list_append_article(SECTION_ Line 859  int section_list_append_article(SECTION_
859          p_section->p_article_tail = p_article;          p_section->p_article_tail = p_article;
860    
861          // Update page          // Update page
862          if ((p_article->visible && p_section->last_page_visible_article_count % BBS_article_limit_per_page == 0) ||          if ((p_article->visible && p_section->last_page_visible_article_count == BBS_article_limit_per_page) ||
863                  p_section->article_count == 1)                  p_section->page_count == 0)
864          {          {
865                  p_section->p_page_first_article[p_section->page_count] = p_article;                  p_section->p_page_first_article[p_section->page_count] = p_article;
866                  p_section->page_count++;                  p_section->page_count++;
# Line 860  int section_list_append_article(SECTION_ Line 872  int section_list_append_article(SECTION_
872                  p_section->last_page_visible_article_count++;                  p_section->last_page_visible_article_count++;
873          }          }
874    
875            if (p_article->ontop && section_list_update_article_ontop(p_section, p_article) < 0)
876            {
877                    log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n",
878                                      p_section->sid, p_article->aid);
879                    return -5;
880            }
881    
882          return 0;          return 0;
883  }  }
884    
# Line 871  int section_list_set_article_visible(SEC Line 890  int section_list_set_article_visible(SEC
890    
891          if (p_section == NULL)          if (p_section == NULL)
892          {          {
893                  log_error("section_list_set_article_visible() NULL pointer error\n");                  log_error("NULL pointer error\n");
894                  return -2;                  return -1;
895          }          }
896    
897          p_article = article_block_find_by_aid(aid);          p_article = article_block_find_by_aid(aid);
# Line 883  int section_list_set_article_visible(SEC Line 902  int section_list_set_article_visible(SEC
902    
903          if (p_section->sid != p_article->sid)          if (p_section->sid != p_article->sid)
904          {          {
905                  log_error("section_list_set_article_visible() error: section sid %d != article sid %d\n", p_section->sid, p_article->sid);                  log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid);
906                  return -2;                  return -2;
907          }          }
908    
# Line 896  int section_list_set_article_visible(SEC Line 915  int section_list_set_article_visible(SEC
915          {          {
916                  p_section->visible_article_count--;                  p_section->visible_article_count--;
917    
918                    if (user_article_cnt_inc(p_article->uid, -1) < 0)
919                    {
920                            log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid);
921                    }
922    
923                  if (p_article->tid == 0)                  if (p_article->tid == 0)
924                  {                  {
925                          p_section->visible_topic_count--;                          p_section->visible_topic_count--;
# Line 914  int section_list_set_article_visible(SEC Line 938  int section_list_set_article_visible(SEC
938                                          p_reply->visible = 0;                                          p_reply->visible = 0;
939                                          p_section->visible_article_count--;                                          p_section->visible_article_count--;
940                                          affected_count++;                                          affected_count++;
941    
942                                            if (user_article_cnt_inc(p_reply->uid, -1) < 0)
943                                            {
944                                                    log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid);
945                                            }
946                                  }                                  }
947                          }                          }
948                  }                  }
# Line 926  int section_list_set_article_visible(SEC Line 955  int section_list_set_article_visible(SEC
955                  {                  {
956                          p_section->visible_topic_count++;                          p_section->visible_topic_count++;
957                  }                  }
958    
959                    if (user_article_cnt_inc(p_article->uid, 1) < 0)
960                    {
961                            log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid);
962                    }
963          }          }
964    
965          p_article->visible = visible;          p_article->visible = visible;
# Line 934  int section_list_set_article_visible(SEC Line 968  int section_list_set_article_visible(SEC
968          return affected_count;          return affected_count;
969  }  }
970    
971    int section_list_update_article_ontop(SECTION_LIST *p_section, ARTICLE *p_article)
972    {
973            int i;
974    
975            if (p_section == NULL || p_article == NULL)
976            {
977                    log_error("NULL pointer error\n");
978                    return -1;
979            }
980    
981            if (p_section->sid != p_article->sid)
982            {
983                    log_error("Inconsistent section sid %d != article sid %d\n", p_section->sid, p_article->sid);
984                    return -2;
985            }
986    
987            if (p_article->ontop)
988            {
989                    for (i = 0; i < p_section->ontop_article_count; i++)
990                    {
991                            if (p_section->p_ontop_articles[i]->aid == p_article->aid)
992                            {
993                                    log_error("Inconsistent state found: article %d already ontop in section %d\n", p_article->aid, p_section->sid);
994                                    return 0;
995                            }
996                            else if (p_section->p_ontop_articles[i]->aid > p_article->aid)
997                            {
998                                    break;
999                            }
1000                    }
1001    
1002                    // Remove the oldest one if the array of ontop articles is full
1003                    if (p_section->ontop_article_count >= BBS_ontop_article_limit_per_section)
1004                    {
1005                            if (i == 0) // p_article is the oldest one
1006                            {
1007                                    return 0;
1008                            }
1009                            memmove((void *)(p_section->p_ontop_articles),
1010                                            (void *)(p_section->p_ontop_articles + 1),
1011                                            sizeof(ARTICLE *) * (size_t)(i - 1));
1012                            p_section->ontop_article_count--;
1013                            i--;
1014                    }
1015                    else
1016                    {
1017                            memmove((void *)(p_section->p_ontop_articles + i + 1),
1018                                            (void *)(p_section->p_ontop_articles + i),
1019                                            sizeof(ARTICLE *) * (size_t)(p_section->ontop_article_count - i));
1020                    }
1021    
1022                    p_section->p_ontop_articles[i] = p_article;
1023                    p_section->ontop_article_count++;
1024    
1025                    // TODO: debug
1026            }
1027            else // ontop == 0
1028            {
1029                    for (i = 0; i < p_section->ontop_article_count; i++)
1030                    {
1031                            if (p_section->p_ontop_articles[i]->aid == p_article->aid)
1032                            {
1033                                    break;
1034                            }
1035                    }
1036                    if (i == p_section->ontop_article_count) // not found
1037                    {
1038                            log_error("Inconsistent state found: article %d not ontop in section %d\n", p_article->aid, p_section->sid);
1039                            return 0;
1040                    }
1041    
1042                    memmove((void *)(p_section->p_ontop_articles + i),
1043                                    (void *)(p_section->p_ontop_articles + i + 1),
1044                                    sizeof(ARTICLE *) * (size_t)(p_section->ontop_article_count - i - 1));
1045                    p_section->ontop_article_count--;
1046            }
1047    
1048            return 0;
1049    }
1050    
1051    int section_list_page_count_with_ontop(SECTION_LIST *p_section)
1052    {
1053            int page_count;
1054    
1055            if (p_section == NULL)
1056            {
1057                    log_error("NULL pointer error\n");
1058                    return -1;
1059            }
1060    
1061            page_count = p_section->page_count - 1 +
1062                                     (p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page +
1063                                     ((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page ? 1 : 0);
1064    
1065            if (page_count < 0)
1066            {
1067                    page_count = 0;
1068            }
1069    
1070            return page_count;
1071    }
1072    
1073    int section_list_page_article_count_with_ontop(SECTION_LIST *p_section, int32_t page_id)
1074    {
1075            if (p_section == NULL)
1076            {
1077                    log_error("NULL pointer error\n");
1078                    return -1;
1079            }
1080    
1081            if (page_id < p_section->page_count - 1)
1082            {
1083                    return BBS_article_limit_per_page;
1084            }
1085            else // if (page_id >= p_section->page_count - 1)
1086            {
1087                    return MIN(MAX(0,
1088                                               (p_section->last_page_visible_article_count + p_section->ontop_article_count -
1089                                                    BBS_article_limit_per_page * (page_id - p_section->page_count + 1))),
1090                                       BBS_article_limit_per_page);
1091            }
1092    }
1093    
1094  ARTICLE *section_list_find_article_with_offset(SECTION_LIST *p_section, int32_t aid, int32_t *p_page, int32_t *p_offset, ARTICLE **pp_next)  ARTICLE *section_list_find_article_with_offset(SECTION_LIST *p_section, int32_t aid, int32_t *p_page, int32_t *p_offset, ARTICLE **pp_next)
1095  {  {
1096          ARTICLE *p_article;          ARTICLE *p_article;
# Line 947  ARTICLE *section_list_find_article_with_ Line 1104  ARTICLE *section_list_find_article_with_
1104    
1105          if (p_section == NULL)          if (p_section == NULL)
1106          {          {
1107                  log_error("section_list_find_article_with_offset() NULL pointer error\n");                  log_error("NULL pointer error\n");
1108                  return NULL;                  return NULL;
1109          }          }
1110    
# Line 959  ARTICLE *section_list_find_article_with_ Line 1116  ARTICLE *section_list_find_article_with_
1116          }          }
1117    
1118          left = 0;          left = 0;
1119          right = p_section->page_count;          right = p_section->page_count - 1;
1120    
1121          // aid in the range [ head aid of pages[left], tail aid of pages[right - 1] ]          // aid in the range [ head aid of pages[left], tail aid of pages[right] ]
1122          while (left < right - 1)          while (left < right)
1123          {          {
1124                  // get page id no less than mid value of left page id and right page id                  // get page id no less than mid value of left page id and right page id
1125                  mid = (left + right) / 2 + (right - left) % 2;                  mid = (left + right) / 2 + (left + right) % 2;
   
                 if (mid >= p_section->page_count)  
                 {  
                         log_error("page id (mid = %d) is out of boundary\n", mid);  
                         return NULL;  
                 }  
1126    
1127                  if (aid < p_section->p_page_first_article[mid]->aid)                  if (aid < p_section->p_page_first_article[mid]->aid)
1128                  {                  {
1129                          right = mid;                          right = mid - 1;
1130                  }                  }
1131                  else                  else // if (aid < p_section->p_page_first_article[mid]->aid)
1132                  {                  {
1133                          left = mid;                          left = mid;
1134                  }                  }
# Line 1039  int section_list_calculate_page(SECTION_ Line 1190  int section_list_calculate_page(SECTION_
1190    
1191          if (p_section == NULL)          if (p_section == NULL)
1192          {          {
1193                  log_error("section_list_calculate_page() NULL pointer error\n");                  log_error("NULL pointer error\n");
1194                  return -1;                  return -1;
1195          }          }
1196    
# Line 1128  int section_list_calculate_page(SECTION_ Line 1279  int section_list_calculate_page(SECTION_
1279          } while (p_article != p_section->p_article_head);          } while (p_article != p_section->p_article_head);
1280    
1281          p_section->page_count = page + (visible_article_count > 0 ? 1 : 0);          p_section->page_count = page + (visible_article_count > 0 ? 1 : 0);
1282          p_section->last_page_visible_article_count = visible_article_count;          p_section->last_page_visible_article_count = (visible_article_count > 0
1283                                                                                                              ? visible_article_count
1284                                                                                                              : (page > 0 ? BBS_article_limit_per_page : 0));
1285    
1286          return 0;          return 0;
1287  }  }
# Line 1150  int article_block_article_count(void) Line 1303  int article_block_article_count(void)
1303                  return -1;                  return -1;
1304          }          }
1305    
1306          ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK +          ret = (p_article_block_pool->block_count - 1) * BBS_article_count_per_block +
1307                    p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count;                    p_article_block_pool->p_block[p_article_block_pool->block_count - 1]->article_count;
1308    
1309          return ret;          return ret;
# Line 1198  int section_list_move_topic(SECTION_LIST Line 1351  int section_list_move_topic(SECTION_LIST
1351    
1352          if (p_section_src == NULL || p_section_dest == NULL)          if (p_section_src == NULL || p_section_dest == NULL)
1353          {          {
1354                  log_error("section_list_move_topic() NULL pointer error\n");                  log_error("NULL pointer error\n");
1355                  return -1;                  return -1;
1356          }          }
1357    
# Line 1411  int get_section_index(SECTION_LIST *p_se Line 1564  int get_section_index(SECTION_LIST *p_se
1564          return index;          return index;
1565  }  }
1566    
1567    int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *master_list)
1568    {
1569            if (p_section == NULL)
1570            {
1571                    log_error("NULL pointer error\n");
1572                    return -1;
1573            }
1574    
1575            if (section_list_rd_lock(p_section) < 0)
1576            {
1577                    log_error("section_list_rd_lock(sid=%d) error\n", p_section->sid);
1578                    return -2;
1579            }
1580    
1581            if (sname != NULL)
1582            {
1583                    memcpy(sname, p_section->sname, sizeof(p_section->sname));
1584            }
1585            if (stitle != NULL)
1586            {
1587                    memcpy(stitle, p_section->stitle, sizeof(p_section->stitle));
1588            }
1589            if (master_list != NULL)
1590            {
1591                    memcpy(master_list, p_section->master_list, sizeof(p_section->master_list));
1592            }
1593    
1594            // release lock of section
1595            if (section_list_rd_unlock(p_section) < 0)
1596            {
1597                    log_error("section_list_rd_unlock(sid=%d) error\n", p_section->sid);
1598                    return -2;
1599            }
1600    
1601            return 0;
1602    }
1603    
1604  int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec)  int section_list_try_rd_lock(SECTION_LIST *p_section, int wait_sec)
1605  {  {
1606          int index;          int index;
# Line 1570  int section_list_rd_lock(SECTION_LIST *p Line 1760  int section_list_rd_lock(SECTION_LIST *p
1760                          timer++;                          timer++;
1761                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1762                          {                          {
1763                                  log_error("section_list_rd_lock() tried %d times on section %d\n", sid, timer);                                  log_error("section_list_try_rd_lock() tried %d times on section %d\n", timer, sid);
1764                          }                          }
1765                  }                  }
1766                  else // failed                  else // failed
1767                  {                  {
1768                          log_error("section_list_rd_lock() failed on section %d\n", sid);                          log_error("section_list_try_rd_lock() failed on section %d\n", sid);
1769                          break;                          break;
1770                  }                  }
1771          }          }
# Line 1601  int section_list_rw_lock(SECTION_LIST *p Line 1791  int section_list_rw_lock(SECTION_LIST *p
1791                          timer++;                          timer++;
1792                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1793                          {                          {
1794                                  log_error("acquire_section_rw_lock() tried %d times on section %d\n", sid, timer);                                  log_error("section_list_try_rw_lock() tried %d times on section %d\n", timer, sid);
1795                          }                          }
1796                  }                  }
1797                  else // failed                  else // failed
1798                  {                  {
1799                          log_error("acquire_section_rw_lock() failed on section %d\n", sid);                          log_error("section_list_try_rw_lock() failed on section %d\n", sid);
1800                          break;                          break;
1801                  }                  }
1802          }          }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1