Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita91c5be

Browse files
committed
pgindent new Win32 files.
1 parent1a67e48 commita91c5be

File tree

2 files changed

+106
-81
lines changed

2 files changed

+106
-81
lines changed

‎src/backend/port/win32/sem.c

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
#include<errno.h>
1515

16-
typedefstruct {
16+
typedefstruct
17+
{
1718
intm_numSems;
18-
off_tm_semaphoreHandles;// offset from beginning of header
19-
off_tm_semaphoreCounts;// offset from beginning of header
20-
}win32_sem_set_hdr;
19+
off_tm_semaphoreHandles;
20+
//offset from beginning of header
21+
off_tm_semaphoreCounts;
22+
//offset from beginning of header
23+
}win32_sem_set_hdr;
2124

2225
/* Control of a semaphore pool. The pool is an area in which we stored all
2326
** the semIds of the pool. The first long is the number of semaphore
@@ -27,30 +30,32 @@ typedef struct {
2730
int
2831
semctl(intsemId,intsemNum,intflag,unionsemunsemun)
2932
{
30-
win32_sem_set_hdr*the_set= (win32_sem_set_hdr*)MAKE_PTR(semId);
33+
win32_sem_set_hdr*the_set= (win32_sem_set_hdr*)MAKE_PTR(semId);
3134

3235
/* semNum might be 0 */
3336
/* semun.array contains the sem initial values */
34-
int*sem_counts= (int*)((off_t)the_set+the_set->m_semaphoreCounts);
37+
int*sem_counts= (int*)((off_t)the_set+the_set->m_semaphoreCounts);
3538

