Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
a91c5be6
Commit
a91c5be6
authored
22 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
pgindent new Win32 files.
parent
1a67e486
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/backend/port/win32/sem.c
+67
-50
67 additions, 50 deletions
src/backend/port/win32/sem.c
src/backend/port/win32/shm.c
+39
-31
39 additions, 31 deletions
src/backend/port/win32/shm.c
with
106 additions
and
81 deletions
src/backend/port/win32/sem.c
+
67
−
50
View file @
a91c5be6
...
@@ -13,10 +13,13 @@
...
@@ -13,10 +13,13 @@
#include
<errno.h>
#include
<errno.h>
typedef
struct
{
typedef
struct
{
int
m_numSems
;
int
m_numSems
;
off_t
m_semaphoreHandles
;
// offset from beginning of header
off_t
m_semaphoreHandles
;
off_t
m_semaphoreCounts
;
// offset from beginning of header
//offset from beginning of header
off_t
m_semaphoreCounts
;
//offset from beginning of header
}
win32_sem_set_hdr
;
}
win32_sem_set_hdr
;
/* Control of a semaphore pool. The pool is an area in which we stored all
/* Control of a semaphore pool. The pool is an area in which we stored all
...
@@ -38,9 +41,11 @@ semctl(int semId, int semNum, int flag, union semun semun)
...
@@ -38,9 +41,11 @@ semctl(int semId, int semNum, int flag, union semun semun)
{
{
int
i
;
int
i
;
struct
sembuf
sops
;
struct
sembuf
sops
;
sops
.
sem_flg
=
IPC_NOWAIT
;
sops
.
sem_flg
=
IPC_NOWAIT
;
for
(
i
=
0
;
i
<
the_set
->
m_numSems
;
++
i
)
{
for
(
i
=
0
;
i
<
the_set
->
m_numSems
;
++
i
)
{
if
(
semun
.
array
[
i
]
==
sem_counts
[
i
])
if
(
semun
.
array
[
i
]
==
sem_counts
[
i
])
continue
;
/* Nothing to do */
continue
;
/* Nothing to do */
...
@@ -61,8 +66,10 @@ semctl(int semId, int semNum, int flag, union semun semun)
...
@@ -61,8 +66,10 @@ semctl(int semId, int semNum, int flag, union semun semun)
/* Fix the count of one semaphore to semun.val */
/* Fix the count of one semaphore to semun.val */
else
if
(
flag
==
SETVAL
)
else
if
(
flag
==
SETVAL
)
{
{
if
(
semun
.
val
!=
sem_counts
[
semNum
])
{
if
(
semun
.
val
!=
sem_counts
[
semNum
])
{
struct
sembuf
sops
;
struct
sembuf
sops
;
sops
.
sem_flg
=
IPC_NOWAIT
;
sops
.
sem_flg
=
IPC_NOWAIT
;
sops
.
sem_num
=
semNum
;
sops
.
sem_num
=
semNum
;
...
@@ -94,15 +101,11 @@ semctl(int semId, int semNum, int flag, union semun semun)
...
@@ -94,15 +101,11 @@ semctl(int semId, int semNum, int flag, union semun semun)
/* Get the current semaphore count */
/* Get the current semaphore count */
else
if
(
flag
==
GETNCNT
)
else
if
(
flag
==
GETNCNT
)
{
return
the_set
->
m_numSems
;
return
the_set
->
m_numSems
;
}
/* Get the current semaphore count of the first semaphore in the pool */
/* Get the current semaphore count of the first semaphore in the pool */
else
if
(
flag
==
GETVAL
)
else
if
(
flag
==
GETVAL
)
{
return
sem_counts
[
semNum
];
return
sem_counts
[
semNum
];
}
/* Other commands not yet supported */
/* Other commands not yet supported */
else
else
...
@@ -135,23 +138,27 @@ semget(int semKey, int semNum, int flags)
...
@@ -135,23 +138,27 @@ semget(int semKey, int semNum, int flags)
sprintf
(
semname
,
"PG_SEMSET.%d."
,
semKey
);
sprintf
(
semname
,
"PG_SEMSET.%d."
,
semKey
);
num_part
=
semname
+
strlen
(
semname
);
num_part
=
semname
+
strlen
(
semname
);
strcpy
(
num_part
,
_itoa
(
_getpid
()
*
-
1
,
cur_num
,
10
));
/* For shared memory, include the pid */
strcpy
(
num_part
,
_itoa
(
_getpid
()
*
-
1
,
cur_num
,
10
));
/* For shared memory,
* include the pid */
win32_sem_set_hdr
*
new_set
=
(
win32_sem_set_hdr
*
)
ShmemInitStruct
(
semname
,
sem_set_size
,
&
found
);
win32_sem_set_hdr
*
new_set
=
(
win32_sem_set_hdr
*
)
ShmemInitStruct
(
semname
,
sem_set_size
,
&
found
);
if
(
found
)
{
if
(
found
)
{
/* This should *never* happen */
/* This should *never* happen */
errno
=
EEXIST
;
errno
=
EEXIST
;
return
-
1
;
return
-
1
;
}
}
new_set
->
m_numSems
=
semNum
;
new_set
->
m_numSems
=
semNum
;
new_set
->
m_semaphoreHandles
=
sizeof
(
win32_sem_set_hdr
);
// array starts after header
new_set
->
m_semaphoreHandles
=
sizeof
(
win32_sem_set_hdr
);
//array starts after header
new_set
->
m_semaphoreCounts
=
new_set
->
m_semaphoreHandles
+
(
sizeof
(
HANDLE
)
*
semNum
);
new_set
->
m_semaphoreCounts
=
new_set
->
m_semaphoreHandles
+
(
sizeof
(
HANDLE
)
*
semNum
);
sem_handles
=
(
HANDLE
*
)
((
off_t
)
new_set
+
new_set
->
m_semaphoreHandles
);
sem_handles
=
(
HANDLE
*
)
((
off_t
)
new_set
+
new_set
->
m_semaphoreHandles
);
sem_counts
=
(
int
*
)
((
off_t
)
new_set
+
new_set
->
m_semaphoreCounts
);
sem_counts
=
(
int
*
)
((
off_t
)
new_set
+
new_set
->
m_semaphoreCounts
);
for
(
int
i
=
0
;
i
<
semNum
&&
ans
;
++
i
)
{
for
(
int
i
=
0
;
i
<
semNum
&&
ans
;
++
i
)
{
strcpy
(
num_part
,
_itoa
(
i
,
cur_num
,
10
));
strcpy
(
num_part
,
_itoa
(
i
,
cur_num
,
10
));
if
(
flags
&
IPC_CREAT
)
if
(
flags
&
IPC_CREAT
)
...
@@ -174,11 +181,13 @@ semget(int semKey, int semNum, int flags)
...
@@ -174,11 +181,13 @@ semget(int semKey, int semNum, int flags)
}
}
}
}
if
(
ans
)
{
if
(
ans
)
return
MAKE_OFFSET
(
new_set
);
return
MAKE_OFFSET
(
new_set
);
}
else
{
else
// Blow away what we've got right now...
{
for
(
int
i
=
0
;
i
<
semNum
;
++
i
)
{
/* Blow away what we've got right now... */
for
(
int
i
=
0
;
i
<
semNum
;
++
i
)
{
if
(
sem_handles
[
i
])
if
(
sem_handles
[
i
])
CloseHandle
(
sem_handles
[
i
]);
CloseHandle
(
sem_handles
[
i
]);
else
else
...
@@ -198,8 +207,12 @@ semop(int semId, struct sembuf * sops, int nsops)
...
@@ -198,8 +207,12 @@ semop(int semId, struct sembuf * sops, int nsops)
int
*
sem_counts
=
(
int
*
)
((
off_t
)
the_set
+
the_set
->
m_semaphoreCounts
);
int
*
sem_counts
=
(
int
*
)
((
off_t
)
the_set
+
the_set
->
m_semaphoreCounts
);
HANDLE
cur_handle
;
HANDLE
cur_handle
;
if
(
nsops
!=
1
)
{
if
(
nsops
!=
1
)
/* Not supported (we return on 1st success, and don't cancel earlier ops) */
{
/*
* Not supported (we return on 1st success, and don't cancel
* earlier ops)
*/
errno
=
E2BIG
;
errno
=
E2BIG
;
return
-
1
;
return
-
1
;
}
}
...
@@ -209,22 +222,26 @@ semop(int semId, struct sembuf * sops, int nsops)
...
@@ -209,22 +222,26 @@ semop(int semId, struct sembuf * sops, int nsops)
if
(
sops
[
0
].
sem_op
==
-
1
)
if
(
sops
[
0
].
sem_op
==
-
1
)
{
{
DWORD
ret
;
DWORD
ret
;
if
(
sops
[
0
].
sem_flg
&
IPC_NOWAIT
)
if
(
sops
[
0
].
sem_flg
&
IPC_NOWAIT
)
ret
=
WaitForSingleObject
(
cur_handle
,
0
);
ret
=
WaitForSingleObject
(
cur_handle
,
0
);
else
else
ret
=
WaitForSingleObject
(
cur_handle
,
INFINITE
);
ret
=
WaitForSingleObject
(
cur_handle
,
INFINITE
);
if
(
ret
==
WAIT_OBJECT_0
)
{
if
(
ret
==
WAIT_OBJECT_0
)
{
/* We got it! */
/* We got it! */
sem_counts
[
sops
[
0
].
sem_num
]
--
;
sem_counts
[
sops
[
0
].
sem_num
]
--
;
return
0
;
return
0
;
}
else
if
(
ret
==
WAIT_TIMEOUT
)
}
else
if
(
ret
==
WAIT_TIMEOUT
)
/* Couldn't get it */
/* Couldn't get it */
errno
=
EAGAIN
;
errno
=
EAGAIN
;
else
else
errno
=
EIDRM
;
errno
=
EIDRM
;
}
}
else
if
(
sops
[
0
].
sem_op
>
0
)
{
else
if
(
sops
[
0
].
sem_op
>
0
)
{
/* Don't want the lock anymore */
/* Don't want the lock anymore */
sem_counts
[
sops
[
0
].
sem_num
]
++
;
sem_counts
[
sops
[
0
].
sem_num
]
++
;
ReleaseSemaphore
(
cur_handle
,
sops
[
0
].
sem_op
,
NULL
);
ReleaseSemaphore
(
cur_handle
,
sops
[
0
].
sem_op
,
NULL
);
...
...
This diff is collapsed.
Click to expand it.
src/backend/port/win32/shm.c
+
39
−
31
View file @
a91c5be6
...
@@ -30,12 +30,13 @@ shmdt(const void *shmaddr)
...
@@ -30,12 +30,13 @@ shmdt(const void *shmaddr)
void
*
void
*
shmat
(
int
memId
,
void
*
shmaddr
,
int
flag
)
shmat
(
int
memId
,
void
*
shmaddr
,
int
flag
)
{
{
/*
KEW_
TODO -- shmat needs to count # attached to shared mem */
/* TODO -- shmat needs to count # attached to shared mem */
void
*
lpmem
=
MapViewOfFileEx
((
HANDLE
)
memId
,
void
*
lpmem
=
MapViewOfFileEx
((
HANDLE
)
memId
,
FILE_MAP_WRITE
|
FILE_MAP_READ
,
FILE_MAP_WRITE
|
FILE_MAP_READ
,
0
,
0
,
/* (DWORD)pshmdsc->segsize */
s_segsize
,
shmaddr
);
0
,
0
,
/* (DWORD)pshmdsc->segsize */
s_segsize
,
shmaddr
);
if
(
lpmem
==
NULL
)
{
if
(
lpmem
==
NULL
)
{
lpmem
=
(
void
*
)
-
1
;
lpmem
=
(
void
*
)
-
1
;
errno
=
GetLastError
();
errno
=
GetLastError
();
}
}
...
@@ -57,12 +58,15 @@ shmctl(int shmid, int flag, struct shmid_ds * dummy)
...
@@ -57,12 +58,15 @@ shmctl(int shmid, int flag, struct shmid_ds * dummy)
{
{
/* Can only test for if exists */
/* Can only test for if exists */
int
hmap
=
shmget
(
shmid
,
0
,
0
);
int
hmap
=
shmget
(
shmid
,
0
,
0
);
if
(
hmap
<
0
)
{
if
(
hmap
<
0
)
{
/* Shared memory does not exist */
/* Shared memory does not exist */
errno
=
EINVAL
;
errno
=
EINVAL
;
return
-
1
;
return
-
1
;
}
}
else
{
else
{
/* Shared memory does exist and must be in use */
/* Shared memory does exist and must be in use */
shmctl
(
hmap
,
IPC_RMID
,
NULL
);
/* Release our hold on it */
shmctl
(
hmap
,
IPC_RMID
,
NULL
);
/* Release our hold on it */
errno
=
0
;
errno
=
0
;
...
@@ -85,7 +89,8 @@ shmget(int memKey, int size, int flag)
...
@@ -85,7 +89,8 @@ shmget(int memKey, int size, int flag)
s_segsize
=
size
;
s_segsize
=
size
;
sprintf
(
szShareMem
,
"sharemem.%d"
,
memKey
);
sprintf
(
szShareMem
,
"sharemem.%d"
,
memKey
);
if
(
flag
&
IPC_CREAT
)
{
if
(
flag
&
IPC_CREAT
)
{
hmap
=
CreateFileMapping
((
HANDLE
)
0xFFFFFFFF
,
/* Use the swap file */
hmap
=
CreateFileMapping
((
HANDLE
)
0xFFFFFFFF
,
/* Use the swap file */
NULL
,
NULL
,
PAGE_READWRITE
,
/* Memory is Read/Write */
PAGE_READWRITE
,
/* Memory is Read/Write */
...
@@ -93,18 +98,21 @@ shmget(int memKey, int size, int flag)
...
@@ -93,18 +98,21 @@ shmget(int memKey, int size, int flag)
(
DWORD
)
s_segsize
,
/* Size Lower 32 bits */
(
DWORD
)
s_segsize
,
/* Size Lower 32 bits */
szShareMem
);
szShareMem
);
}
}
else
{
else
{
hmap
=
OpenFileMapping
(
FILE_MAP_ALL_ACCESS
,
hmap
=
OpenFileMapping
(
FILE_MAP_ALL_ACCESS
,
FALSE
,
FALSE
,
szShareMem
);
szShareMem
);
if
(
!
hmap
)
{
if
(
!
hmap
)
{
errno
=
ENOENT
;
errno
=
ENOENT
;
return
-
1
;
return
-
1
;
}
}
}
}
dwRet
=
GetLastError
();
dwRet
=
GetLastError
();
if
(
dwRet
==
ERROR_ALREADY_EXISTS
&&
hmap
&&
(
flag
&
(
IPC_CREAT
|
IPC_EXCL
)))
{
if
(
dwRet
==
ERROR_ALREADY_EXISTS
&&
hmap
&&
(
flag
&
(
IPC_CREAT
|
IPC_EXCL
)))
{
/* Caller wanted to create the segment -- error if already exists */
/* Caller wanted to create the segment -- error if already exists */
CloseHandle
(
hmap
);
CloseHandle
(
hmap
);
errno
=
EEXIST
;
errno
=
EEXIST
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment