/[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.40 by sysadm, Mon Oct 13 02:23:27 2025 UTC Revision 1.61 by sysadm, Tue Nov 18 15:15:18 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     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "log.h"  #include "log.h"
14  #include "section_list.h"  #include "section_list.h"
15  #include "trie_dict.h"  #include "trie_dict.h"
16    #include "user_list.h"
17  #include <errno.h>  #include <errno.h>
18  #include <signal.h>  #include <signal.h>
19  #include <stdio.h>  #include <stdio.h>
# Line 28  Line 25 
25  #include <sys/sem.h>  #include <sys/sem.h>
26  #include <sys/shm.h>  #include <sys/shm.h>
27    
28  #ifdef _SEM_SEMUN_UNDEFINED  #if defined(_SEM_SEMUN_UNDEFINED) || defined(__CYGWIN__)
29  union semun  union semun
30  {  {
31          int val;                           /* Value for SETVAL */          int val;                           /* Value for SETVAL */
# Line 37  union semun Line 34  union semun
34          struct seminfo *__buf; /* Buffer for IPC_INFO          struct seminfo *__buf; /* Buffer for IPC_INFO
35                                                            (Linux-specific) */                                                            (Linux-specific) */
36  };  };
37  #endif // #ifdef _SEM_SEMUN_UNDEFINED  #endif // #if defined(_SEM_SEMUN_UNDEFINED)
38    
39  #define SECTION_TRY_LOCK_WAIT_TIME 1 // second  enum _section_list_constant_t
40  #define SECTION_TRY_LOCK_TIMES 10  {
41            SECTION_TRY_LOCK_WAIT_TIME = 1, // second
42            SECTION_TRY_LOCK_TIMES = 10,
43    
44  #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
45  #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)
46  #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),
47    
48  #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
49    
50  #define SID_STR_LEN 5 // 32-bit + NULL          SID_STR_LEN = 5, // 32-bit + NULL
51    };
52    
53  struct article_block_t  struct article_block_t
54  {  {
55          ARTICLE articles[ARTICLE_PER_BLOCK];          ARTICLE articles[BBS_article_count_per_block];
56          int article_count;          int article_count;
57          struct article_block_t *p_next_block;          struct article_block_t *p_next_block;
58  };  };
# Line 215  void article_block_cleanup(void) Line 215  void article_block_cleanup(void)
215                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);
216          }          }
217    
218          if (shmctl(shmid, IPC_RMID, NULL) == -1)          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)
219          {          {
220                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);
221          }          }
# Line 225  void article_block_cleanup(void) Line 225  void article_block_cleanup(void)
225    
226  int set_article_block_shm_readonly(void)  int set_article_block_shm_readonly(void)
227  {  {
228    #ifndef __CYGWIN__
229          int shmid;          int shmid;
230          void *p_shm;          void *p_shm;
231          int i;          int i;
# Line 247  int set_article_block_shm_readonly(void) Line 248  int set_article_block_shm_readonly(void)
248                          return -2;                          return -2;
249                  }                  }
250          }          }
251    #endif
252    
253          return 0;          return 0;
254  }  }
# Line 342  ARTICLE *article_block_find_by_aid(int32 Line 344  ARTICLE *article_block_find_by_aid(int32
344          }          }
345    
346          left = 0;          left = 0;
347          right = p_article_block_pool->block_count;          right = p_article_block_pool->block_count - 1;
348    
349          // 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] ]
350          while (left < right - 1)          while (left < right)
351          {          {
352                  // 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
353                  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;  
                 }  
354    
355                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)
356                  {                  {
357                          right = mid;                          right = mid - 1;
358                  }                  }
359                  else                  else // if (aid >= p_article_block_pool->p_block[mid]->articles[0].aid)
360                  {                  {
361                          left = mid;                          left = mid;
362                  }                  }
# Line 404  ARTICLE *article_block_find_by_index(int Line 400  ARTICLE *article_block_find_by_index(int
400                  return NULL;                  return NULL;
401          }          }
402    
403          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)
404          {          {
405                  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);
406                  return NULL;                  return NULL;
407          }          }
408    
409          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];
410    
411          if (index % ARTICLE_PER_BLOCK >= p_block->article_count)          if (index % BBS_article_count_per_block >= p_block->article_count)
412          {          {
413                  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);
414                  return NULL;                  return NULL;
415          }          }
416    
417          return (p_block->articles + (index % ARTICLE_PER_BLOCK));          return (p_block->articles + (index % BBS_article_count_per_block));
418  }  }
419    
420  extern int section_list_init(const char *filename)  extern int section_list_init(const char *filename)
# Line 536  void section_list_cleanup(void) Line 532  void section_list_cleanup(void)
532                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);                  log_error("shmdt(shmid = %d) error (%d)\n", shmid, errno);
533          }          }
534    
535          if (shmctl(shmid, IPC_RMID, NULL) == -1)          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)
536          {          {
537                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shmctl(shmid = %d, IPC_RMID) error (%d)\n", shmid, errno);
538          }          }
# Line 546  void section_list_cleanup(void) Line 542  void section_list_cleanup(void)
542    
543  int set_section_list_shm_readonly(void)  int set_section_list_shm_readonly(void)
544  {  {
545    #ifndef __CYGWIN__
546          int shmid;          int shmid;
547          void *p_shm;          void *p_shm;
548    
# Line 566  int set_section_list_shm_readonly(void) Line 563  int set_section_list_shm_readonly(void)
563          }          }
564    
565          p_section_list_pool = p_shm;          p_section_list_pool = p_shm;
566    #endif
567    
568          return 0;          return 0;
569  }  }
# Line 649  SECTION_LIST *section_list_create(int32_ Line 647  SECTION_LIST *section_list_create(int32_
647          return p_section;          return p_section;
648  }  }
649    
650    int section_list_update(SECTION_LIST *p_section, const char *sname, const char *stitle, const char *master_list)
651    {
652            int64_t index;
653    
654            if (p_section == NULL || sname == NULL || stitle == NULL || master_list == NULL)
655            {
656                    log_error("NULL pointer error\n");
657                    return -1;
658            }
659    
660            index = get_section_index(p_section);
661    
662            strncpy(p_section->sname, sname, sizeof(p_section->sname) - 1);
663            p_section->sname[sizeof(p_section->sname) - 1] = '\0';
664    
665            strncpy(p_section->stitle, stitle, sizeof(p_section->stitle) - 1);
666            p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';
667    
668            strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);
669            p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';
670    
671            if (trie_dict_set(p_section_list_pool->p_trie_dict_section_by_name, sname, index) < 0)
672            {
673                    log_error("trie_dict_set(section, %s, %d) error\n", sname, index);
674                    return -2;
675            }
676    
677            return 0;
678    }
679    
680  void section_list_reset_articles(SECTION_LIST *p_section)  void section_list_reset_articles(SECTION_LIST *p_section)
681  {  {
682          p_section->article_count = 0;          p_section->article_count = 0;
# Line 664  void section_list_reset_articles(SECTION Line 692  void section_list_reset_articles(SECTION
692          p_section->ontop_article_count = 0;          p_section->ontop_article_count = 0;
693  }  }
694    
695  SECTION_LIST *section_list_find_by_name(const char *sname, int64_t *p_index)  SECTION_LIST *section_list_find_by_name(const char *sname)
696  {  {
697          int64_t index;          int64_t index;
698          int ret;          int ret;
# Line 686  SECTION_LIST *section_list_find_by_name( Line 714  SECTION_LIST *section_list_find_by_name(
714                  return NULL;                  return NULL;
715          }          }
716    
         if (p_index != NULL)  
         {  
                 *p_index = index;  
         }  
   