3639
/* Fix the count of all sem of the pool to semun.array */
3740
if (flag==SETALL)
3841
{
39-
inti;
42+
inti;
4043
structsembufsops;
44+
4145
sops.sem_flg=IPC_NOWAIT;
4246

43-
for (i=0;i<the_set->m_numSems;++i) {
47+
for (i=0;i<the_set->m_numSems;++i)
48+
{
4449
if (semun.array[i]==sem_counts[i])
45-
continue;/* Nothing to do */
50+
continue;/* Nothing to do */
4651

4752
if (semun.array[i]<sem_counts[i])
4853
sops.sem_op=-1;
4954
else
5055
sops.sem_op=1;
5156

5257
sops.sem_num=i;
53-
58+
5459
/* Quickly lock/unlock the semaphore (if we can) */
5560
if (semop(semId,&sops,1)<0)
5661
return-1;
@@ -61,16 +66,18 @@ semctl(int semId, int semNum, int flag, union semun semun)
6166
/* Fix the count of one semaphore to semun.val */
6267
elseif (flag==SETVAL)
6368
{
64-
if (semun.val!=sem_counts[semNum]) {
69+
if (semun.val!=sem_counts[semNum])
70+
{
6571
structsembufsops;
72+
6673
sops.sem_flg=IPC_NOWAIT;
6774
sops.sem_num=semNum;
6875

6976
if (semun.val<sem_counts[semNum])
7077
sops.sem_op=-1;
7178
else
7279
sops.sem_op=1;
73-
80+
7481
/* Quickly lock/unlock the semaphore (if we can) */
7582
if (semop(semId,&sops,1)<0)
7683
return-1;
@@ -82,8 +89,8 @@ semctl(int semId, int semNum, int flag, union semun semun)
8289
/* Delete the pool */
8390
elseif (flag==IPC_RMID)
8491
{
85-
inti;
86-
HANDLE*sem_handles= (HANDLE*)((off_t)the_set+the_set->m_semaphoreHandles);
92+
inti;
93+
HANDLE*sem_handles= (HANDLE*)((off_t)the_set+the_set->m_semaphoreHandles);
8794

8895
/* Loop over all semaphore to delete them */
8996
for (i=0;i<the_set->m_numSems;++i)
@@ -94,15 +101,11 @@ semctl(int semId, int semNum, int flag, union semun semun)
94101

95102
/* Get the current semaphore count */
96103
elseif (flag==GETNCNT)
97-
{
98104
returnthe_set->m_numSems;
99-
}
100105

101106
/* Get the current semaphore count of the first semaphore in the pool */
102107
elseif (flag==GETVAL)
103-
{
104108
returnsem_counts[semNum];
105-
}
106109

107110
/* Other commands not yet supported */
108111
else
@@ -116,17 +119,17 @@ semctl(int semId, int semNum, int flag, union semun semun)
116119
int
117120
semget(intsemKey,intsemNum,intflags)
118121
{
119-
charsemname[32];
120-
charcur_num[20];
121-
DWORDlast_error;
122-
char*num_part;
123-
boolans= true;
122+
charsemname[32];
123+
charcur_num[20];
124+
DWORDlast_error;
125+
char*num_part;
126+
boolans= true;
124127
SECURITY_ATTRIBUTESsec_attrs;
125-
HANDLEcur_handle;
126-
boolfound= false;
127-
Sizesem_set_size=sizeof(win32_sem_set_hdr)+semNum* (sizeof(HANDLE)+sizeof(int));
128-
HANDLE*sem_handles=NULL;
129-
int*sem_counts=NULL;
128+
HANDLEcur_handle;
129+
boolfound= false;
130+
Sizesem_set_size=sizeof(win32_sem_set_hdr)+semNum* (sizeof(HANDLE)+sizeof(int));
131+
HANDLE*sem_handles=NULL;
132+
int*sem_counts=NULL;
130133

131134
sec_attrs.nLength=sizeof(sec_attrs);
132135
sec_attrs.lpSecurityDescriptor=NULL;
@@ -135,23 +138,27 @@ semget(int semKey, int semNum, int flags)
135138
sprintf(semname,"PG_SEMSET.%d.",semKey);
136139
num_part=semname+strlen(semname);
137140

138-
strcpy(num_part,_itoa(_getpid()*-1,cur_num,10));/* For shared memory, include the pid */
139-
win32_sem_set_hdr*new_set= (win32_sem_set_hdr*)ShmemInitStruct(semname,sem_set_size,&found);
141+
strcpy(num_part,_itoa(_getpid()*-1,cur_num,10));/* For shared memory,
142+
* include the pid */
143+
win32_sem_set_hdr*new_set= (win32_sem_set_hdr*)ShmemInitStruct(semname,sem_set_size,&found);
140144

141-
if (found) {
145+
if (found)
146+
{
142147
/* This should *never* happen */
143148
errno=EEXIST;
144149
return-1;
145150
}
146151

147152
new_set->m_numSems=semNum;
148-
new_set->m_semaphoreHandles=sizeof(win32_sem_set_hdr);// array starts after header
149-
new_set->m_semaphoreCounts=new_set->m_semaphoreHandles+ (sizeof(HANDLE)*semNum);
153+
new_set->m_semaphoreHandles=sizeof(win32_sem_set_hdr);
154+
//array starts after header
155+
new_set->m_semaphoreCounts=new_set->m_semaphoreHandles+ (sizeof(HANDLE)*semNum);
150156

151-
sem_handles= (HANDLE*)((off_t)new_set+new_set->m_semaphoreHandles);
152-
sem_counts= (int*)((off_t)new_set+new_set->m_semaphoreCounts);
157+
sem_handles= (HANDLE*)((off_t)new_set+new_set->m_semaphoreHandles);
158+
sem_counts= (int*)((off_t)new_set+new_set->m_semaphoreCounts);
153159

154-
for (inti=0;i<semNum&&ans;++i) {
160+
for (inti=0;i<semNum&&ans;++i)
161+
{
155162
strcpy(num_part,_itoa(i,cur_num,10));
156163

157164
if (flags&IPC_CREAT)
@@ -174,11 +181,13 @@ semget(int semKey, int semNum, int flags)
174181
}
175182
}
176183

177-
if (ans) {
184+
if (ans)
178185
returnMAKE_OFFSET(new_set);
179-
}else {
180-
// Blow away what we've got right now...
181-
for (inti=0;i<semNum;++i) {
186+
else
187+
{
188+
/* Blow away what we've got right now... */
189+
for (inti=0;i<semNum;++i)
190+
{
182191
if (sem_handles[i])
183192
CloseHandle(sem_handles[i]);
184193
else
@@ -193,13 +202,17 @@ semget(int semKey, int semNum, int flags)
193202
int
194203
semop(intsemId,structsembuf*sops,intnsops)
195204
{
196-
win32_sem_set_hdr*the_set= (win32_sem_set_hdr*)MAKE_PTR(semId);
197-
HANDLE*sem_handles= (HANDLE*)((off_t)the_set+the_set->m_semaphoreHandles);
198-
int*sem_counts= (int*)((off_t)the_set+the_set->m_semaphoreCounts);
199-
HANDLEcur_handle;
205+
win32_sem_set_hdr*the_set= (win32_sem_set_hdr*)MAKE_PTR(semId);
206+
HANDLE*sem_handles= (HANDLE*)((off_t)the_set+the_set->m_semaphoreHandles);
207+
int*sem_counts= (int*)((off_t)the_set+the_set->m_semaphoreCounts);
208+
HANDLEcur_handle;
200209

201-
if (nsops!=1) {
202-
/* Not supported (we return on 1st success, and don't cancel earlier ops) */
210+
if (nsops!=1)
211+
{
212+
/*
213+
* Not supported (we return on 1st success, and don't cancel
214+
* earlier ops)
215+
*/
203216
errno=E2BIG;
204217
return-1;
205218
}
@@ -208,23 +221,27 @@ semop(int semId, struct sembuf * sops, int nsops)
208221

209222
if (sops[0].sem_op==-1)
210223
{
211-
DWORDret;
224+
DWORDret;
225+
212226
if (sops[0].sem_flg&IPC_NOWAIT)
213227
ret=WaitForSingleObject(cur_handle,0);
214228
else
215229
ret=WaitForSingleObject(cur_handle,INFINITE);
216230

217-
if (ret==WAIT_OBJECT_0) {
231+
if (ret==WAIT_OBJECT_0)
232+
{
218233
/* We got it! */
219234
sem_counts[sops[0].sem_num]--;
220235
return0;
221-
}elseif (ret==WAIT_TIMEOUT)
236+
}
237+
elseif (ret==WAIT_TIMEOUT)
222238
/* Couldn't get it */
223239
errno=EAGAIN;
224240
else
225241
errno=EIDRM;
226242
}
227-
elseif (sops[0].sem_op>0) {
243+
elseif (sops[0].sem_op>0)
244+
{
228245
/* Don't want the lock anymore */
229246
sem_counts[sops[0].sem_num]++;
230247
ReleaseSemaphore(cur_handle,sops[0].sem_op,NULL);

‎src/backend/port/win32/shm.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ shmdt(const void *shmaddr)
2828

2929
/* Attach to an existing area */
3030
void*
31-
shmat(intmemId,void*shmaddr,intflag)
31+
shmat(intmemId,void*shmaddr,intflag)
3232
{
33-
/*KEW_TODO -- shmat needs to count # attached to shared mem */
34-
void*lpmem=MapViewOfFileEx((HANDLE)memId,
35-
FILE_MAP_WRITE |FILE_MAP_READ,
36-
0,0,/* (DWORD)pshmdsc->segsize */s_segsize,shmaddr);
33+
/*TODO -- shmat needs to count # attached to shared mem */
34+
void*lpmem=MapViewOfFileEx((HANDLE)memId,
35+
FILE_MAP_WRITE |FILE_MAP_READ,
36+
0,0,/* (DWORD)pshmdsc->segsize */s_segsize,shmaddr);
3737

38-
if (lpmem==NULL) {
39-
lpmem= (void*)-1;
38+
if (lpmem==NULL)
39+
{
40+
lpmem= (void*)-1;
4041
errno=GetLastError();
4142
}
4243

43-
returnlpmem;
44+
returnlpmem;
4445
}
4546

4647
/* Control a shared mem area */
@@ -50,21 +51,24 @@ shmctl(int shmid, int flag, struct shmid_ds * dummy)
5051
if (flag==IPC_RMID)
5152
{
5253
/* Delete the area */
53-
CloseHandle((HANDLE)shmid);
54+
CloseHandle((HANDLE)shmid);
5455
return0;
5556
}
5657
if (flag==IPC_STAT)
5758
{
5859
/* Can only test for if exists */
59-
inthmap=shmget(shmid,0,0);
60-
if (hmap<0) {
60+
inthmap=shmget(shmid,0,0);
61+
62+
if (hmap<0)
63+
{
6164
/* Shared memory does not exist */
6265
errno=EINVAL;
6366
return-1;
6467
}
65-
else {
68+
else
69+
{
6670
/* Shared memory does exist and must be in use */
67-
shmctl(hmap,IPC_RMID,NULL);/* Release our hold on it */
71+
shmctl(hmap,IPC_RMID,NULL);/* Release our hold on it */
6872
errno=0;
6973
return0;
7074
}
@@ -78,33 +82,37 @@ shmctl(int shmid, int flag, struct shmid_ds * dummy)
7882
int
7983
shmget(intmemKey,intsize,intflag)
8084
{
81-
HANDLEhmap;
82-
charszShareMem[32];
83-
DWORDdwRet;
85+
HANDLEhmap;
86+
charszShareMem[32];
87+
DWORDdwRet;
8488

85-
s_segsize=size;
86-
sprintf(szShareMem,"sharemem.%d",memKey);
89+
s_segsize=size;
90+
sprintf(szShareMem,"sharemem.%d",memKey);
8791

88-
if (flag&IPC_CREAT) {
89-
hmap=CreateFileMapping((HANDLE)0xFFFFFFFF,/* Use the swap file */
90-
NULL,
91-
PAGE_READWRITE,/* Memory is Read/Write */
92-
0L,/* Size Upper 32 Bits */
93-
(DWORD)s_segsize,/* Size Lower 32 bits*/
94-
szShareMem);
92+
if (flag&IPC_CREAT)
93+
{
94+
hmap=CreateFileMapping((HANDLE)0xFFFFFFFF,/* Use the swap file*/
95+
NULL,
96+
PAGE_READWRITE,/* Memory is Read/Write */
97+
0L,/* Size Upper 32 Bits*/
98+
(DWORD)s_segsize,/* Size Lower 32 bits */
99+
szShareMem);
95100
}
96-
else {
101+
else
102+
{
97103
hmap=OpenFileMapping(FILE_MAP_ALL_ACCESS,
98-
FALSE,
99-
szShareMem);
100-
if (!hmap) {
104+
FALSE,
105+
szShareMem);
106+
if (!hmap)
107+
{
101108
errno=ENOENT;
102109
return-1;
103110
}
104111
}
105112

106113
dwRet=GetLastError();
107-
if (dwRet==ERROR_ALREADY_EXISTS&&hmap&& (flag& (IPC_CREAT |IPC_EXCL))) {
114+
if (dwRet==ERROR_ALREADY_EXISTS&&hmap&& (flag& (IPC_CREAT |IPC_EXCL)))
115+
{
108116
/* Caller wanted to create the segment -- error if already exists */
109117
CloseHandle(hmap);
110118
errno=EEXIST;
@@ -116,5 +124,5 @@ shmget(int memKey, int size, int flag)
116124
return-1;
117125
}
118126

119-
return (int)hmap;
127+
return (int)hmap;
120128
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp