/[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.59 by sysadm, Mon Nov 17 12:16:48 2025 UTC Revision 1.61 by sysadm, Tue Nov 18 15:15:18 2025 UTC
# Line 25  Line 25 
25  #include <sys/sem.h>  #include <sys/sem.h>
26  #include <sys/shm.h>  #include <sys/shm.h>
27    
28  #if defined(_SEM_SEMUN_UNDEFINED) || defined(__MSYS__) || defined(__MINGW32__)  #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 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 240  int set_article_block_shm_readonly(void) Line 241  int set_article_block_shm_readonly(void)
241                  shmid = (p_article_block_pool->shm_pool + i)->shmid;                  shmid = (p_article_block_pool->shm_pool + i)->shmid;
242    
243                  // Remap shared memory in read-only mode                  // Remap shared memory in read-only mode
 #if defined(__MSYS__) || defined(__MINGW32__)  
                 if (shmdt((p_article_block_pool->shm_pool + i)->p_shm) == -1)  
                 {  
                         log_error("shmdt(shmid = %d) error (%d)\n", (p_article_block_pool->shm_pool + i)->shmid, errno);  
                         return -2;  
                 }  
                 p_shm = shmat(shmid, (p_article_block_pool->shm_pool + i)->p_shm, SHM_RDONLY);  
 #else  
244                  p_shm = shmat(shmid, (p_article_block_pool->shm_pool + i)->p_shm, SHM_RDONLY | SHM_REMAP);                  p_shm = shmat(shmid, (p_article_block_pool->shm_pool + i)->p_shm, SHM_RDONLY | SHM_REMAP);
 #endif  
245                  if (p_shm == (void *)-1)                  if (p_shm == (void *)-1)
246                  {                  {
247                          log_error("shmat(article_block_pool shmid = %d) error (%d)\n", shmid, errno);                          log_error("shmat(article_block_pool shmid = %d) error (%d)\n", shmid, errno);
248                          return -2;                          return -2;
249                  }                  }
250          }          }
251    #endif
252    
253          return 0;          return 0;
254  }  }
# Line 549  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 561  int set_section_list_shm_readonly(void) Line 555  int set_section_list_shm_readonly(void)
555          shmid = p_section_list_pool->shmid;          shmid = p_section_list_pool->shmid;
556    
557          // Remap shared memory in read-only mode          // Remap shared memory in read-only mode
 #if defined(__MSYS__) || defined(__MINGW32__)  
         if (shmdt(p_section_list_pool) == -1)  
         {  
                 log_error("shmdt(section_list_pool) error (%d)\n", errno);  
                 return -1;  
         }  
         p_shm = shmat(shmid, p_section_list_pool, SHM_RDONLY);  
 #else  
558          p_shm = shmat(shmid, p_section_list_pool, SHM_RDONLY | SHM_REMAP);          p_shm = shmat(shmid, p_section_list_pool, SHM_RDONLY | SHM_REMAP);
 #endif  
559          if (p_shm == (void *)-1)          if (p_shm == (void *)-1)
560          {          {
561                  log_error("shmat(section_list_pool shmid = %d) error (%d)\n", shmid, errno);                  log_error("shmat(section_list_pool shmid = %d) error (%d)\n", shmid, errno);
# Line 578  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 1627  int section_list_try_rd_lock(SECTION_LIS Line 1613  int section_list_try_rd_lock(SECTION_LIS
1613  {  {
1614          int index;          int index;
1615          struct sembuf sops[4];          struct sembuf sops[4];
1616  #if !defined(__MSYS__) && !defined(__MINGW32__)  #ifndef __CYGWIN__
1617          struct timespec timeout;          struct timespec timeout;
1618  #endif  #endif
1619          int ret;          int ret;
# Line 1660  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  #if defined(__MSYS__) || defined(__MINGW32__)  #ifdef __CYGWIN__
1650          ret = semop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4));          ret = semop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4));
1651  #else  #else
1652          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;
# Line 1680  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  #if !defined(__MSYS__) && !defined(__MINGW32__)  #ifndef __CYGWIN__
1670          struct timespec timeout;          struct timespec timeout;
1671  #endif  #endif
1672          int ret;          int ret;
# Line 1703  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  #if defined(__MSYS__) || defined(__MINGW32__)  #ifdef __CYGWIN__
1693          ret = semop(p_section_list_pool->semid, sops, 3);          ret = semop(p_section_list_pool->semid, sops, 3);
1694  #else  #else
1695          timeout.tv_sec = wait_sec;          timeout.tv_sec = wait_sec;


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

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