717          return (p_section_list_pool->sections + index);          return (p_section_list_pool->sections + index);
718  }  }
719    
720  SECTION_LIST *section_list_find_by_sid(int32_t sid, int64_t *p_index)  SECTION_LIST *section_list_find_by_sid(int32_t sid)
721  {  {
722          int64_t index;          int64_t index;
723          int ret;          int ret;
# Line 719  SECTION_LIST *section_list_find_by_sid(i Line 742  SECTION_LIST *section_list_find_by_sid(i
742                  return NULL;                  return NULL;
743          }          }
744    
         if (p_index != NULL)  
         {  
                 *p_index = index;  
         }  
   
745          return (p_section_list_pool->sections + index);          return (p_section_list_pool->sections + index);
746  }  }
747    
# Line 737  int section_list_append_article(SECTION_ Line 755  int section_list_append_article(SECTION_
755    
756          if (p_section == NULL || p_article_src == NULL)          if (p_section == NULL || p_article_src == NULL)
757          {          {
758                  log_error("section_list_append_article() NULL pointer error\n");                  log_error("NULL pointer error\n");
759                  return -1;                  return -1;
760          }          }
761    
# Line 760  int section_list_append_article(SECTION_ Line 778  int section_list_append_article(SECTION_
778          }          }
779    
780          if (p_article_block_pool->block_count == 0 ||          if (p_article_block_pool->block_count == 0 ||
781                  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)
782          {          {
783                  if ((p_block = pop_free_article_block()) == NULL)                  if ((p_block = pop_free_article_block()) == NULL)
784                  {                  {
# Line 770  int section_list_append_article(SECTION_ Line 788  int section_list_append_article(SECTION_
788    
789                  if (p_article_block_pool->block_count > 0)                  if (p_article_block_pool->block_count > 0)
790                  {                  {
791                          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;
792                  }                  }
793    
794                  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 849  int section_list_append_article(SECTION_ Line 867  int section_list_append_article(SECTION_
867          p_section->p_article_tail = p_article;          p_section->p_article_tail = p_article;
868    
869          // Update page          // Update page
870          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) ||
871                  p_section->article_count == 1)                  p_section->page_count == 0)
872          {          {
873                  p_section->p_page_first_article[p_section->page_count] = p_article;                  p_section->p_page_first_article[p_section->page_count] = p_article;
874                  p_section->page_count++;                  p_section->page_count++;
# Line 905  int section_list_set_article_visible(SEC Line 923  int section_list_set_article_visible(SEC
923          {          {
924                  p_section->visible_article_count--;                  p_section->visible_article_count--;
925    
926                    if (user_article_cnt_inc(p_article->uid, -1) < 0)
927                    {
928                            log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_article->uid);
929                    }
930    
931                  if (p_article->tid == 0)                  if (p_article->tid == 0)
932                  {                  {
933                          p_section->visible_topic_count--;                          p_section->visible_topic_count--;
# Line 923  int section_list_set_article_visible(SEC Line 946  int section_list_set_article_visible(SEC
946                                          p_reply->visible = 0;                                          p_reply->visible = 0;
947                                          p_section->visible_article_count--;                                          p_section->visible_article_count--;
948                                          affected_count++;                                          affected_count++;
949    
950                                            if (user_article_cnt_inc(p_reply->uid, -1) < 0)
951                                            {
952                                                    log_error("user_article_cnt_inc(uid=%d, -1) error\n", p_reply->uid);
953                                            }
954                                  }                                  }
955                          }                          }
956                  }                  }
# Line 935  int section_list_set_article_visible(SEC Line 963  int section_list_set_article_visible(SEC
963                  {                  {
964                          p_section->visible_topic_count++;                          p_section->visible_topic_count++;
965                  }                  }
966    
967                    if (user_article_cnt_inc(p_article->uid, 1) < 0)
968                    {
969                            log_error("user_article_cnt_inc(uid=%d, 1) error\n", p_article->uid);
970                    }
971          }          }
972    
973          p_article->visible = visible;          p_article->visible = visible;
# Line 1033  int section_list_page_count_with_ontop(S Line 1066  int section_list_page_count_with_ontop(S
1066                  return -1;                  return -1;
1067          }          }
1068    
1069          page_count = p_section->page_count - (p_section->last_page_visible_article_count > 0 ? 1 : 0) +          page_count = p_section->page_count - 1 +
1070                                   (p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page +                                   (p_section->last_page_visible_article_count + p_section->ontop_article_count + BBS_article_limit_per_page - 1) /
1071                                   ((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page == 0 ? 0 : 1);                                           BBS_article_limit_per_page;
1072    
1073            if (page_count < 0)
1074            {
1075                    page_count = 0;
1076            }
1077    
1078          return page_count;          return page_count;
1079  }  }
# Line 1054  int section_list_page_article_count_with Line 1092  int section_list_page_article_count_with
1092          }          }
1093          else // if (page_id >= p_section->page_count - 1)          else // if (page_id >= p_section->page_count - 1)
1094          {          {
1095                  return MAX(0, (p_section->last_page_visible_article_count + p_section->ontop_article_count -                  return MIN(MAX(0,
1096                                             BBS_article_limit_per_page * (page_id - p_section->page_count + 1)));                                             (p_section->last_page_visible_article_count + p_section->ontop_article_count -
1097                                                    BBS_article_limit_per_page * (page_id - p_section->page_count + 1))),
1098                                       BBS_article_limit_per_page);
1099          }          }
1100  }  }
1101    
# Line 1072  ARTICLE *section_list_find_article_with_ Line 1112  ARTICLE *section_list_find_article_with_
1112    
1113          if (p_section == NULL)          if (p_section == NULL)
1114          {          {
1115                  log_error("section_list_find_article_with_offset() NULL pointer error\n");                  log_error("NULL pointer error\n");
1116                  return NULL;                  return NULL;
1117          }          }
1118    
# Line 1084  ARTICLE *section_list_find_article_with_ Line 1124  ARTICLE *section_list_find_article_with_
1124          }          }
1125    
1126          left = 0;          left = 0;
1127          right = p_section->page_count;          right = p_section->page_count - 1;
1128    
1129          // 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] ]
1130          while (left < right - 1)          while (left < right)
1131          {          {
1132                  // 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
1133                  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;  
                 }  
1134    
1135                  if (aid < p_section->p_page_first_article[mid]->aid)                  if (aid < p_section->p_page_first_article[mid]->aid)
1136                  {                  {
1137                          right = mid;                          right = mid - 1;
1138                  }                  }
1139                  else                  else // if (aid < p_section->p_page_first_article[mid]->aid)
1140                  {                  {
1141                          left = mid;                          left = mid;
1142                  }                  }
# Line 1164  int section_list_calculate_page(SECTION_ Line 1198  int section_list_calculate_page(SECTION_
1198    
1199          if (p_section == NULL)          if (p_section == NULL)
1200          {          {
1201                  log_error("section_list_calculate_page() NULL pointer error\n");                  log_error("NULL pointer error\n");
1202                  return -1;                  return -1;
1203          }          }
1204    
# Line 1253  int section_list_calculate_page(SECTION_ Line 1287  int section_list_calculate_page(SECTION_
1287          } while (p_article != p_section->p_article_head);          } while (p_article != p_section->p_article_head);
1288    
1289          p_section->page_count = page + (visible_article_count > 0 ? 1 : 0);          p_section->page_count = page + (visible_article_count > 0 ? 1 : 0);
1290          p_section->last_page_visible_article_count = visible_article_count;          p_section->last_page_visible_article_count = (visible_article_count > 0
1291                                                                                                              ? visible_article_count
1292                                                                                                              : (page > 0 ? BBS_article_limit_per_page : 0));
1293    
1294          return 0;          return 0;
1295  }  }
# Line 1275  int article_block_article_count(void) Line 1311  int article_block_article_count(void)
1311                  return -1;                  return -1;
1312          }          }
1313    
1314          ret = (p_article_block_pool->block_count - 1) * ARTICLE_PER_BLOCK +          ret = (p_article_block_pool->block_count - 1) * BBS_article_count_per_block +
1315                    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;
1316    
1317          return ret;          return ret;
# Line 1323  int section_list_move_topic(SECTION_LIST Line 1359  int section_list_move_topic(SECTION_LIST
1359    
1360          if (p_section_src == NULL || p_section_dest == NULL)          if (p_section_src == NULL || p_section_dest == NULL)
1361          {          {
1362                  log_error("section_list_move_topic() NULL pointer error\n");                  log_error("NULL pointer error\n");
1363                  return -1;                  return -1;
1364          }          }
1365    
# Line 1536  int get_section_index(SECTION_LIST *p_se Line 1572  int get_section_index(SECTION_LIST *p_se
1572          return index;          return index;
1573  }  }
1574    
1575    int get_section_info(SECTION_LIST *p_section, char *sname, char *stitle, char *master_list)
1576    {
1577            if (p_section == NULL)
1578            {
1579                    log_error("NULL pointer error\n");
1580                    return -1;
1581            }
1582    
1583            if (section_list_rd_lock(p_section) < 0)
1584            {
1585                    log_error("section_list_rd_lock(sid=%d) error\n", p_section->sid);
1586                    return -2;
1587            }
1588    
1589            if (sname != NULL)
1590            {
1591                    memcpy(sname, p_section->sname, sizeof(p_section->sname));
1592            }
1593            if (stitle != NULL)
1594            {
1595                    memcpy(stitle, p_section->stitle, sizeof(p_section->stitle));
1596            }
1597            if (master_list != NULL)
1598            {
1599                    memcpy(master_list, p_section->master_list, sizeof(p_section->master_list));
1600            }
1601    
1602            // release lock of section
1603            if (section_list_rd_unlock(p_section) < 0)
1604            {
1605                    log_error("section_list_rd_unlock(sid=%d) error\n", p_section->sid);
1606                    return -2;
1607            }
1608    
1609            return 0;
1610    }
1611    
1612  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)
1613  {  {
1614          int index;          int index;
1615          struct sembuf sops[4];          struct sembuf sops[4];
1616    #ifndef __CYGWIN__
1617          struct timespec timeout;          struct timespec timeout;
1618    #endif
1619          int ret;          int ret;
1620    
1621          index = get_section_index(p_section);          index = get_section_index(p_section);
# Line 1571  int section_list_try_rd_lock(SECTION_LIS Line 1646  int section_list_try_rd_lock(SECTION_LIS
1646                  sops[3].sem_flg = SEM_UNDO;                        // undo on terminate                  sops[3].sem_flg = SEM_UNDO;                        // undo on terminate
1647          }          }
1648    
1649    #ifdef __CYGWIN__
1650            ret = semop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4));
1651    #else
1652          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;
1653          timeout.tv_nsec = 0;          timeout.tv_nsec = 0;
1654    
1655          ret = semtimedop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4), &timeout);          ret = semtimedop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4), &timeout);
1656    #endif
1657          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
1658          {          {
1659                  log_error("semtimedop(index = %d, lock read) error %d\n", index, errno);                  log_error("semop(index = %d, lock read) error %d\n", index, errno);
1660          }          }
1661    
1662          return ret;          return ret;
# Line 1587  int section_list_try_rw_lock(SECTION_LIS Line 1666  int section_list_try_rw_lock(SECTION_LIS
1666  {  {
1667          int index;          int index;
1668          struct sembuf sops[3];          struct sembuf sops[3];
1669    #ifndef __CYGWIN__
1670          struct timespec timeout;          struct timespec timeout;
1671    #endif
1672          int ret;          int ret;
1673    
1674          index = get_section_index(p_section);          index = get_section_index(p_section);
# Line 1608  int section_list_try_rw_lock(SECTION_LIS Line 1689  int section_list_try_rw_lock(SECTION_LIS
1689          sops[2].sem_op = 0;                                                        // wait until unlocked          sops[2].sem_op = 0;                                                        // wait until unlocked
1690          sops[2].sem_flg = 0;          sops[2].sem_flg = 0;
1691    
1692    #ifdef __CYGWIN__
1693            ret = semop(p_section_list_pool->semid, sops, 3);
1694    #else
1695          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;
1696          timeout.tv_nsec = 0;          timeout.tv_nsec = 0;
1697    
1698          ret = semtimedop(p_section_list_pool->semid, sops, 3, &timeout);          ret = semtimedop(p_section_list_pool->semid, sops, 3, &timeout);
1699    #endif
1700          if (ret == -1 && errno != EAGAIN && errno != EINTR)          if (ret == -1 && errno != EAGAIN && errno != EINTR)
1701          {          {
1702                  log_error("semtimedop(index = %d, lock write) error %d\n", index, errno);                  log_error("semop(index = %d, lock write) error %d\n", index, errno);
1703          }          }
1704    
1705          return ret;          return ret;
# Line 1695  int section_list_rd_lock(SECTION_LIST *p Line 1780  int section_list_rd_lock(SECTION_LIST *p
1780                          timer++;                          timer++;
1781                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1782                          {                          {
1783                                  log_error("section_list_try_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);
1784                          }                          }
1785                  }                  }
1786                  else // failed                  else // failed
# Line 1726  int section_list_rw_lock(SECTION_LIST *p Line 1811  int section_list_rw_lock(SECTION_LIST *p
1811                          timer++;                          timer++;
1812                          if (timer % SECTION_TRY_LOCK_TIMES == 0)                          if (timer % SECTION_TRY_LOCK_TIMES == 0)
1813                          {                          {
1814                                  log_error("section_list_try_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);
1815                          }                          }
1816                  }                  }
1817                  else // failed                  else // failed


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

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